Fragmentation & Its types in the operating system/What is fragmentation?/ What are the types of fragmentation?

Hello Friends, In this blog post(What is fragmentation) I am going to explain to you the problem of fragmentation and its classification in the operating system. Fragmentation problem is related to an unused memory block which is generally left in a case when a process block is either of higher memory or lower memory with respect to the available memory block.

In other words, if the total available memory is divided into multiple partitions of fixed size or variable-sized either statically or dynamically, the unused memory space remains internal or external to the partitions. When a process comes and requests for memory, its request is not satisfied while the sum of memory unused is greater than the process’s request. This phenomenon or problem is known as fragmentation(What is fragmentation).

Fragmentation is classified into two categories on the basis of static and dynamic allocation of memory. One is internal fragmentation where memory blocks remain of fixed size. And another is external fragmentation where memory block is allocated at run time as per requirement of memory|What is fragmentation|

Types of fragmentation:

Internal Fragmentation:

The phenomenon, in which there is a wasted space internal to a partition due to the fact that the block of data loaded is smaller than the partition, is referred to as internal fragmentation.

When the partition is static that is fixed-sized partitioning, memory is wasted in each partition due to an object of a smaller size than the partition itself is loaded. For example, suppose there is partition of 10232 bytes in memory and a request comes for 10230 bytes of memory. If this request is satisfied then 2 bytes of memory will be left unused. This is also shown in the below-given fig.

internal-fragmentation
Fig: Internal Fragmentation

External Fragmentation:

The phenomenon in which there is a waste space external to partition due to the fact the memory that is external to all the partitions becomes increasingly fragmented is referred to as external fragmentation.

Dynamic partitioning or multiprogramming with variable partitions eliminates internal fragmentation by making each partition only as large as necessary to satisfy a request for space for an object.

With dynamic partitioning, those partitions are of variable length and number. When a process is brought into the main memory, it is allocated exactly as much memory as it requires and no more. An example using 64Mbytes of main memory is shown in the below-given fig.

external-fragmentation-content
Fig: External Fragmentation- The effect of dynamic partitioning

Initially, the main memory is empty, except for the operating system as shown in fig(a). The first three processes are loaded in, starting where the operating system ends and occupying just enough space for each process as shown in fig (b) (c) (d). This leaves hole at the end of the memory. That is too small for a fourth process.

At some point, none of the processes in memory is ready. The operating system swaps out process 2 as shown in fig(e), which leaves sufficient room to load a new process. Now, it loads process 4 as in fig(f).

Because process 4 is smaller than process 2, another small hole is created. Later a point is reached at which none of the processes in main memory is ready, but process 2, in the ready-suspended state, is available.

Because there is not sufficient room in memory for process 2, the operating system swaps process 1 out and swaps in process 2, as shown in fig(g). and (h) respectively. Thus it leads to a situation in which there are a lot of small holes in memory that is external fragmentation.

So it is clear that external fragmentation solves the problem of internal fragmentation but it still suffers from the problem of unused memory space at run time.

One technique for overcoming external fragmentation is memory compaction. From time to time, the operating system shifts the processes so that they are contiguous and so that all the free memory is together in one block. For example, as shown in fig(h), compaction will result in block of free memory of length of 16M, which can be easily used for another process.

In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post about What is fragmentation & What are the types of fragmentation.

Please feel free to give your important feedbacks in the comment section below|What is fragmentation|

Have a great time! Sayonara!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.