Open In App

What is Fragmentation in Operating System?

Last Updated : 25 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The process of dividing a computer file, such as a data file or an executable program file, into fragments that are stored in different parts of a computer’s storage medium, such as its hard disc or RAM, is known as fragmentation in computing. When a file is fragmented, it is stored on the storage medium in non-contiguous blocks, which means that the blocks are not stored next to each other. 

What is Fragmentation in an Operating System?

An unwanted problem with operating systems is fragmentation, which occurs when processes load and unload from memory and divide available memory. Because memory blocks are so small, they cannot be assigned to processes, and thus remain idle. It’s also important to realize that programs create free space or holes in memory when they are loaded and unloaded. Because additional processes cannot be assigned to these little pieces, memory is used inefficiently.

The memory allocation scheme determines the fragmentation circumstances. These regions of memory become fragmented when the process loads and unloads from it, making it unusable for incoming processes. We refer to it as fragmentation.

Cause of Fragmentation

This can happen when a file is too large to fit into a single contiguous block of free space on the storage medium, or when the blocks of free space on the medium are insufficient to hold the file. Because the system must search for and retrieve individual fragments from different locations in order to open the file, fragmentation can cause problems when reading or accessing the file. 

Effect of Fragmentation

This can reduce system performance and make it more difficult to access the file. It is generally best to defragment your hard disc on a regular basis to avoid fragmentation, which is a process that rearranges the blocks of data on the disc so that files are stored in contiguous blocks and can be accessed more quickly.

Types of Fragmentation

There are two main types of fragmentation: 

1. Internal fragmentation

Internal fragmentation occurs when there is unused space within a memory block. For example, if a system allocates a 64KB block of memory to store a file that is only 40KB in size, that block will contain 24KB of internal fragmentation. When the system employs a fixed-size block allocation method, such as a memory allocator with a fixed block size, this can occur.

Internal fragmentation

2. External fragmentation

External fragmentation occurs when a storage medium, such as a hard disc or solid-state drive, has many small blocks of free space scattered throughout it. This can happen when a system creates and deletes files frequently, leaving many small blocks of free space on the medium. When a system needs to store a new file, it may be unable to find a single contiguous block of free space large enough to store the file and must instead store the file in multiple smaller blocks. This can cause external fragmentation and performance problems when accessing the file.

External fragmentation

Fragmentation can also occur at various levels within a system. File fragmentation, for example, can occur at the file system level, in which a file is divided into multiple non-contiguous blocks and stored on a storage medium. Memory fragmentation can occur at the memory management level, where the system allocates and deallocated memory blocks dynamically. Network fragmentation occurs when a packet of data is divided into smaller fragments for transmission over a network.

How Fragmentation in Operating System affects the System?

  • Slower Performance: Fragmentation slows down the read and write speed of the disk, as the disk head has to move to different locations to access the fragments of a file. This, in turn, increases the access time and reduces the overall speed of the system, causing slowdowns and lag in applications.
  • Disk Space Wasting: Fragmentation can also lead to disk space being wasted, as fragments may occupy more space than required. This can result in a shortage of disk space, causing the system to become unstable and vulnerable to crashes or errors.
  • Data Loss: In severe cases, fragmentation can also cause the system to run out of disk space, leading to data loss. This can be particularly detrimental to users who rely on their systems to store critical information and data.
  • Increased Risk of System Crashes: The more fragmented a disk becomes, the more prone it is to crashes and errors. This can cause the system to become unstable and vulnerable to data loss, crashes, and other issues.
  • Reduced Battery Life: Fragmentation can also negatively impact the battery life of laptops and other mobile devices. This is because fragmentation requires the disk to work harder, which in turn puts additional strain on the battery.

Role of Fragmentation in Operating System

Fragmentation is a critical issue that can significantly impact the performance of an operating system. The primary role of fragmentation is to slow down the read and write speed of the disk. As the disk head has to move to different locations to access the fragments of a file, the access time increases, reducing the overall speed of the system. This can lead to a decrease in system performance, causing slowdowns and lag in applications. Moreover, fragmentation can also lead to disk space being wasted, as fragments may occupy more space than required. This can result in a shortage of disk space, causing the system to become unstable and vulnerable to crashes or errors. In severe cases, fragmentation can also cause the system to run out of disk space, leading to data loss.

To maintain optimal performance, it is essential to regularly defragment the disk. Defragmentation reorganizes the fragments of a file and allocates contiguous disk space to store the file. This helps to improve the read and write speed of the disk, reducing access time and increasing the overall speed of the system. By regularly defragmenting the disk, the performance of the operating system can be improved and maintained, ensuring a smooth and efficient user experience.

Advantages of Fragmentation

There are several potential benefits to fragmentation:

  • It makes better use of storage space on a computer’s hard disc or other storage medium. When a file is fragmented, it can be stored in the medium’s available free-space blocks, even if those blocks are not contiguous. This is especially useful if the medium contains a large number of small blocks of free space that would otherwise be wasted.
  • It can improve system performance by reducing the amount of seeking required by the system’s hard disc drive (HDD) or solid-state drive (SSD). When a file is stored on the medium in contiguous blocks, the HDD or SSD must move its read/write head to different locations on the disc to access the various blocks.
  • It can enable a system to store larger files than it could otherwise. If the system does not have a single contiguous block of free space large enough to store a specific file, the file can be fragmented and stored in multiple smaller blocks.

However, it is generally recommended to minimize fragmentation whenever possible, as it can have a negative impact on system performance and make accessing and managing files more difficult.

Disadvantages of Fragmentation

  • It can degrade system performance, particularly when reading or accessing fragmented files. When a system needs to access a fragmented file, it must search for and retrieve the various fragments from various locations on the storage medium, which can take longer than accessing a contiguous file. This can reduce system performance and make it more difficult to access the file.
  • It can make managing and organizing files on a system more difficult. When a file is fragmented, it is stored on the storage medium in multiple non-contiguous blocks, making it more difficult to locate and access the file.
  • It has the potential to shorten the lifespan of a storage medium, such as a hard disc or solid-state drive. When a system writes data to a storage medium, it can cause the medium to wear out. Data stored in non-contiguous blocks can cause more wear and tear on the medium than data stored in contiguous blocks, potentially reducing the medium’s lifetime.
  • It can consume more system storage space. When a file is fragmented, the system must store additional information on the storage medium about the location of each fragment. This can consume more space and limit the amount of space available for other files.

FAQs on Fragmentation in Operating System

Q.1: What is system fragmentation?

Answer:

In computing, file system fragmentation is also known as file system aging, System fragmentation is technique of a file system to lay out the contents of files non-continuously to allow in-place change of their contents.

Q.2: What is difference between Segmentation and Fragmentation in OS?

Answer:

While segmentation is a technique that includes breaking a process up into several modules or sections, fragmentation is a situation in which memory chunks are left unused.

Q.3: What is memory fragmentation?

Answer:

Memory fragmentation occurs when your memory is divided up into several non-sequential chunks and gaps that are too big to be used for new memory allocations.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads