What is Fragmentation in Operating System?
Last Updated :
16 Jul, 2024
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. In this article, we are going to discuss fragmentation in detail along with its type, working, role, advantages, and disadvantages.
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:
- Internal Fragmentation
- External 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.

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.

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
- 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
- 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.
Conclusion
In conclusion, fragmentation in an operating system refers to the inefficient use of memory, where available memory is broken into small, non-contiguous blocks. This makes it difficult to allocate large blocks of memory to programs, reducing overall system performance. There are two main types: internal fragmentation, where allocated memory has unused space, and external fragmentation, where free memory is scattered. Reducing fragmentation helps improve the efficient use of memory and system performance.
Similar Reads
Disk Defragmentation in Operating System
In the world of computer storage management, retaining the performance of Hard Disk Drives (HDDs) is important for ensuring easy operation and responsiveness of the running system. One key method used to obtain this is disk defragmentation. As data is written, modified, and deleted on a disk through
5 min read
What is an Operating System?
An Operating System is a System software that manages all the resources of the computing device. Acts as an interface between the software and different parts of the computer or the computer hardware. Manages the overall resources and operations of the computer. Controls and monitors the execution o
9 min read
What is Demand Paging in Operating System?
Demand paging is a memory management scheme used in operating systems to improve memory usage and system performance. Let's understand demand paging with real life example Imagine you are reading a very thick book, but you donât want to carry the entire book around because itâs too heavy. Instead, y
10 min read
File System Implementation in Operating System
A file is a collection of related information. The file system resides on secondary storage and provides efficient and convenient access to the disk by allowing data to be stored, located, and retrieved. File system implementation in an operating system refers to how the file system manages the stor
11 min read
Compaction in Operating System
Compaction is a technique to collect all the free memory present in the form of fragments into one large chunk of free memory, which can be used to run other processes. It does that by moving all the processes towards one end of the memory and all the available free space towards the other end of th
3 min read
Worst-Fit Allocation in Operating Systems
For both fixed and dynamic memory allocation schemes, the operating system must keep a list of each memory location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must be allocated. These partitions can be allocated using four different methods,
2 min read
What is Mainframe Operating System?
Operating System is a fully integrated set of specialized programs that handle all the operations of the computer. The operating system is the most important type of system software in a computer system. Examples of Operating Systems are Windows, Linux, Mac OS, etc. Let's understand the Mainframe Op
4 min read
Design and Implementation in Operating System
The design of an operating system is a broad and complex topic that touches on many aspects of computer science. This article will cover the design of operating systems in general and then focus on the implementation aspect. Design Goals:Design goals are the objectives of the operating system. They
6 min read
Directory Implementation in Operating System
Directory implementation in the operating system can be done using Singly Linked List and Hash table. The efficiency, reliability, and performance of a file system are greatly affected by the selection of directory-allocation and directory-management algorithms. There are numerous ways in which the
3 min read
Functions of Operating System
An Operating System acts as a communication interface between the user and computer hardware. Its purpose is to provide a platform on which a user can execute programs conveniently and efficiently. The main goal of an operating system is to make the computer environment more convenient to use and to
7 min read