1. Contiguous allocation and fragmentation
The CPU generates logical (virtual) addresses; the MMU maps them to physical addresses. In the simplest scheme a relocation (base) register is added to each address and a limit register checks that it is in range.
With variable partitions, free memory is a set of holes. To place a process of size :
| Policy | Picks | Note |
|---|---|---|
| First fit | first hole | fast; usually good |
| Next fit | like first fit, from where the last search stopped | spreads allocations |
| Best fit | smallest hole | leaves tiny unusable holes; searches all |
| Worst fit | largest hole | leaves big holes; often worst in practice |
Fragmentation:
- External: enough total free memory, but not in one piece. Happens with variable partitions and segmentation. Fixed by compaction (needs dynamic relocation) or by paging.
- Internal: space wasted inside an allocated block, because blocks come in fixed sizes. Happens with fixed partitions and paging (on average half a page per process).
Segmentation divides a program into logical units (code, stack, data). A logical address is (segment, offset); the segment table holds base and limit, and an offset limit causes a trap. Segments vary in size, so segmentation has external fragmentation but no internal fragmentation.