Skip to content
Related Articles

Related Articles

Compaction in Operating System

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Expert
  • Last Updated : 17 Dec, 2021

Compaction is a technique to collect all the free memory present in form of fragments into one large chunk of free memory, which can be used to run other processes.

It does that by moving all the processes towards one end of the memory and all the available free space towards the other end of the memory so that it becomes contiguous.

It is not always easy to do compaction. Compaction can be done only when the relocation is dynamic and done at execution time. Compaction can not be done when relocation is static and is performed at load time or assembly time.

Before Compaction

Before compaction, the main memory has some free space between occupied space. This condition is known as external fragmentation. Due to less free space between occupied spaces, large processes cannot be loaded into them.

Main Memory
Occupied space
Free space
Occupied space
Occupied space
Free space

After Compaction

After compaction, all the occupied space has been moved up and the free space at the bottom. This makes the space contiguous and removes external fragmentation. Processes with large memory requirements can be now loaded into the main memory.

Main Memory
Occupied space
Occupied space
Occupied space
Free space
Free space

Purpose of Compaction in Operating System

While allocating memory to process, the operating system often faces a problem when there’s a sufficient amount of free space within the memory to satisfy the memory demand of a process. however the process’s memory request can’t be fulfilled because the free memory available is in a non-contiguous manner, this problem is referred to as external fragmentation. To solve such kinds of problems compaction technique is used.

Issues with Compaction

Although the compaction technique is very useful in making memory utilization efficient and reduces external fragmentation of memory, the problem with it is that a large amount of time is wasted in the process and during that time the CPU sits idle hence reducing the efficiency of the system.

Advantages of Compaction

  • Reduces external fragmentation.
  • Make memory usage efficient.
  • Memory becomes contiguous.
  • Since memory becomes contiguous more processes can be loaded to memory.

Disadvantages of Compaction

  • System efficiency reduces.
  • A huge amount of time is wasted in performing compaction.
  • CPU sits idle for a long time.
  • Not always easy to perform compaction.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!