Appearance
34. Fragmentation (Internal / External)
Wasted memory that exists but can't be used — two different causes.
Internal fragmentation: waste inside an allocated block, because memory is handed out in fixed-size chunks that rarely fit your data exactly (e.g., request 13KB, get a 16KB block, 3KB wasted inside it). Common in paging and fixed-size allocators.
External fragmentation: waste between allocated blocks — enough total free memory exists, but it's scattered in pieces too small to satisfy a request (e.g., 60KB free total, but no contiguous 50KB block). Common in contiguous file allocation and variable-size heap/RAM partitioning.
| Internal External | ||
|---|---|---|
| Waste location | Inside a block | Between blocks |
| Cause | Fixed block sizes | Variable allocations over time |
| Fix | Smaller blocks | Compaction or paging |
| Does paging cause it? | Yes | No |
| Does segmentation cause it? | No | Yes |
Fixes: internal → smaller block/page sizes (trade-off: larger page tables). External → compaction (expensive — move data, update pointers) or paging, which eliminates external fragmentation entirely since any free frame can be used.