Compaction

As we know, fixed and dynamic partitioning suffers from external fragmentation. However, this issue can be overcome through compaction.

In compaction, all the holes are contiguous, and OS combines all the loaded processes in different partitions. 

Now, merged holes can accommodate new processes according to their needs. This method is also known as de-fragmentation. Let us explain through the diagram.

compaction

After compaction, the process P8 can be loaded into the main memory easily because contiguous space is available now.

Problems with Compaction

The system’s efficiency also decreases because the CPU is set to idle at the time of compaction.

Explanation: At the time of compaction, the CPU stops the execution of the current process because it will resume the process from somewhere else after compaction. If the CPU does not stop the execution of a process, then it may execute the instructions from somewhere else locations instead of the next instruction of the same process in memory.

Note: Consider an OS that requires 6 NS time to transfer 1-B. Then, 1 MB transfer needs (1 X 2^20) X (6 X 10 ^ -9) seconds.

So, transferring a large amount of data requires a huge amount of time.

1. Complex Memory Allocation

In Fixed partitioning, the list of partitions is made once and will never change.

Allocation and de-allocation take place very frequently in dynamic memory allocation. So, partition size also changes each time in allocation and de-allocation. That’s why it is very difficult for OS to manage everything at a time.

How do we manage allocation and de-allocation?

OS uses the following data structures for memory allocation and de-allocation.

Both of these concepts, we will discuss in the next post.