1. Overview
In this tutorial, we’ll discuss external fragmentation in the operating system with a practical example. In addition, we’ll explore the possible reasons for the occurrence of external fragmentation.
Finally, we’ll talk about the impact of external fragmentation.
2. What Is External Fragmentation?
External fragmentation is a memory management-related issue in computer systems where available memory space isn’t used efficiently. In the case of external fragmentation, the available memory is split into small, non-contiguous blocks.
Therefore, it results in large empty spaces that we can’t use to store data, even though the total amount of memory space is enough. Additionally, external fragmentation leads to inefficiency in memory utilization and can negatively impact system performance.
Now let’s take an example to understand how external fragmentation occurs and how to fix it. Let’s consider a memory system with 14 MB of memory. Out of all the memory, we allocate 7 MB of memory to the two existing processes, P1 and P2. Hence, the remaining available memory is 7 MB:
Now, the operating system starts a process P3. The process P3 requires 2 MB of memory. Let’s assign P3:
Therefore, after we assign the process P3, the remaining memory is 5 MB. Now, the operating system starts another process, P4. In order to allocate memory to P4, the memory requirement is 4 MB. As we can see, we have free memory of 5 MB, but the memory blocks are not contiguous. Hence, even though we have the required memory, we can’t allocate the process P4. The easiest way to fix this issue is to merge the available memory blocks and create a single contiguous memory block:
3. Reasons for Occurrence and Removal Approaches
External fragmentation happens in an operating system due to how we allocate and deallocate memory. When a process requests memory from an operating system, the memory manager finds a free block of memory that is big enough to fulfil the request.
After completion of the execution, the process deallocates the allocated memory. Now, the memory manager is left with a small block of unused memory that may not be big enough to fulfill the next memory allocation request. Over time, these small, unused blocks can accumulate and cause external fragmentation.
We can use memory allocation algorithms that minimize waste and prevent the fragmentation of free memory blocks in order to reduce external fragmentation. One such algorithm is the buddy memory allocation algorithm. This algorithm divides memory into blocks of different sizes. Therefore, it allocates memory in a way that minimizes the amount of memory waste and fragmentation.
Another common method is to use a memory manager that performs compaction. Compaction is a method that involves moving blocks of memory to reduce the amount of external fragmentation. Additionally, using a virtual memory system, the operating system swaps less frequently used memory pages to disk. In this way, we can reduce external fragmentation.
Finally, we can utilize the garbage collection method that automatically reclaims the memory that is no longer being used. Hence, it reduces external fragmentation in the memory.
4. Impact of External Fragmentation
External fragmentation in an operating system has several implications. Some important implications include inefficiency in memory utilization, reduction in performance, limited memory availability, increased fragmentation over time, and difficulty in memory management.
When external fragmentation occurs, small blocks of unused memory are scattered throughout the memory space. The unused scattered memory blocks make the operating system unable to utilize the available memory. Hence, as the number of unused scattered memory blocks grows, the inefficiency in memory utilization increases.
Additionally, when memory is externally fragmented, the operating system has to search for larger contiguous memory blocks. Therefore, the additional time in search for the necessary memory block can slow down the allocation process and negatively impact system performance.
External fragmentation can make it difficult to allocate large blocks of memory, even when there is enough memory available in total. As a result, it can lead to increased swapping and paging. When we perform more swapping and paging, it can slow down the system and degrade its performance.
External fragmentation worsens over time as we allocate and deallocate more memory, resulting in many small, unused memory blocks. Additionally, it can make it difficult for the memory manager to manage memory effectively, leading to further inefficiencies in memory utilization.
Therefore, it’s important for an operating system to use a memory allocation algorithm that minimizes external fragmentation in order to ensure efficient memory utilization and good system performance.
5. Conclusion
In this article, we discussed external fragmentation in the operating system with a practical example. We explored several possible reasons for the occurrence of external fragmentation. Finally, we presented some important consequences when external fragmentation occurs.