Partitioned Memory Allocation
Partitioned Memory Allocation
Allocation Policies
Best Fit
First Fit
Worst Fit
Buddy Allocation
First Fit Allocation
1K bytes
To allocate n bytes, use the
first available free block
such that the block size is
larger than n. 2K bytes 2K bytes
Simplicity of implementation
Requires:
Free block list sorted by address
Allocation requires a search for a suitable partition
Deallocation requires a check to see if the freed partition
could be merged with adjacent free partitions (if any)
Example
Allocate 1K Deallocate last Deallocate 3rd
6K 6K 6K 6K
1K 1K 1K
4K
3K 3K
4K 4K 4K
11K
1K 1K
4K
3K 3K
First Fit Allocation
Advantages Disadvantages
Simple External fragmentation
Tends to produce larger
free blocks toward
the end of the address
space
Best Fit Allocation
1K bytes 1K bytes
To allocate n bytes, use the
smallest available free
block such that the block
size is larger than n. 2K bytes 2K bytes
6K 6K 6K 6K
4K 4K 4K
8K
4K 4K 4K
1K 1K 1K 1K
3K 3K 3K 3K
Best Fit Allocation
Advantages Disadvantages
Works well when most External fragmentation
allocations are of small Slow allocation
size Slow deallocation
Relatively simple Tends to produce many useless
tiny fragments (not really
great)
Worst Fit Allocation
1K bytes 1K bytes
To allocate n bytes, use
the largest available
free block such that the
block size is larger than 2K bytes
n.
6K 6K 6K 6K
2K 2K 2K
4K
2K 2K
5K 5K 5K
7K
1K 1K 1K
3K
2K 2K 2K
Worst Fit Allocation
Advantages Disadvantages
Works best if External fragmentation
allocations are of Tends to break large free
medium sizes blocks such that large
partitions cannot be
allocated
Buddy Allocation
8K bytes 8K bytes
Example (cont’d)
Deallocate 2nd block Deallocate 3rd block
2K bytes
4K bytes
2K bytes
2K bytes 2K bytes
2K bytes 2K bytes
16K bytes
8K bytes 8K bytes
Buddy Allocation (cont’d)
Advantages Disadvantages
Fast allocation Internal fragmentation
Fast deallocation External fragmentation
Very simple data
structures (log n + 1
lists of available
blocks, at max)
Multiprogramming