Chapter 2 - Memory Management (Simple Systems)
Chapter 2 - Memory Management (Simple Systems)
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
(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.)
(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?