Operating System - Fragmentation in Memory Management
Fragmentation occurs when memory is wasted or unused due to how processes are allocated. It reduces memory efficiency.
There are two main types:
Internal Fragmentation
Definition:
Internal fragmentation occurs when fixed-sized memory blocks are allocated to processes, but the process doesn’t use the full block, leaving unused space inside the block.
Example:
Assume the OS allocates memory in fixed-size blocks of 4 KB.
-
A process requests 3.6 KB of memory.
-
It is given one 4 KB block (because blocks are fixed).
-
Unused memory = 4 KB – 3.6 KB = 0.4 KB
This 0.4 KB is internal fragmentation — it’s inside the allocated block but not usable by other processes.
External Fragmentation
Definition:
External fragmentation occurs when free memory is split into small blocks scattered throughout, and a large enough block cannot be found for a process even though total free memory is enough.
Example:
Consider total free memory = 10 KB, split into:
-
2 KB (free)
-
3 KB (allocated)
-
1 KB (free)
-
2 KB (allocated)
-
2 KB (free)
Now, a process requests 4 KB of memory.
-
Total free = 5 KB (2 + 1 + 2), so memory is available.
-
But there is no single 4 KB contiguous block.
This is external fragmentation — memory is free, but it's spread out, and not usable as one block.