Difference between Internal and External fragmentation
|Internal Fragmentation||External Fragmentation|
|When a process is allocated more memory than required, few space is left unused and this is called as INTERNAL FRAGMENTATION||After execution of processes when they are swapped out of memory and other smaller processes replace them, many small non contiguous(adjacent) blocks of unused spaces are formed which can serve a new request if all of them are put together but as they are not adjacent to each other a new request can’t be served and this is known as EXTERNAL FRAGMENTATION.|
|It occurs when memory is divided into fixed-sized partitions.||It occurs when memory is divided into variable-sized partitions based on size of process.|
|It can be cured by allocating memory dynamically or having partitions of different sizes.||It can be cured by Compaction, Paging and Segmentation.|
Here is a short video i made to help you understand better!
- It arises when we use fixed sized partitioning.
- Some part of the memory is kept for operating system and the rest is available for user space.
- In this case the user space is divided into blocks of 10 KB each.
- When process 1 with size 8 KB is allocated a block of 10 KB, 2 KB space is left unused. When process 2 with size 10 KB is allocated a !0 KB block no space is left unused. When process 3 with size 9KB is allocated a 10 KB block, 1KB is left unused.
- Here 2 processes are allocated space more than required and this unused space is so small to store a new process and is wasted. This is called as INTERNAL FRAGMENTATION.
- It arises when dynamic partitioning technique is used.
- Here memory is allocated to the processes dynamically based on their size.
- So in the above example, the user space contains processes 1,2 & 3 Out of which process 1 & 3 complete their execution and are swapped out and two other processes, process 4 & 5 are swapped in their places.
- Process 4 takes place of process 1 but as its size is only 8 KB, it is allocated only 8 KB and rest is left unused.
- Process 5 takes place of process 3. It is allocated 6 KB space and 8 KB is left unused.
- Now suppose a new process, process 6 wants to be swapped in and its size is 6 KB. Though we have total 6 KB space but we cannot service this request as these blocks are not contiguous(adjacent). This is called as EXTERNAL FRAGMENTATION.