External fragmentation refers to the condition where free memory space is split into small, non-contiguous blocks due to the allocation and deallocation of memory over time. These small free spaces scattered throughout the memory are not large enough to accommodate new processes or requests, even though there may be enough total free memory.
This type of fragmentation arises when memory is allocated and deallocated dynamically, causing free memory to be fragmented into small blocks of unused space, which makes it difficult to use the available memory efficiently.
External fragmentation happens primarily in systems that allocate memory in variable-sized blocks. When a process is allocated memory and later deallocated, the memory that was used by that process becomes free. However, since memory allocation and deallocation may occur in different locations and sizes, this results in small gaps or "fragments" of free memory between allocated regions.
For example:
Consider a memory system with the following scenario:
At some point, Process 1 terminates and its allocated memory is freed. Now the memory space might look like this:
| 200 KB (Free) | 300 KB (Allocated) | 400 KB (Allocated) |
Then, if Process 4 requires a 150 KB block, it cannot be placed in the free 200 KB space, as there are small gaps in between allocated memory. This is where external fragmentation causes a problem.
Let’s look at a visual example of memory allocation and deallocation:
| Allocation | Allocation | Allocation | Free Space | Allocation | Free Space | Free Space |
| 200 KB | 300 KB | 400 KB | 100 KB | 250 KB | 50 KB | 100 KB |
Here, there is a total of 1000 KB of memory. However, free memory is fragmented into several smaller blocks, such as:
If a new process requires 500 KB, the system can’t allocate it despite having 1000 KB of free space because the largest contiguous free block available is only 250 KB, which is not enough.
There are several techniques used by operating systems to manage and reduce external fragmentation:
Compaction is the process of rearranging the contents of memory to combine the free blocks of memory into larger contiguous blocks. By shifting the processes together and moving them to adjacent areas, the free space is consolidated into one large block. However, this process can be time-consuming and resource-intensive, as it requires copying data from one part of memory to another.
Example: After compaction, the memory might look like this:
| Allocation | Allocation | Allocation | Allocation |
| 200 KB | 300 KB | 400 KB | 500 KB |
Now the memory is contiguous and no smaller fragmented blocks are left.
In systems that use paging (one of the memory management techniques), external fragmentation is virtually eliminated. In paging, memory is divided into fixed-size blocks (pages), and each process is divided into pages of the same size. These pages can be scattered throughout physical memory, but they don’t have to be contiguous. The operating system uses a page table to map the virtual address space of a process to physical memory addresses, preventing fragmentation issues that arise in contiguous allocation schemes.
Segmentation divides memory into variable-sized segments based on logical units of a program (e.g., code, data, stack). While segmentation can still suffer from fragmentation, it allows better management of different parts of a process. It can be combined with paging to reduce fragmentation further.
The buddy system is a memory allocation scheme that divides memory into blocks of sizes that are powers of two (e.g., 64 KB, 128 KB, 256 KB). When a memory request is made, the system tries to find the smallest block that can accommodate the request. If no block large enough is available, the system splits a larger block into two "buddies" (two smaller blocks of equal size), ensuring that blocks can be easily merged back when they are freed.
Advantage: This system reduces fragmentation by ensuring memory blocks are of a standard size, making it easier to find a suitable block for allocation.
Allocating large contiguous blocks for each program or process can reduce fragmentation. However, this method might lead to internal fragmentation (where a block is larger than the actual memory needed), so it is typically used in combination with other methods.
External fragmentation is a common problem in memory management, particularly in systems that use contiguous allocation or segmentation schemes. It results in inefficient use of memory, as free space is scattered into small chunks that cannot be used to fulfill memory requests.
To combat this, techniques like compaction, paging, and segmentation can be employed to reduce or eliminate fragmentation. In modern systems, paging is the most effective method for handling memory allocation, as it entirely eliminates external fragmentation. However, for systems that still rely on contiguous memory allocation, compaction and buddy systems can help reduce the impact of external fragmentation.
Open this section to load past papers