Fixed Dynamic Mem Management DSB
Fixed Dynamic Mem Management DSB
Fixed/Variable
Partitioning
D S Bais
Real Memory Management
• Background
• Memory Management Requirements
• Fixed/Static Partitioning
• Variable/Dynamic Partitioning
• Simple/Basic Paging
• Simple/Basic Segmentation
• Segmentation with Paging
2
Contiguous Allocation
• An executing process must be loaded entirely in main
memory (if overlays are not used).
• Main memory is usually split into two (Memory split)
or more (Memory division) partitions:
– Resident operating system, usually held in low memory
partition with interrupt vector.
– User processes then held in high memory partitions.
• Relocation registers used to protect user processes
from each other, and from changing OS code and data:
– Base register contains value of smallest physical address.
– Limit register contains range of logical addresses –
each logical address must be less than the limit register.
– MMU maps logical address dynamically.
3
Real Memory Management Techniques
4
Fixed Partitioning
• Equal-size partitions:
– If there is an available partition, a process
can be loaded into that partition –
• because all partitions are of equal size, it does
not matter which partition is used.
– If all partitions are occupied by blocked
processes, choose one process to swap out to
make room for the new process.
6
Placement Algorithm with Partitions
• Unequal-size partitions,
use of multiple queues:
– assign each process to the
smallest partition within
which it will fit.
– a queue exists for each
partition size.
– tries to minimize internal
fragmentation.
– problem: some queues
might be empty while
some might be loaded.
7
Placement Algorithm with Partitions
• Unequal-size partitions,
use of a single queue:
– when its time to load a
process into memory,
the smallest available
partition that will hold
the process is selected.
– increases the level of
multiprogramming at
the expense of internal
fragmentation.
8
Dynamics of Fixed Partitioning
10
Variable Partitioning
– Degree of multiprogramming limited by number of partitions.
– Variable-partition sizes for efficiency (sized to a given process’ needs).
– Hole – block of available memory; holes of various size are scattered
throughout memory.
– When a process arrives, it is allocated memory from a hole large enough to
accommodate it.
– Process exiting frees its partition, adjacent free partitions combined.
– Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
11
Managing allocated and free partitions
• Example: memory with 5 processes and 3 holes:
– tick marks show memory allocation units.
– shaded regions (0 in the bitmap) are free.
12
Memory Management with Linked Lists
13
Variable Partitioning: example
14
Internal/External Fragmentation
• There are really two types of fragmentation:
1. Internal Fragmentation –
allocated memory may be slightly larger than
requested memory; this size difference is
memory internal to a partition, but not being
used.
2. External Fragmentation –
total memory space exists to satisfy a size n
request, but that memory is not contiguous.
15
Reducing External Fragmentation
• Reduce external fragmentation by doing
compaction:
– Shuffle memory contents to place all free
memory together in one large block (or
possibly a few large ones).
– Compaction is possible only if relocation is
dynamic, and is done at execution time.
– I/O problem:
• Lock job in memory while it is involved in I/O.
• Do I/O only into OS buffers.
16
Comments on Variable Partitioning
• Partitions are of variable length and number.
• Each process is allocated exactly as much
memory as it requires.
• Eventually holes are formed in main memory.
This can cause external fragmentation.
• Must use compaction to shift processes so they
are contiguous; all free memory is in one block.
• Used in IBM’s OS/MVT (Multiprogramming
with a Variable number of Tasks).
17
Dynamic Storage-Allocation Problem
21
Knuth’s Buddy System
• A reasonable compromise to overcome disadvantages
of both fixed and variable partitioning schemes.
• Memory allocated using power-of-2 allocation;
Satisfies requests in units sized as power of 2.
• Memory blocks are available in size of 2^{K} where L
<= K <= U and where:
– 2^{L} = smallest size of block allocatable.
– 2^{U} = largest size of block allocatable
(generally, the entire memory available).
• A modified form is used in Unix SVR4 for kernel
memory allocation.
22
Buddy System Allocation
23
Example of Buddy System
24
Tree Representation of Buddy System
25
Dynamics of Buddy System (1)
• We start with the entire block of size 2^{U}.
• When a request of size S is made:
– If 2^{U-1} < S <= 2^{U} then allocate the entire block of size
2^{U}.
– Else, split this block into two buddies, each of size 2^{U-1}.
– If 2^{U-2} < S <= 2^{U-1} then allocate one of the 2 buddies.
– Otherwise one of the 2 buddies is split again.
• This process is repeated until the smallest block greater or equal
to S is generated.
• Two buddies are coalesced whenever both of them become
unallocated.
26
Dynamics of Buddy System (2)
• The OS maintains several lists of holes:
– the i-list is the list of holes of size 2^{i}.
– whenever a pair of buddies in the i-list occur, they
are removed from that list and coalesced into a
single hole in the (i+1)-list.
• Presented with a request for an allocation of
size k such that 2^{i-1} < k <= 2^{i}:
– the i-list is first examined.
– if the i-list is empty, the (i+1)-list is then
examined ...
27
Comments on Buddy System
• Mostly efficient when the size M of memory
used by the Buddy System is a power of 2:
– M = 2^{U} “bytes” where U is an integer.
– then the size of each block is a power of 2.
– the smallest block is of size 1.
• On average, internal fragmentation is 25%
– each memory block is at least 50% occupied.
• Programs are not moved in memory:
– simplifies memory management.
28