The Wayback Machine - https://web.archive.org/web/20241110033324/https://www.geeksforgeeks.org/what-is-fragmentation-in-operating-system/
Open In App

What is Fragmentation in Operating System?

Last Updated : 16 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

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

  • 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.

Frequently Asked Questions on Fragmentation – FAQs

What is system fragmentation?

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.

What is difference between Segmentation and Fragmentation in OS?

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.

What is memory fragmentation?

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.



Similar Reads

Internal Fragmentation in OS
Internal Fragmentation is a problem that occurs due to poor memory allocation and it results in wastage of memory. When a process is loaded into the system it requests memory which is essential for its working. The operating system allocates memory to processes to work with but if the memory happens to be smaller and bigger than the process require
5 min read
Difference Between Fragmentation and Compaction
In an operating system, memory management plays a vital role in maximum CPU utilization, when space is allocated to a process there is some loss of memory(fragmentation) leads to inefficient use of memory, and to reduce this loss one of the techniques (compaction) is used to optimize memory space. What is Fragmentation?Fragmentation occurs when the
4 min read
External Fragmentation in OS
Free spaces in the memory, sometimes referred to as fragments, are created whenever a process is loaded or unloaded from the physical memory block. As these regions are not continuous, no process can be given a contiguous allocation of these small memory chunks. As a result, the RAM is squandered and is not available to other processes. This issue
9 min read
Difference Between Fragmentation and Segmentation in OS
Memory management is an essential part of the operating system that concerns itself with the allocation, control, and release of memory resources. This is because every application that is executed will require some space for its data, code, and execution stacks, which also creates the need for appropriate strategies to address. Two main aspects of
5 min read
Difference between Internal and External fragmentation
Memory fragmentation is a prevalent problem in operating systems that can result in the inefficient use of memory resources. There are two types of fragmentation: internal and external, and they both have an impact on memory allocation and use. In this article, we are going to study the difference between Internal and External fragmentation in deta
4 min read
System Protection in Operating System
Introduction: System protection in an operating system refers to the mechanisms implemented by the operating system to ensure the security and integrity of the system. System protection involves various techniques to prevent unauthorized access, misuse, or modification of the operating system and its resources. There are several ways in which an op
3 min read
User View Vs Hardware View Vs System View of Operating System
User View of Operating System: The Operating System is an interface, hides the details which must be performed and present a virtual machine to the user that makes it easier to use. Operating System provides the following services to the user. Execution of a programAccess to I/O devicesControlled access to filesError detection (Hardware failures, a
1 min read
Xv6 Operating System -adding a new system call
Prerequisite - Xv6 Operating System -add a user program In last post we got to know how to add user program in Xv6 Operating System. Now here you will see how to add new system call in Xv6 Operating System. A dding new system call to xv6: A system call is way for programs to interact with operating system. A computer program makes system call when
6 min read
Traps and System Calls in Operating System (OS)
Traps and system calls are two mechanisms used by an operating system (OS) to perform privileged operations and interact with user-level programs. Here is an overview of each mechanism: Traps: A trap is an interrupt generated by the CPU when a user-level program attempts to execute a privileged instruction or encounters an error. When a trap occurs
3 min read
Fork System Call in Operating System
In many operating systems, the fork system call is an essential operation. The fork system call allows the creation of a new process. When a process calls the fork(), it duplicates itself, resulting in two processes running at the same time. The new process that is created is called a child process. It is a copy of the parent process. The fork syst
5 min read
System Programs in Operating System
System Programming can be defined as the act of building Systems Software using System Programming Languages. According to Computer Hierarchy, Hardware comes first then is Operating System, System Programs, and finally Application Programs. Program Development and Execution can be done conveniently in System Programs. Some of the System Programs ar
3 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 storage and retrieval of data on a physical storage de
11 min read
Difference between System Software and Operating System
Software is like a set of instructions that tell a computer what to do. There are two main types application software and system software. Application software is extra programs you can add to your computer to do specific things, like write documents or play games. You don't need these to use your computer, but they help you do particular tasks. Sy
5 min read
Banker's Algorithm in Operating System
Prerequisite - Resource Allocation Graph (RAG), Banker’s Algorithm, Program for Banker’s Algorithm Banker's Algorithm is a resource allocation and deadlock avoidance algorithm. This algorithm test for safety simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-state” check to test for possible acti
15 min read
Swap Space in Operating System
A computer has a sufficient amount of physical memory but most of the time we need more so we swap some memory on disk. Swap space is a space on a hard disk that is a substitute for physical memory. It is used as virtual memory which contains process memory images. Whenever our computer runs short of physical memory it uses its virtual memory and s
6 min read
Thread Models in Operating System
A thread is a light weight process which is similar to a process where every process can have one or more threads. Each thread contains a Stack and a Thread Control Block. There are four basic thread models : 1. User Level Single Thread Model : Each process contains a single thread.Single process is itself a single thread.process table contains an
2 min read
The Tempo Operating System
Operating system : An Operating system is an interface between the computer user and computer hardware. An Operating system is a software which performs all the basic task like file handling, file management, memory management, handling input and output, controlling peripherals devices such as disk drive and printer, mouse...etc Tempo operating sys
5 min read
Boot Block in Operating System
Basically for a computer to start running to get an instance when it is powered up or rebooted it need to have an initial program to run. And this initial program which is known as bootstrap needs to be simple. It must initialize all aspects of the system, from CPU registers to device controllers and the contents of the main memory, and then starts
5 min read
Comparison on using Java for an Operating System instead of C
Java is a managed language which offers memory safety. In Java, pointers do not exist, so we cannot do pointer arithmetic on a function pointer. An application can invoke a method defined in a class through the class object. In Java, we cannot do unsafe typecast of an object to overwrite the method pointer with something else. An out of bound array
2 min read
Difference between Loading and Linking in Operating System
An operating system acts as an intermediary between the user of a computer and computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs conveniently and efficiently. Linking and Loading are utility programs that play an important role in the execution of a program. Linking intakes the o
4 min read
Stack Implementation in Operating System uses by Processor
A stack is an associate ordered a set of components, only one of that (last added) are often accessed at a time. The point of access is named the highest of the stack. The number of components within the stack, or length of the stack, is variable. Items could solely be side to or deleted from the highest of the stack. For this reason, a stack is ad
4 min read
Best-Fit Allocation in Operating System
INTRODUCTION: Best-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process. Once a suitable block is found, the operating system spli
4 min read
Thread Control Block in Operating System
Very similar to Process Control Blocks (PCBs) which represents processes, Thread Control Blocks (TCBs) represents threads generated in the system. It contains information about the threads, such as it's ID and states. The components have been defined below: Thread ID: It is a unique identifier assigned by the Operating System to the thread when it
1 min read
Two State Process Model in Operating System
Pre-requisite: States of a Process in Operating Systems The process in an operating system passes from different states starting from its formation to its completion. A process consists of program data and its associated data and a process control block (PCB). A process may change its state because of the following events like I/O requests, interru
3 min read
I/O Hardware in Operating System
I/O Hardware is a set of specialized hardware devices that help the operating system access disk drives, printers, and other peripherals. These devices are located inside the motherboard and connected to the processor using a bus. They often have specialized controllers that allow them to quickly respond to requests from software running on top of
6 min read
Completely Fair Queuing (CFQ) in Operating System
Several Linux I/O schedulers have been proposed. Some of these are: Completely Fair Queuing (CFQ) Deadline NOOP Anticipatory CFQ is one of the input/output scheduler for the Linux kernel and is the current default scheduler in the Linux kernel. What is kernel ? Kernel is the central part of an operating system. It manages the operation between the
2 min read
Concurrent Processes in Operating System
Concurrent processing is a computing model in which multiple processors execute instructions simultaneously for better performance. Concurrent means, which occurs when something else happens. The tasks are broken into subtypes, which are then assigned to different processors to perform simultaneously, sequentially instead, as they would have to be
2 min read
Time Sharing Operating System
Multiprogrammed, batched systems provide an environment where various system resources were used effectively, but it did not provide for user interaction with computer systems. Time-sharing is a logical extension of multiprogramming. The CPU performs many tasks by switches that are so frequent that the user can interact with each program while it i
5 min read
List scheduling in Operating System
Prerequisite - CPU Scheduling List Scheduling also known as Priority List Based Scheduling is a scheduling technique in which an ordered list of processes are made by assigning them some priorities. So, basically what happens is, a list of processes that are ready to be executed at a given point is made. And then depending on the availability of pr
3 min read
Priority Assignment to Tasks in Operating System
Assigning priority to tasks : When the number of tasks with different relative deadlines are more than the priority levels supported by the operating system, then some tasks share the same priority value. But the exact method of assigning priorities to tasks can proficiently affect the utilization of processor. If the tasks are randomly selected fo
3 min read
three90RightbarBannerImg