2. Compaction
Memory compaction is the process of moving
allocated objects together and leaving empty space
together.
It is a technique that is used when memory is divided into
variable-size partitions. Compaction refers to combining
all the empty spaces together and processes. By applying
this technique, we can store the bigger processes in the
memory. The free partitions are merged which can now be
allocated according to the needs of new processes.
3. Compaction is the process of moving memory around to
eliminate most of the smaller holes and make one larger hole. On
hole. On storage disks, this is known as disk defragmentation – a
a well used utility in mostWindows operating systems. Like
defragmentation, compaction is very time expensive. It is possible
possible to perform a partial compaction, simply to create a hole in
in memory large enough to house the new process that is
attempting to execute. i.e. compaction is a method to overcome the
the external fragmentation problem.
What is compaction ??
4. The idea of compaction is to move all processes towards one end of memory and all the free blocks of memory towards
the other end. For example, consider the case in which the blocks are distributed between 2 processes as shown in the
below image.
Now, using the compaction algorithm, we move process P2 upwards and the free block of 100 K between P1 and P2
downwards thus forming a big block of 500 K. However, compaction is possible only when dynamic relocation is used
i.e. when the address binding is done at runtime.
5. Consider a system with 3 pages and about 50% of
their objects are allocated. By compacting, all the living
living objects are moved into the first two pages, leaving
leaving the second half of the second page and the third
third page completely empty.The empty page can then
then be ignored during future mark/sweep phases since
since it is known to be empty of living objects, or it can
can be released and returned to the desired operating
system.
6. Advantages of compactions
In memory management, swapping creates multiple fragments in the
memory because of the processes moving in and out.
Compaction helps to solve the problem of fragmentation, but it requires
too much of CPU time.
It moves all the occupied areas of store to one end and leaves one large
free memory or space for incoming jobs in one large block, instead of
numerous small ones.
In compaction, the system also maintains relocation information and it
must be performed on each new allocation of job to the memory or
completion of job from memory.
Reduces external fragmentation. All free blocks are brought together as
one large block of free space.
7. Now imagine a storage “pool” managed by the
operating system. Processes then request from the OS to be
granted the use of storage fragments of various sizes, use
them, and then “free” them when done. This all happens in a
generally random fashion. Over time, storage in the pool will
tend to become fragmented, meaning that the segments
that are in use and those that are free will be scattered all
through the pool. Now some process requests a large piece
of storage from the OS, and the OS cannot satisfy that
request because, although the total amount of free/unused
storage in the pool is large, there is no single contiguous
“piece” that is large enough to satisfy the request. At this
point, the OS has to compact the pool which means
reorganize the arrangement of the free and used areas by
moving them in real storage and updating the virtual storage
address lookup tables so that their virtual addresses remain
8. We got to know that the dynamic partitioning suffers from external
fragmentation. However, this can cause some serious problems.
To avoid compaction, we need to change the rule which says that the process
can't be stored in the different places in the memory.
We can also use compaction to minimize the probability of external
fragmentation. In compaction, all the free partitions are made contiguous and
all the loaded partitions are brought together.
By applying this technique, we can store the bigger processes in the memory.
The free partitions are merged which can now be allocated according to the
needs of new processes. This
technique is also called defragmentation.
As shown in the image, the process P5, which could not be loaded into the
memory due to the lack of contiguous space, can be loaded now in the
memory since the free partitions are made contiguous.
9. Problems/disadvantages of Compaction
The efficiency of the system is decreased in the case of
compaction due to the fact that all the free spaces will be
transferred from several places to a single place.
Huge amount of time is invested for this procedure and the
remain idle for all this time. Despite of the fact that the
avoids external fragmentation, it makes system inefficient.
Large sized memory transfer needs some huge amount of
in seconds.