What is Fragmentation in Operating System? Types and Causes

 
  
          
What is Fragmentation in Operating System
Fragmentation in Operating System


 Fragmentation in Operating System

Operating system fragmentation occurs when processes are loaded and unloaded from memory, causing free memory space to become fragmented. Because memory blocks are so tiny, they are unable to be allocated to processes and stay empty.

Every time a process enters RAM, contiguous memory allocation allots space to the process. Either dynamic or fixed partitioning is used to split these RAM areas. These regions of memory become fragmented when the process loads and unloads from it, making them unusable for subsequent processes.


What is Fragmentation in an Operating System?


Operating system fragmentation, which happens when processes load and unload from memory and split available memory, is an undesirable issue. Because memory blocks are so tiny, they are unable to be allocated to processes and stay empty. It's also critical to understand that as programs are loaded and unloaded, empty space or holes in memory are created. These little bits of memory are not able to be given to further processes, which results in wasteful utilization of memory.

The fragmentation conditions are determined by the memory allocation method. When a process loads and unloads, these memory regions get fragmented, rendering them unsuitable for incoming processes. We call this process "fragmentation."


Causes of Fragmentation

The main memory is used to load and unload user programs, and it also houses processes in memory blocks. After a process loads and swaps, there are many spaces left behind that are too big for another process to load. Because main memory processes are allocated dynamically, even while main memory is accessible, there is not enough space in it to load another process.


Effect of Fragmentation

System performance may suffer as a result, and file access may become more challenging. To prevent fragmentation, which is a procedure that rearranges the data blocks on the disc so that files are kept in continuous blocks and can be accessed more rapidly, it is generally advisable to defragment your hard disk on a regular basis.


Types of Fragmentation

In the operating system, fragmentation mostly occurs in two ways. They are listed below:

  • Internal Fragmentation
  • External Fragmentation

1. Internal Fragmentation

When a memory block contains unused space, internal fragmentation takes place. For instance, a system allocating 64KB of RAM to hold a 40KB file will result in 24KB of internal fragmentation in that block. This can happen if the system uses a fixed-size block allocation technique, like a memory allocator with a defined block size.

For Example:
Assume that fixed partitioning—that is, memory chunks with fixed sizes—is used for RAM memory allocation. Sizes of 2MB, 4MB, 4MB, and 8MB are available. A portion of this RAM is used by the operating system.


Assume a 3MB process P1 is introduced and is allocated a 4MB memory block. Consequently, this block's 1MB of free space is wasted and cannot be utilized to allot memory to another process. We call this internal disarray.


How Should the OS Handle Internal Fragmentation?

We are unable to load a 6MB process into RAM at this time. This is because the process is loaded using a contiguous memory allocation. Here, it is evident that when a process is given a block that is larger than it is intended to be, memory is wasted and cannot be utilized by another process. In OS, this is referred to as internal fragmentation.


There are no pre-established partitions in this case. As long as we have free contiguous memory available, we allocate RAM to the processes based on their sizes.

External Fragmentation

When a storage media, like a hard disk or solid-state drive, has a lot of little free space blocks dispersed throughout it, external fragmentation happens. This may occur when a system repeatedly adds and removes files, which leaves the medium with numerous little empty blocks. When a system has to store a new file, it might not be able to locate a single, big enough block of free space at one time and will have to store the file in smaller chunks instead. Performance issues with file access and external fragmentation may result from this.

For Example:

Take external fragmentation as an example. The memory is not contiguous, as seen in the above figure, but there is enough room (50 KB) to execute a process (05), however 45 KB is needed. The vacant space can be utilized to carry out a process through the use of segmentation, paging, and compaction.


How Can External Fragmentation Be Removed?

The reason for external fragmentation is that we are allocating memory in a contiguous manner above. The first half of the 6MB process will be loaded into the 2MB hole, and the remaining two portions will be loaded into the 4MB hole, assuming we can split the process up into three parts of 2MB each.

Alternatively, the two holes of size 2MB and 4MB might be combined to create a single 6MB hole. It is now simple to load this process into the RAM.


Advantages and Disadvantages of Fragmentation

Fragmentation has a number of benefits and drawbacks. Here are a few of them:

Advantages

Fragmentation has several benefits. Here are a few of them:

  • Quick Data Writers :It might be quicker to write data in a system that allows for data fragmentation than to rearrange storage to allow for contiguous writes of data.
  • .Reduced Inadequacies :The write will fail in a system that does not allow fragmentation if there is not enough sequential space.
  • .Optimizing Storage :By using every storage block that is accessible, a fragmented system may be able to utilize a storage device more efficiently.

Disadvantages

  • System performance may suffer as a result, especially while reading or accessing fragmented files. It can take longer for a system to access a fragmented file than it would for a contiguous file because it has to look for and retrieve the numerous fragments from different locations on the storage medium. System performance may suffer as a result, and file access may become more challenging.
  • It may complicate file management and organization on a system. A fragmented file makes it harder to find and retrieve since it is stored on the storage medium in several non-contiguous parts.
  • It could make a storage media, like a solid-state drive or hard disc, less resilient. The wear and tear of a storage medium can occur from a system writing data to it. The medium's lifespan may be shortened by data stored in non-contiguous blocks since they may experience greater wear and tear than data stored in contiguous blocks.
  • It might use up more system storage. When a file is broken up into smaller pieces, the system needs to keep track of where each piece is located on the storage media. This may use up more space and reduce the amount that may be used for other files.

Conclusion

In summary, operating system fragmentation is the inefficient utilization of memory caused by the division of accessible memory into tiny, non-contiguous pieces. This lowers system performance by making it challenging to assign big memory blocks to applications. Internal fragmentation, in which memory allotted is left unused, and external fragmentation, in which memory that is free is dispersed, are the two primary forms. System performance and memory efficiency are enhanced by reducing fragmentation.


What is fragmentation in operating system?

When a process is loaded and unloaded from memory, free memory space becomes fragmented, an undesirable issue with the operating system is referred to as fragmentation. The small size of the memory blocks prevents the processes from being assigned to them. As a result, the memory blocks are never used.


What is internal and external fragmentation?

When a process's memory block exceeds its needs, internal fragmentation occurs. External fragmentation occurs when non-contiguous memory blocks remain after the removal of a process.


What is the difference between partitioning and fragmentation?

The RDBMS determines the nomenclature. Partitioning is a database feature in SQL Server that can be used to enhance your database's manageability and/or performance. When insert/delete operations cause your rows in the data pages to be non-contiguous, this is known as fragmentation.


What distinguishes OS segmentation from fragmentation?

Fragmentation is the state in which memory portions remain unused, whereas segmentation is a technique that involves dividing a process into multiple modules or pieces.