CoursifyCoursify

Memory Fragmentation: Internal vs. External Fragmentation

Memory Fragmentation: Internal vs. External Fragmentation

Verified Sources
May 28, 2026

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:

  1. 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. []
  2. 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

  1. Fragmentation in Operating System - GeeksforGeeks - Detailed explanation of memory fragmentation and its impact on system performance.

  2. Key Difference Between Internal And External Fragmentation - Unstop - Comparative analysis of internal and external memory allocation issues.

  3. 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 SpartitionS_{partition} represent the fixed size of an allocated memory block or partition, and let SprocessS_{process} represent the actual memory requested by a process. If the partition is assigned to this process, then:

SpartitionSprocessS_{partition} \ge S_{process}

The resulting internal fragmentation FinternalF_{internal} within that partition is defined as:

Finternal=SpartitionSprocessF_{internal} = S_{partition} - S_{process}

If a system contains MM active partitions, each holding a process of size Sprocess,iS_{process, i} within a partition of size Spartition,iS_{partition, i}, the total internal fragmentation Ftotal_internalF_{total\_internal} is the sum of the individual wastes: []

Ftotal_internal=i=1M(Spartition,iSprocess,i)F_{total\_internal} = \sum_{i=1}^{M} (S_{partition, i} - S_{process, i})

2. External Fragmentation

Let physical memory contain nn scattered, non-contiguous free blocks (holes), where the size of the ii-th free block is sis_i. The total available free memory SfreeS_{free} is: []

Sfree=i=1nsiS_{free} = \sum_{i=1}^{n} s_i

If a new process requests a contiguous chunk of memory of size SreqS_{req}, external fragmentation occurs when:

SfreeSreqandsi<Sreq i{1,2,,n}S_{free} \ge S_{req} \quad \text{and} \quad s_i < S_{req} \quad \forall \ i \in \{1, 2, \dots, n\}

In this scenario, the system has enough total free memory to satisfy the request, but because no individual free block sis_i is large enough, the process cannot be loaded. []

Footnotes

  1. Fragmentation - Raghunathpur College - Academic lecture notes defining the mathematical difference between memory allocated and required space.

  2. 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 NN allocated blocks are maintained in dynamic partitioning, another 0.5N0.5 N 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

  1. 1
    Step 1

    The operating system scans the active memory tables to identify all currently allocated memory segments and the scattered free blocks ('holes') between them.

  2. 2
    Step 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 Sfree=i=1nsiS_{free} = \sum_{i=1}^{n} s_i.

  3. 3
    Step 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: Basenew=Baseold+ΔBase_{new} = Base_{old} + \Delta.

  4. 4
    Step 4

    All individual free holes are merged into a single, contiguous block of free memory of size SfreeS_{free} 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 1

Early 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 2

Memory 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 3

Partitions 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 4

Compaction 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 5

Paging and Segmentation are introduced, completely eliminating external fragmentation and minimizing internal fragmentation."

Deep Dive FAQs: Fragmentation Edge Cases

Knowledge Check

Question 1 of 4
Q1Single choice

If a system uses fixed-size partitioning of size 16 KB16\text{ KB} and a process of size 11 KB11\text{ KB} is loaded, what is the resulting internal fragmentation?

Explore Related Topics

1

Memory Allocation with First-Fit and Best-Fit

2

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 20 KB20\text{ KB} process in a 32 KB32\text{ KB} 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 10 KB+12 KB+18 KB=40 KB10\text{ KB}+12\text{ KB}+18\text{ KB}=40\text{ KB} into a single 40 KB40\text{ KB} block for a 30 KB30\text{ KB} request.
  • Compaction is expensive because it involves process relocation and address updates.
3

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.
Chat with Kiro