Compaction

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Compaction

Compaction is a technique to collect all the free memory present in the 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.

For students preparing for competitive exams like GATE , understanding memory management
techniques such as compaction is crucial. Our GATE course offers detailed coverage of these
concepts, including practical examples and scenarios, to help you grasp the intricacies of dynamic
and static relocation and their implications for memory management.

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, thereby
increasing scalability of OS.

 Fragmentation of file system can be temporarily removed by compaction.

 Improves memory utilization as their is less gap between memory blocks.

Disadvantages of Compaction

 System efficiency reduces and latency is increased.

 A huge amount of time is wasted in performing compaction.

 CPU sits idle for a long time.

 Not always easy to perform compaction.

 It may cause deadlocks since it disturbs the memory allocation process.

You might also like