Fragmentation is a memory-management problem in which some portion of available memory becomes difficult to use efficiently because of the way memory has been allocated to processes. The important point is that fragmentation does not simply mean that memory has become "empty." It describes a mismatch between the way free space is arranged and the way memory requests need to be satisfied.
During the lifetime of a system, processes are created, loaded into memory, suspended, terminated, and replaced by other processes. When these operations occur repeatedly, the arrangement of allocated and free memory can become less convenient for future allocations. Depending on the allocation technique, the unused space may occur inside an allocated block or may appear as separate gaps between allocated blocks.
Fragmentation is the condition in which memory space is not utilized efficiently because some available space is either trapped inside allocated blocks or scattered into separate free regions.
Fragmentation is closely related to the memory allocation strategy used by an operating system. Consider a system that initially has a large free memory area. Several processes may be loaded into that area. Later, some of those processes finish and release their memory. The newly released areas may not be adjacent to one another.
A future process may require a particular amount of memory. Even if the total amount of free memory is greater than the requested amount, the request may still be difficult to satisfy when the allocation method requires one sufficiently large contiguous region.
Fragmentation is generally discussed in two forms:
Internal fragmentation occurs when the allocation unit supplied to a process is larger than the amount of memory that the process actually needs. The unused portion remains inside the allocated unit. Since that block has already been assigned, the operating system cannot normally give the unused portion to another process as an independent allocation.
The key characteristic is therefore the location of the wasted space. The unused memory is located within the boundary of an allocated block.
Suppose memory is allocated in blocks of 8 KB. A process requires only 6 KB. The operating system still allocates one complete 8 KB block.
The 2 KB is inside the allocated block and is therefore an example of internal fragmentation.
Figure 1: Internal fragmentation occurs when unused space remains inside an allocated memory block.
Paging is based on fixed-size pages and frames. A process is divided into pages, and each page occupies a complete frame. If the last page of a process does not completely fill its frame, the remaining portion of that frame is unused by that process.
For example, if the page size is 4 KB and a process requires 10 KB, the process needs three pages:
The third page occupies a complete 4 KB frame, leaving 2 KB unused in that frame. This unused portion represents internal fragmentation.
External fragmentation has a different structure. Here, memory that is currently free exists outside allocated blocks, but the free space is divided into multiple separated regions.
This becomes important when an allocation request needs one contiguous memory region. The operating system may have enough total free memory, but no individual free region may be large enough for the request.
Assume that free memory exists in three separate holes:
Total free memory is:
Now suppose a process requires 30 KB of contiguous memory. None of the individual holes is 30 KB, so the request cannot be satisfied by simply selecting one of these holes.
The problem is not the total amount of free memory. The problem is its distribution.
Figure 2: External fragmentation occurs when free memory is distributed across separate holes.
External fragmentation is commonly associated with variable-size contiguous allocation. When processes of different sizes are allocated and later released, holes of different sizes can appear between active processes.
Segmentation is another technique in which variable-sized segments can contribute to external fragmentation when segments need contiguous physical regions.
| Point | Internal Fragmentation | External Fragmentation |
|---|---|---|
| Where is space wasted? | Inside an allocated block. | Between allocated blocks as separate free holes. |
| Main reason | Allocation unit is larger than the actual request. | Free memory becomes divided into separate regions. |
| Nature of allocation | Usually associated with fixed-size allocation. | Usually associated with variable-size contiguous allocation. |
| Typical example | Unused portion of the last page. | Several small holes between processes. |
| Can total free space be misleading? | Yes, because some allocated space may not be useful. | Yes, because free space may be scattered. |
| Common approach | Choose an appropriate allocation unit size. | Use compaction or an allocation technique that reduces unusable holes. |
The entire 8 KB block has been allocated to the process. The 2 KB unused portion is located inside the allocated block, so it is internal fragmentation.
The free regions are separated by allocated processes. Their total size may be large, but a process requiring one contiguous block may not fit into any individual hole.
Variable-size memory allocation strategies can influence how free holes are created and reused. Three commonly discussed strategies are First Fit, Best Fit, and Worst Fit. These algorithms do not completely eliminate fragmentation; instead, they determine how a requested block is selected from available free holes.
First Fit searches the free list from the beginning and selects the first hole that is large enough for the requested process.
Best Fit searches for the smallest available hole that can satisfy the request. The intention is to avoid wasting a large hole for a relatively small process.
Worst Fit chooses the largest available hole for the request. The idea is to leave a reasonably large remainder after allocation.
First Fit, Best Fit and Worst Fit are allocation strategies. They should not be described as complete solutions that eliminate fragmentation. Their effect depends on the sequence and sizes of memory requests.
A system uses fixed-size memory blocks of 4 KB. A process requires 13 KB. Determine the number of blocks required and the internal fragmentation.
A paging system uses a page size of 1 KB. A process occupies 7.5 KB. Find the number of pages required and the unused memory in the final page.
A memory contains free holes of 12 KB, 7 KB, 18 KB and 9 KB. A new process requires 20 KB of contiguous memory. Determine whether the request can be satisfied without compaction.
The largest individual free hole is only 18 KB. The process requires 20 KB of contiguous memory.
Suppose free holes of 6 KB, 11 KB, 9 KB and 14 KB are separated by allocated processes. A process requires 30 KB of contiguous memory. Can compaction make the allocation possible?
However, the largest individual hole is only 14 KB. Therefore, a 30 KB contiguous request cannot currently be placed.
If the operating system can move allocated processes and combine the separated free regions, the free space can be consolidated.
Since 40 KB is larger than the requested 30 KB, the process can now be placed in the consolidated free region.
Compaction is a technique used to reduce external fragmentation by moving allocated memory blocks so that separate free holes are brought together into one larger free region.
Imagine that memory contains several active processes with small gaps between them. If those processes can be relocated safely, the operating system can move them toward one side of memory. The gaps then merge into a larger continuous free area.
Compaction is not a solution to internal fragmentation. It is primarily useful for external fragmentation where free space is scattered across memory.
There is no single memory-management technique that removes every form of memory wastage in every situation. The choice of allocation method determines which type of fragmentation is more likely and how it can be controlled.
Fixed-size allocation can make free-space management simpler, but it may introduce unused space inside allocated units. Variable-size allocation can use requested sizes more directly, but repeated allocation and release can create separated free holes.
Paging is particularly useful for avoiding the need for a process to occupy one contiguous physical memory region. However, paging can still have internal fragmentation, especially in the final page of a process.
Compaction can address scattered free space in systems where relocation is practical, but it introduces its own overhead.
| Technique | Fragmentation Concern | Reason |
|---|---|---|
| Paging | Internal Fragmentation | The final page of a process may not completely fill its allocated frame. |
| Segmentation | External Fragmentation | Segments are variable in size and may require contiguous physical space. |
| Fixed Partitioning | Internal Fragmentation | A partition can be larger than the process assigned to it. |
| Variable Partitioning | External Fragmentation | Repeated allocation and release can create separated free holes. |
In numerical questions, fragmentation may also be expressed as a percentage of the allocated memory.
Suppose 20 KB is allocated to a process, but the process uses only 18 KB.
External fragmentation does not have one universally useful percentage formula comparable to internal fragmentation because the practical issue is often whether a particular contiguous request can fit into an individual hole.
Therefore, numerical questions involving external fragmentation usually provide a list of free holes and ask whether a requested process can be allocated using a particular strategy.
Fragmentation is a condition in which memory is not utilized efficiently because unused space is either present inside allocated blocks or distributed across separate free regions.
Internal fragmentation is unused memory inside a block that has already been allocated to a process.
External fragmentation occurs when free memory is divided into separate holes between allocated regions.
Paging can produce internal fragmentation because the final page of a process may not completely fill its allocated frame.
Segmentation can suffer from external fragmentation because segments are variable in size and may require contiguous physical memory.
No. External fragmentation means that free memory exists but is scattered into separate regions. The system may still be unable to satisfy a large contiguous allocation request.
Compaction rearranges allocated memory regions so that separated free holes are combined into a larger contiguous free area.
No. Compaction primarily addresses external fragmentation. Internal fragmentation exists inside allocated blocks and therefore cannot normally be removed by simply moving those blocks together.
Paging allows pages of a process to occupy different physical frames, so the process does not need one large contiguous physical memory region.
No. Best Fit is a placement strategy. Its actual effect on fragmentation depends on the workload and sequence of memory allocations and releases.
Try the following questions without opening the solutions first. These problems cover both conceptual and numerical aspects of fragmentation.
A system uses blocks of 8 KB. A process requires 19 KB. Find the number of blocks required and the internal fragmentation.
Free holes are 14 KB, 9 KB, 22 KB and 7 KB. A process requires 25 KB of contiguous memory. Can it be allocated without compaction?
A process requires 15 KB of memory and the page size is 4 KB. Calculate the number of pages and unused space in the final page.
A system has 60 KB total free memory divided into several holes. A process requires 35 KB contiguous memory. Is total free memory alone enough to conclude that the process can be loaded?
Internal Fragmentation: Internal fragmentation occurs when a fixed-size allocated memory unit contains unused space. Paging is a common example where the final page may not be completely filled.
External Fragmentation: External fragmentation occurs when free memory is available but divided into separate holes. A large contiguous allocation may fail even though the total free memory is sufficient.
Compaction: Compaction reduces external fragmentation by moving allocated regions so that separated free holes are combined.
Fragmentation is an important concept in operating-system memory management because the usefulness of memory depends not only on how much memory is available but also on how that memory is organized. Internal fragmentation represents unused space within allocated units, while external fragmentation represents separated free regions that may be difficult to use for contiguous allocation.
Understanding this distinction makes several other operating-system topics easier to study. Paging explains how fixed-size pages and frames can avoid the need for contiguous physical allocation, while segmentation demonstrates the advantages and challenges of variable-size logical memory regions. Memory-allocation algorithms such as First Fit, Best Fit and Worst Fit provide different ways of selecting free regions, while compaction can consolidate scattered free space when relocation is possible.
For examinations and interviews, the most important points to remember are the location of wasted space, the reason fragmentation occurs, the type of fragmentation associated with common allocation techniques, and the numerical method used to calculate unused space or determine whether a contiguous request can be satisfied.