Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Fragmentation is an unwanted problem that arises due to memory allocation and deallocation. In contiguous memory, allocation is done in a continuous fashion. The spaces in the RAM are divided based on fixed partitioning or dynamic partitioning. When the processes get loaded and unloaded from the main memory, the allotted spaces get broken into small pieces. The broken spaces can't be allocated to the new processes due to several reasons, which we’ll discuss in this article. This problem is called fragmentation.
Basically, there are two types of fragmentation:
Internal Fragmentation
External Fragmentation
What is Internal Fragmentation in OS?
Internal fragmentation occurs when fixed-sized memory blocks are allocated to the processes. When free space is created during the time of memory assignment is slightly larger than the memory requested by the process, internal fragmentation occurs. The unused space is considered fragmented since it cannot be used for other processes.
For Example: Let's consider a fixed partitioning scheme where the memory blocks are of fixed sizes( say 4MB each). Now, suppose a process of size 3 MB comes and occupies a block of memory. So, the 1MB space in this block is free and can’t be used to allocate it to other processes. This is called internal fragmentation. The diagram below shows memory division, where each memory block is size 4MB.
How to Removel Internal Fragmentation?
We have seen above that the problem occurs when we have a fixed-partitioning scheme. Therefore, we can use dynamic partitioning to deal with this problem. In dynamic partitioning, the processes are allocated only the required amount of space. This considerably reduces the problem of internal fragmentation.
What is External Fragmentation in OS?
External fragmentation arises when we are unable to allocate space to a process in spite of the fact that we have total space available in the memory, but that space is not contiguous.
The holes or vacant spaces created by leaving process mark empty spaces in the memory, and the non-contiguous spaces are not a good fit to accommodate a new upcoming process.
For example: Suppose there are many processes present in the main memory, and two processes each of size 4 MB leave the memory. A total of 8MB + 2MB = 10MB memory space is free now. Now a new process equal to the sum of total available space can’t be loaded into the main memory as the unused space is not in a contiguous fashion. This is known as external fragmentation.
In the diagram given below, two processes of sizes, 8MB and 10MB try to enter into the memory, but neither of them can be loaded as no contiguous space of 8MB or 10MB is available.
How to Removel External Fragmentation?
One way to reduce external fragmentation is to allocate memory non-contiguously to the processes, which is done by paging and segmentation. Another technique is Compaction.
Difference Between Internal and External Fragmentation
The main differences between internal and external fragmentation are illustrated in the table given below:
Now, head to head Comparison:
Parameter
Internal Fragmentation
External Fragmentation
Definition,
The difference between the memory space needed and the assigned memory is considered as internal fragmentation.
When there are empty spaces among the non-contiguous memory blocks that cannot be assigned to any process, this problem is considered as external fragmentation.
Memory Block size
In internal fragmentation, the memory blocks are of fixed size.
In external fragmentation, the memory blocks are of varying sizes.
Occurrence
Internal fragmentation occurs when we divide physical memory into contiguous mounted-sized blocks and allocate memory for a process that may be larger than the amount of memory requested. As a result, the unused allocated space remains and cannot be used by other processes.
External fragmentation occurs when a process or processes are removed from the main memory and the free spaces created are too small to fit a new process.
Solution
The use of a dynamic partitioning scheme and best-fit block search are the solutions that can reduce internal fragmentation.
Compaction, paging, and segmentation are the solutions for external fragmentation.
External fragmentation, also known as memory fragmentation, occurs in memory management when free memory blocks are scattered throughout the memory space, making it challenging to allocate large contiguous blocks for incoming processes. This can lead to inefficient memory utilization and performance degradation.
What is the difference between replication and fragmentation?
Replication involves duplicating data across multiple nodes or systems to enhance availability and fault tolerance. Fragmentation, on the other hand, refers to the division of data into smaller parts for storage efficiency. Replication aims for redundancy, while fragmentation focuses on optimizing storage utilization.
What is the difference between internal and external index fragmentation?
Internal index fragmentation occurs when the index nodes have space that is not completely filled with pointers, impacting performance. External index fragmentation arises when the physical order of index pages does not match the logical order, leading to slower access times.
What is the difference between external fragmentation and segmentation?
External fragmentation occurs in memory allocation when free memory is scattered throughout the memory space, making it difficult to allocate contiguous blocks efficiently. Segmentation, on the other hand, divides memory into variable-sized segments, each representing a logical unit, but can also lead to fragmentation.
Conclusion
This article has discussed fragmentation and its variations: internal and external fragmentation. We also discussed how to remove these two fragmentations and important differences between the two based on various parameters.