Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between compaction and defragmentation?

My operating systems textbook says that compaction is a process that rearranges disk blocks such that all free disk blocks form a contiguous "chunk" of free disk space.

But I always thought that was what defragmentation does? Are these two terms the same? Or am I missing something?

like image 587
vladimirm Avatar asked May 28 '14 22:05

vladimirm


1 Answers

Compaction :- means moving the "in-use" memory areas to eliminate holes caused by terminated processes.Suppose we have five processes A, B, C, D, E, allocated as |A|B|C|D|E| in memory. After sometime process B and D are terminated. Now we have memory layout as |A| |C| |E|. After applying compaction we will have |A|C|E| | | i.e instead of two one-block memory unit we have one two-block memory unit.

Defragmentation :- means storing complete file in smallest number of contiguous regions. That is, it tries to store file as one complete unit if that size of contiguous memory is available. Suppose process A has fragments A1, A2, A3, process B has fragments B1, B2. Now, suppose memory layout is |A1|B1|A2|A3|B2|, after defragmentation we have |A1|A2|A3|B1|B2|.

Defragmentation can also contribute to compaction.

like image 124
codeFreak Avatar answered Oct 12 '22 11:10

codeFreak