Compaction in Memory Management Tutorial-9


In Dynamic partition scheme of Contiguous
memory allocation we have the problem of external fragmentation in which even though we have
an available memory space since it is fragmented across different parts of the memory we won’t
be able to use it. So here suppose here we have a process request
of 300 Kb and we have an available memory space of 450 KB but since the memory space
is not contiguous we won’t be able to load this process to the memory
Now to overcome the problem of external fragmentation in dynamic partitioning scheme we can use
one method called compaction. so what is Compaction .Compaction is the method by which we bring
all the empty spaces together I.e we pull together all the occupied spaces
as a result all the empty spaces or holes are brought together
so in this example either we can pull all the processes up so P3 now P6 can be moved or followed
by the process P2 and hence the empty space of 450KB is drawn together down so here we
require the movement of the 2 processes P6 of 600kb and P2 of 200 KB so total 800KB of data have to
be moved. So one other way is we can pull down all theprocesses. P2 now followed by P6 now P3 is also pulled down this will bring the empty space of 450
KB at the beginning portion of the memories .again we require the movement of 2 processes
thus 200 + 600 again 800kb of data has to be moved here.
now one other way is here we have a Hole of 200kb and here we have one process of 200
kb instead of moving 2 processes just bring the process P2 to this hole this will again bring
out the occupy space us together and all the empty space together can here we have to move
just one process and only 200 kb of data have to be So compared to the previous cases here
we require the least movement of data.Anyway compaction is not considered as a good solution
for external fragmentation because we have to invest a considerable amount of time for
movement of the processes and during which the execution of the processes have to be stopped
.Thus compaction is an expensive task and hence it is not considered as a good solution
for external fragmentation