Memory Fragmentation: Internal vs. External Fragmentation
In modern Memory Management, the efficiency of physical memory (RAM) utilization is a primary performance bottleneck. As the operating system (OS) dynamically loads and terminates processes, physical memory is continuously allocated and deallocated. Over time, this dynamic allocation cycle leads to a phenomenon known as Fragmentation. []
Fragmentation refers to the condition where physical memory becomes broken into small, non-contiguous pieces, rendering a portion of the system's memory capacity unusable. Even if the total amount of free memory is mathematically sufficient to run a process, the system may fail to allocate memory because the free space is not contiguous or is trapped within already allocated blocks. []
Memory allocation strategies generally fall into two categories: Fixed Partitioning (where memory is split into static, predetermined blocks) and Dynamic Partitioning (where memory is allocated on-demand based on process size). These two paradigms suffer from different types of fragmentation:
- Internal Fragmentation: Occurs when memory is allocated in fixed-size blocks. If a process requires less memory than the block size, the remaining space within that block is wasted and cannot be used by other processes. []
- External Fragmentation: Occurs when memory is allocated dynamically. As processes finish and leave, they create "holes" of free memory. Although the aggregate free space across all holes may be large, it is scattered in non-contiguous chunks, making it impossible to satisfy a single large memory request. []
The diagram below illustrates how both forms of fragmentation manifest in physical memory:
Footnotes
-
Fragmentation in Operating System - GeeksforGeeks - Detailed explanation of memory fragmentation and its impact on system performance. ↩
-
Key Difference Between Internal And External Fragmentation - Unstop - Comparative analysis of internal and external memory allocation issues. ↩
-
Fragmentation - Raghunathpur College - Academic lecture notes defining the mathematical difference between memory allocated and required space. ↩ ↩2
Memory Fragmentation Explained: Internal & External
Mathematical Formulations of Fragmentation
To analyze fragmentation quantitatively, we can define formal mathematical models for both types of memory waste.
1. Internal Fragmentation
Let represent the fixed size of an allocated memory block or partition, and let represent the actual memory requested by a process. If the partition is assigned to this process, then:
The resulting internal fragmentation within that partition is defined as:
If a system contains active partitions, each holding a process of size within a partition of size , the total internal fragmentation is the sum of the individual wastes: []
2. External Fragmentation
Let physical memory contain scattered, non-contiguous free blocks (holes), where the size of the -th free block is . The total available free memory is: []
If a new process requests a contiguous chunk of memory of size , external fragmentation occurs when:
In this scenario, the system has enough total free memory to satisfy the request, but because no individual free block is large enough, the process cannot be loaded. []
Footnotes
-
Fragmentation - Raghunathpur College - Academic lecture notes defining the mathematical difference between memory allocated and required space. ↩
-
Fragmentation in Operating System(OS) | by Ritesh Ranjan - Medium - Breakdown of contiguous memory allocation rules and external fragmentation conditions. ↩ ↩2
Key Difference to Remember
Internal fragmentation is a waste of space inside an allocated block of memory because the partition size is larger than the requested size. External fragmentation is a waste of space between allocated memory blocks because the free blocks are too small and scattered to satisfy new requests.
Memory Fragmentation Overhead Comparison
Estimated percentage of wasted memory due to fragmentation under different memory management techniques
The 50-Percent Rule
According to Knuth's 50-Percent Rule, for a first-fit allocation strategy, if allocated blocks are maintained in dynamic partitioning, another blocks will be lost to external fragmentation. This means that about one-third of memory can be wasted due to external fragmentation!
The Compaction Process to Eliminate External Fragmentation
- 1Step 1
The operating system scans the active memory tables to identify all currently allocated memory segments and the scattered free blocks ('holes') between them.
- 2Step 2
The system sums the sizes of all non-contiguous free memory blocks to determine if the consolidated free space is sufficient to host waiting processes. Let total free space be .
- 3Step 3
The system shifts all active processes dynamically toward one end of the physical memory. This requires updating the base registers of each relocated process to point to their new physical starting addresses: .
- 4Step 4
All individual free holes are merged into a single, contiguous block of free memory of size at the other end of physical memory, ready for new allocations.
Performance Overhead of Compaction
While Compaction resolves external fragmentation, it is computationally expensive. It requires copying all data of active processes in memory, which consumes significant CPU cycles and suspends process execution during the transfer.
Evolution of Memory Management and Fragmentation Control
Contiguous Allocation & Single Partitioning
Phase 1Early operating systems loaded a single program into memory. There was no internal or external fragmentation from multiple processes, but memory utilization was extremely low."
Fixed Partitioning (MFT)
Phase 2Memory is divided into fixed-size partitions. Multiple processes can run, but it introduces severe internal fragmentation when process sizes do not match partition sizes."
Dynamic/Variable Partitioning (MVT)
Phase 3Partitions are allocated dynamically based on process requirements. This eliminates internal fragmentation but introduces external fragmentation as processes terminate and leave scattered holes."
Compaction Techniques
Phase 4Compaction is introduced to merge scattered free holes into a single block. However, the high CPU overhead makes it impractical for real-time and high-performance systems."
Paging & Segmentation (Modern OS)
Phase 5Paging and Segmentation are introduced, completely eliminating external fragmentation and minimizing internal fragmentation."
Deep Dive FAQs: Fragmentation Edge Cases
Knowledge Check
If a system uses fixed-size partitioning of size and a process of size is loaded, what is the resulting internal fragmentation?
Explore Related Topics
Memory Allocation with First-Fit and Best-Fit
Fixed Partition vs Variable Partition in Operating Systems, and the Need for Compaction
Fixed and variable partitioning are contiguous memory allocation schemes that differ in when partitions are created and the type of fragmentation they produce, prompting the use of compaction.
- Fixed partitioning: static predefined partitions, simple implementation, limited multiprogramming, suffers internal fragmentation (e.g., a process in a partition).
- Variable partitioning: dynamic partitions sized to each process, higher memory utilization, but creates external fragmentation requiring placement algorithms.
- Compaction moves processes to coalesce free holes, turning scattered space such as into a single block for a request.
- Compaction is expensive because it involves process relocation and address updates.
Fault vs Failure
Faults are underlying causes of erroneous system states, while failures are the observable deviations of service from expected behavior; understanding this distinction is essential for dependability, reliability, and software quality.
- A fault (design, implementation, or hardware defect) can remain dormant or be masked by fault‑tolerance.
- Activation of a fault creates an error, an internal incorrect state.
- Propagation of an error to the service interface results in a failure visible to users.
- Multiple faults may exist without immediate failures if they are never triggered.
- The mental model: human mistake → fault → activation → error → failure.
