0% found this document useful (0 votes)
125 views31 pages

Chapter 2 - Memory Management (Simple Systems)

The document discusses different memory allocation schemes used in operating systems including single-user contiguous, fixed partitions, dynamic partitions, and relocatable dynamic partitions. It describes how each scheme allocates and manages memory and the advantages and disadvantages of each approach.

Uploaded by

shania nkusi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views31 pages

Chapter 2 - Memory Management (Simple Systems)

The document discusses different memory allocation schemes used in operating systems including single-user contiguous, fixed partitions, dynamic partitions, and relocatable dynamic partitions. It describes how each scheme allocates and manages memory and the advantages and disadvantages of each approach.

Uploaded by

shania nkusi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

Faculty of Computing and Informatics

Department of Computer Science


Operating Systems
OPS621S

2020 - Semester 2
Event Specific Picture –Chapter 2
behind red graphic
Memory Management
(Simple Systems)
Learning Objectives
 After completing the chapter, you should be able to describe:
 How four memory allocation schemes in this chapter manage
incoming jobs
 How four memory allocation systems work: best-fit, first-fit,
next-fit and worst-fit
 How a memory list is used to keep the status of available
memory
 The essential role of memory deallocation, and the
consequences if it isn’t performed
 How compaction can improve memory allocation efficiency.
Chapter Outline
 Introduction
 Four types of memory allocation schemes
– Single-user contiguous scheme
– Fixed partitions
– Dynamic partitions
– Relocatable dynamic partitions
 Fragmentation
 Memory allocation methods / algorithms
 First fit
 Best fit
 Deallocation
 Relocatable dynamic partition
Introduction
 Management of main memory is critical
 Entire system performance dependent on two
items
– How much memory is available
– Optimization of memory during job processing
 This chapter introduces:
– Memory manager
– Four types of memory allocation schemes
• Single-user systems
• Fixed partitions
• Dynamic partitions
• Relocatable dynamic partitions
Introduction
 Operating systems must employ techniques to:
– Track where and how a program resides in memory
– Convert logical addresses into actual physical addresses
 Logical address (sometimes called a virtual or relative
address) A value generated by the CPU that specifies a
generic location, relative to the program
– is simply an integer value relative to the starting point of the
program
 Physical address An actual address in the main memory
device
– is a logical address added to the starting location of the
program in main memory
Single - User Contiguous Scheme
 Commercially available in 1940s and 1950s
 Entire program loaded into memory
 Contiguous memory space allocated as needed
 Jobs processed sequentially
 Memory manager performs minimal work
– Evaluates incoming process size; loads if small enough to fit,
otherwise reject and evaluates next incoming process. Accumulator to
track program size
– Monitors occupied memory space when process end; makes entire
memory space available and then checks for the next process.
 Disadvantages
– No support for multiprogramming or networking
– Not cost effective => unsuitable for business.
– Program size must be less than memory size to execute
Fixed partition
 Commercially available in 1950s and 1960s
 Main memory is partitioned
– At system startup
– One contiguous partition per job
 Permits multiprogramming
 Partition sizes remain static
– Must shut down computer system to reconfigure
 Requires:
– Protection of the job’s memory space
– Matching job size with partition size
Fixed partition (cont.)
 Memory Manager: allocates memory space to jobs
– Information: stored in a table

(table 2.1)
A simplified fixed-partition memory table with the free partition shaded.
© Cengage Learning 2018
(figure 2.2)
As the jobs listed in Table 2.1 are loaded into the four fixed partitions, Job 3 must
wait even though Partition 1 has 70K of available memory. Jobs are allocated space
on the basis of “first available partition of required size.”
© Cengage Learning 2018
Fixed partition
 Characteristics:
– Requires contiguous loading of entire program
– Job allocation method
• First available partition with required size
– To work well:
• All jobs must be same size and memory size known
ahead of time
– Arbitrary partition size leads to undesired results
• Partition too small
– Large jobs have longer turnaround time
• Partition too large
– Memory waste: internal fragmentation
Dynamic partition
 Main memory is partitioned
– Jobs given memory requested when loaded
– One contiguous partition per job
 Job allocation method
– First come, first serve allocation method
– Memory waste: comparatively small within partitions
 Disadvantages:
– Full memory utilization only during loading of first
jobs
– Subsequent allocation: memory waste
• External fragmentation: fragments between blocks
Dynamic partition
(figure 2.3)
Main memory use during
dynamic partition
allocation. Five
snapshots (a-e) of main
memory as eight jobs
are submitted for
processing and allocated
space on the basis of
“first come, first served.”
Job 8 has to wait (e)
even though there’s
enough free memory
between partitions to
accommodate it.
© Cengage Learning
2018
Fragmentation
 Internal Fragmentation:
Allocated memory may be slightly larger than
requested memory; this size difference is memory
internal to a partition, but not being used.
 External Fragmentation:
A situation in which the dynamic allocation of
memory creates unusable fragments of free memory
between blocks of busy, or allocated memory. It
is not contiguous.
 Reduce external fragmentation by compaction.
Best-fit and First-fit Allocation
 Two methods for free space allocation
– First-fit memory allocation scheme:
• Job is assigned first partition large enough
• Leads to fast allocation of memory space
– Best-fit memory allocation scheme:
• Job is assigned smallest partition large enough
• Results in least wasted space
• Internal fragmentation reduced, but not eliminated
 Fixed and dynamic memory allocation
schemes use both methods.
Best-fit and First-fit Allocation (cont.)
First-fit memory allocation

Best-fit memory allocation


First-fit

(figure 2.5)
Using a first-fit scheme, Job 1 claims the first available space. Job 2 then claims the
first partition large enough to accommodate it, but by doing so it takes the last block
large enough to accommodate Job 3. Therefore, Job 3 (indicated by the asterisk) must
wait until a large block becomes available, even though there’s 75K of unused memory
space (internal fragmentation). Notice that the memory list is ordered according to
memory location.
© Cengage Learning 2018
Best-fit

(figure 2.6)
Best-fit free scheme. Job 1 is allocated to the closest-fitting free partition, as are Job 2
and Job 3. Job 4 is allocated to the only available partition although it isn’t the best-
fitting one. In this scheme, all four jobs are served without waiting. Notice that the
memory list is ordered according to memory size. This scheme uses memory more
efficiently but it’s slower to implement.
© Cengage Learning 2018
Best-fit and First-fit Allocation (cont.)

Check algorithms for both first fit and


best fit in the textbook.
Hypothetical allocation schemes
 Next-fit: starts searching from last allocated
block, for next available block when a new
job arrives
 Worst-fit: allocates largest free available
block to new job.
– Opposite of best-fit
– Good way to explore theory of memory
allocation
– Not best choice for an actual system
Deallocation
 Deallocation: freeing/releasing allocated memory
space
 For fixed-partition system:
– Straightforward process
– Memory Manager resets the status of job’s memory block to
“free” upon job completion
– Any code may be used
– Example code: binary values with 0 (zero) indicating free and
1 (one) indicating busy
 For dynamic-partition system:
– Algorithm tries to combine free areas of memory
– More complex
Deallocation (cont.)
Three dynamic partition system cases, depending
on position of block to be deallocated:
– Case 1: When the block to be deallocated is
adjacent to another free block
– Case 2: When the block to be deallocated is
between two free blocks
– Case 3: When the block to be deallocated is
isolated from other free blocks
Look for examples regarding these
cases in textbook
Relocatable Dynamic Partitions
 Memory Manager relocates programs
– Gathers all empty blocks together
 Compact the empty blocks
– Make one block of memory large enough to
accommodate some or all of the jobs waiting to
get in.
Relocatable Dynamic Partitions (cont.)
 Compaction: reclaiming fragmented
sections of memory space sections
– Every program in memory must be relocated
• Programs become contiguous
– Operating system must distinguish between
addresses and data values
• Every address adjusted to account for the program’s
new location in memory
• Data values left alone
Relocatable Dynamic Partitions (cont.)

(figure 2.7)
Three snapshots of memory before and after compaction with the operating system
occupying the first 10K of memory. When Job 6 arrives requiring 84K, the initial memory
layout in (a) shows external fragmentation totaling 96K of space. Immediately after
compaction (b), external fragmentation has been eliminated, making room for Job 6 which,
after loading, is shown in (c).
© Cengage Learning 2018
Relocatable Dynamic Partitions (cont.)

(figure 2.9)
Contents of the relocation register for Job 4 (a) before the job’s relocation
(a value of zero) and (b) after compaction (a negative number).
© Cengage Learning 2018
Relocatable Dynamic Partitions (cont.)
 Compaction issues:
– What goes on behind the scenes when
relocation and compaction take place?

– What keeps track of how far each job has


moved from its original storage area?

– What lists have to be updated?


Relocatable Dynamic Partitions (cont.)
 What lists have to be updated?
– Free list
• Showing the partition for the new block of free
memory
– Busy list
• Showing the new locations for all of the jobs
already in process that were relocated
– Each job will have a new address
• Exception: those already at the lowest memory
locations
Relocatable Dynamic Partitions (cont.)
 Special-purpose registers used for relocation:
– Bounds register
• Stores highest (last) location accessible by each
program
– Relocation register
• Contains the value that must be added to each
address referenced in the program
• Must be able to access the correct memory addresses
after relocation
• If the program is not relocated, “zero” value stored in
the program’s relocation register
Relocatable Dynamic Partitions (cont.)
 Compacting and relocating optimizes use of
memory
– Improves throughput
 Options for timing of compaction:
– When a certain percentage of memory is busy
– When there are jobs waiting to get in
– After a prescribed amount of time has elapsed
 Compaction entails more overhead
 Goal: optimize processing time and memory use
while keeping overhead as low as possible
Relocatable Dynamic Partitions (cont.)

There are advantages and disadvantages to each.


End

You might also like