Skip to content

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 locationInside a blockBetween blocks
CauseFixed block sizesVariable allocations over time
FixSmaller blocksCompaction or paging
Does paging cause it?YesNo
Does segmentation cause it?NoYes

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.