What is memory fragmentation?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Operating Systems topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Memory fragmentation is the inability to use available memory because it's in small, non-contiguous pieces. Two types: External fragmentation: total free memory is enough to satisfy a request, but it's scattered in small non-contiguous chunks — no single large chunk available: Memory: [Used 10K][Free 5K][Used 8K][Free 3K][Used 15K][Free 7K] Total free: 15K, but largest contiguous: 7K. A 10K request FAILS even though 15K is free!. Cause: variable-size allocation and deallocation creating "holes." Solutions: compaction (move processes to fill holes — expensive, requires relocation), paging (no external fragmentation — any page/frame pair works). Internal fragmentation: allocated memory is slightly more than requested — wasted space within an allocated region: Request: 18KB allocation system allocates in 4KB chunks: allocates 20KB (5 × 4KB) Internal waste: 2KB (unusable space inside the allocated block). Cause: fixed-size allocation units (pages, blocks). Larger allocation units → more internal fragmentation. Smaller units → more overhead. Solutions: external: compaction (move allocations to consolidate free space — requires process relocation), paging (non-contiguous allocation in equal-size frames). Internal: smaller allocation unit size, buddy system (power-of-2 sizes, merge buddies on free). Best Fit / First Fit / Worst Fit allocation policies: affect external fragmentation patterns. Best Fit minimizes waste per allocation but creates many small unusable holes. First Fit is fastest. Worst Fit leaves larger free chunks — empirically often worse.
Common Mistake
Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Operating Systems answers easy to follow.
Previous
What is the dining philosophers problem?
Next
What is the difference between multiprogramming, multitasking, and multiprocessing?