5 Difference Between Internal And External Fragmentation (With Examples)

SHARE

What Is Internal And External Fragmentation?

Internal fragmentation is when a process is allocated more memory than required, and therefore, few space is left unused.  For example:

When process 1 with the size of 10KB is allocated a block of 12KB, 2KB space is left unused. Now, when process 2, with size 10 KB is allocated a 0KB block, no space is left unused. When process 3 with size 12KB is allocated a 13 KB block, 1KB is left unused.  From this example, 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 what is referred to as Internal Fragmentation.

External Fragmentation happens when a dynamic memory allocation algorithm allocates some memory and a small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced. Total memory space exists to satisfy a request but it is not contiguous.  External fragmented blocks are available for allocation, but may be too small to be of any use.

Key Difference

  1. External fragmentation occurs due to the lack of enough adjacent space after loading and unloading of programs or files for some time because then all free space is distributed here and there. On the other hand, internal fragmentation occurs when a fixed size partition is assigned to a program/file with less size than the partition making the rest of the space in that partition unusable. 
  2. After execution of processes when they are swapped out of memory and other smaller processes replace them, many small non-contagious (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 referred to as external fragmentation. When a process is allocated more memory than required little space is left unused and this is referred to as internal fragmentation. Internal fragmentation occurs when a fixed size memory allocation technique is used whereas external fragmentation occurs when a dynamic memory allocation technique is used.
  3. Internal fragmentation can be prevented by having partitions of several sizes and assigning a program based on the best fit. On the contrary, external fragmentation can be prevented by methods such as paging and segmentation whereby a logical contiguous virtual memory space is given whereas in reality the files/programs are separated into parts and placed here and there.
  4.  In internal fragmentation, fixed sized blocks the leftover space in one block cannot be used for other processes whereas in external fragmentation the removed process leaves a space or hole and the memory appears as a collection of small holes rather than a chunk.

READ FURTHER: Difference Between Paging And Segmentation In OS

Difference Between Internal And External Fragmentation In Tabular Form     

BASIS OF COMPARISON   INTERNAL FRAGMENTATION EXTERNAL FRAGMENTATION
Occurrence External fragmentation occurs due to the lack of enough adjacent space after loading and unloading of programs or files for some time because then all free space is distributed here and there. Internal fragmentation occurs when a fixed size partition is assigned to a program/file with less size than the partition making the rest of the space in that partition unusable.   
Condition Internal fragmentation occurs when a fixed size memory allocation technique is used. External fragmentation occurs when a dynamic memory allocation technique is used.  
Prevention Internal fragmentation can be prevented by having partitions of several sizes and assigning a program based on the best fit. External fragmentation can be prevented by methods such as paging and segmentation whereby a logical contiguous virtual memory space is given whereas in reality the files/programs are separated into parts and placed here and there.
Processes In internal fragmentation, fixed sized blocks the leftover space in one block cannot be used for other processes. In external fragmentation the removed process leaves a space or hole and the memory appears as a collection of small holes rather than a chunk.
     

Also Read: Difference Between Paging And Segmentation