Open In App

Difference Between Compaction and Defragmentation

Last Updated : 04 Feb, 2022
Like Article

The technique of collection of all the free space in a contiguous manner to make system and memory run efficiently is known as Compaction or Defragmentation. But as the name suggests there is a small difference between them, let’s look into that minor difference.


Compaction is one of the solutions to External Fragmentation. The goal is to shuffle the memory content to place all the free memory together in one block. Compaction is not always possible. If relocation is static and is done at assembly or load time, compaction cannot be done. The simplest compaction algorithm is simply to move all processes towards one end of memory. This scheme can be expensive.


Defragmentation means storing the complete files in the smallest number of contiguous regions. It means it tries to store files as one complete unit if that size of contiguous memory is available. Defragmentation works by locating file fragments that are scattered and putting them back together. The purpose is to decrease file access time and increase space on the hard drive.

Difference between Compaction and Defragmentation




1. Compaction is a process in which the free space is collected in a large memory chunk to make some space available for processes. It is a process that reduces the degree of fragmentation.
2. Compaction is used to reduce external fragmentation. Defragmentation reduces data access time and allows storage to be used more efficiently. 
3. Compaction is only possible if the relocation is dynamic Some operating systems automatically defragment storage periodically
4. It attacks the problem of fragmentation by moving all the allocated blocks to one end of memory, thus combining all the holes. It does this by physically organizing the contents of the mass storage device used to store files into the smallest number of contiguous regions
5. Not always easy to perform compaction. Easy to perform Defragmentation. Many tools are available like Disk Defragment etc.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads