- Fragmentation is the primary problem faced while allocating memory. In this article we will focus on Fragmentation and steps to minimize it. Fragmentation can be of two types:
- Internal Fragmentation
- External Fragmentation
- External fragmentation arises when free memory areas existing in a system are too small to be allocated to processes.
- When enough total memory space exists to allocate a process but it is not contiguous, storage space is fragmented into a large number of small blocks. Such unused small free blocks which are outside to partitions are referred to as external fragmentation.
- Statistical analysis shows that with allocation of N blocks, another 0.5 blocks may be lost due to fragmentation. That is, one-third of memory may be unusable! This property is known as the 50-percent rule.
- Internal fragmentation exists when the memory allocated to a process is not fully utilized by it.
- When a process is allocated a larger block than the size of the process, some memory area inside the partition becomes unusable. This type of memory wastage is considered as internal fragmentation.
- In other words, internal fragmentation is the amount of unusable memory which is inside to a partition.
- A possible solution to reduce external fragmentation is compaction.
- A compaction is a process to merge different unused small free blocks in the memory to produce a large free block.
- The kernel periodically can perform memory compaction to reduce total amount of external fragmentation.
- It involves movement of processes (dynamic relocation) in the memory during their execution. It can be implemented by using relocation register.
- Consider process C in the figure (a) that contains address 3M bytes when C is in execution. We have two free memory blocks available one is followed by process A and other free block is followed by process D.
- During compaction, C is moved to the memory area with start address 2M bytes (figure b). Similarly process D is moved to process C’s memory area.
- After compaction, we have one large free block at the bottom that is used to load process E (figure c).
- Dynamic relocation is not practical if the computer system does not use relocation register.