150 likes | 254 Views
Lecture 14 Memory Management III. Variable Partition Allocation. Variable Partitions. The number, location, and size of the partitions vary dynamically as processes come and go Improves memory utilization. Process is allocated exactly as much memory as required
E N D
Lecture 14 Memory Management III Variable Partition Allocation M.B. Ibáñez
Variable Partitions • The number, location, and size of the partitions vary dynamically as processes come and go • Improves memory utilization. Process is allocated exactly as much memory as required • The number and size of the processes in memory vary dynamically throughout the day • Complicates allocating and deallocating memory M.B. Ibáñez
OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 10 process 2 process 2 process 2 process 2 Example M.B. Ibáñez
OS OS OS OS OS OS OS 128 K 320 K 320 K 320 K 320 K 320 K 320 K Process 1 Process 1 Process 1 Process 1 Process 1 Process 1 128 K 128 K 224 K 224 K Process 4 Process 4 Process 2 Process 2 96 K 96 K 896 K 576 K Process 3 288 K Process 3 288 K Process 3 Process 3 288 K 288 K 64 K 64 K 64 K 64 K External fragmentation problem OS 320 K Process 1 224 K Process 3 288 K 64 K M.B. Ibáñez
OS 320 K Process 1 128 K Process 4 96 K Process 3 288 K 64 K Solution: Compaction OS 320 K Process 1 128 K Process 4 288 K Process 3 Process 5 100K 60K M.B. Ibáñez
Placement algorithms revisited • Best-fit • Chooses the block that is closest in size to the request • worst performer overall • since smallest block is found for process, the smallest amount of fragmentation is left memory compaction must be done more often M.B. Ibáñez
Placement algorithms revisited • First-fit • Begins to scan memory from the beginning and chooses the first available block that is large enough • fastest • may have many process loaded in the front end of memory that must be searched over when trying to find a free block M.B. Ibáñez
Placement algorithms revisited • Next-fit • Begins to scan memory from the location of the last placement and chooses the next available block that is large enough. • more often allocate a block of memory at the end of memory where the largest block is found • the largest block of memory is broken up into smaller blocks • compaction is required to obtain a large block at the end of memory M.B. Ibáñez
8K 8K 12K 12K First Fit 22K 6K Best Fit Last allocated block (14K) 18K 2K 8K 8K 6K 6K Allocated block Free block 14K 14K Next Fit 36K 20K Before After Placement algorithmsExample M.B. Ibáñez
Memory Managementwith Bit Maps • Memory is divided up into allocation units, perhaps as small as few words and perhaps as large as several kilobytes • Corresponding to each allocation unit is a bit in the bit map, which is 0 if the unit is free and 1 if it is occupied • A bit map provides a simple way to keep track of memory words in a fixed amount of memory because the size of the bit map depends only on the size of memory and the size of the allocation unit M.B. Ibáñez
Memory Managementwith Bit Maps M.B. Ibáñez
Memory Managementwith Linked Lists • Another way of keeping track of memory is maintaining a linked list of allocated and free memory segments. • A segment is either a process or a hole between two processes M.B. Ibáñez
Memory Managementwith Linked Lists M.B. Ibáñez
Memory Managementwith the Buddy System • Available blocks of size 2k, L≤ k ≤U • 2L is the smallest block that is allocated • 2U is the largest size block that is allocated • To begin, the entire space available for allocation is treated as a single block of size 2U • if a request of size s such as 2U-1 < s ≤ 2U is made, then the entire block is allocated • Otherwise, the block is split into two equal buddies of size 2U-1. (The process is repeated) M.B. Ibáñez
Memory Managementwith the Buddy System M.B. Ibáñez