Fragmentation (computing)
In computer storage, fragmentation is a phenomenon in the computer system which involves the distribution of data into smaller pieces so that storage space, such as computer memory or a hard drive, is used inefficiently, reducing capacity or performance and often both. The exact consequences of fragmentation depend on the specific system of storage allocation in use and the particular form of fragmentation. In many cases, fragmentation leads to storage space being "wasted", and programs will tend to run inefficiently due to the shortage of memory.
In computer storage, fragmentation is a phenomenon in the computer system which involves the distribution of data into smaller pieces so that storage space, such as computer memory or a hard drive, is used inefficiently, reducing capacity or performance and often both. The exact consequences of fragmentation depend on the specific system of storage allocation in use and the particular form of fragmentation. In many cases, fragmentation leads to storage space being "wasted", and programs will tend to run inefficiently due to the shortage of memory. ==Basic principle== In main memory fragmentation, when a computer program requests blocks of memory from the computer system, the blocks are allocated in chunks. When the computer program is finished with a chunk, it can free it back to the system, making it available to later be allocated again to another or the same program. The size and the amount of time a chunk is held by a program vary. During its lifespan, a computer program can request and free many chunks of memory. Fragmentation can occur when a block of memory is requested by a program and is allocated to that program, but the program has not freed (uncommitted) it. This leads to theoretically "available", unused memory being marked as allocated - which reduces the amount of globally available memory, making it harder for programs to request and access memory. When a program is started, the free memory areas are long and contiguous. Over time and with use, the long contiguous regions become fragmented into smaller and smaller contiguous areas. Eventually, it may become impossible for the program to obtain large contiguous chunks of memory. ==Types== Fragmentation occurs whenever a piece of data or free space is broken into several pieces. Fragmentation is often accepted in return for improvements in speed or simplicity. Analogous phenomena occur for other resources such as processors; see below. ====Internal fragmentation==== greatly reduces slack space.]] Due to the rules governing memory allocation, more computer memory is sometimes allocated than is needed. When this happens, the excess memory goes to waste. In this scenario, the unusable memory, known as slack space, is contained within an allocated region. This arrangement, termed fixed partitions, suffers from inefficient memory use - any process, no matter how small, occupies an entire partition. This waste is called internal fragmentation. Memory paging creates internal fragmentation because an entire page frame (typically 4–64 KiB) will be allocated whether or not that much storage is needed. malloc and similar allocators tend to provide a degree of alignment, so that memory can only be provided to programs in chunks (usually a multiple of 4 bytes). As a result if a program requests perhaps 29 bytes, it will actually get a chunk of 32 bytes. Internal fragmentation on the allocator level is very difficult to reclaim after it has occurred; usually the best way to remove it is with a design change. For example, in dynamic memory allocation, memory pools drastically cut internal fragmentation by spreading the space overhead over a larger number of objects. Internal fragmentation on the page level (which is external fragmentation on the allocator level) can be reclaimed by moving allocated blocks. This requires editing pointers to reflect the moving of allocated blocks, which is difficult for non-garbage-collected languages. Compacting garbage collectors perform pointer fixups as it compacts the virtual address space. ====External fragmentation==== External fragmentation arises when free memory is separated into small blocks and is interspersed by allocated memory. It is a weakness of certain storage allocation algorithms when they fail to order memory used by programs efficiently. The result is that, although free storage is available, it is effectively unusable because it is divided into pieces that are too small individually to satisfy the demands of the application. The term "external" refers to the fact that the unusable storage is outside the allocated regions. For example, consider a situation wherein a program allocates three continuous blocks of memory and then frees the middle block. The memory allocator can use this free block of memory for future allocations. However, it cannot use this block if the memory to be allocated is larger in size than this free block. External fragmentation on the page level can be reclaimed by an application's own allocator or garbage collector as it frees up and hands back (uncommits) pages to the OS. External fragmentation on the page level can also be reclaimed by the operating system by moving pages in the physical address space and editing the page table to match. This is called page migration. The application is oblivious to the process because the virtual memory addresses remain unchanged. ===Comparison=== Compared to external fragmentation, overhead and internal fragmentation account for little loss in terms of wasted memory and reduced performance. It is defined as: Fragmentation of 0% means that all the free memory is in a single large block; fragmentation is 90% (for example) when 100 MB of free memory is present but the largest free block of memory for storage is just 10 MB. External fragmentation tends to be less of a problem in file systems than in primary memory (RAM) storage systems, because programs usually require their RAM storage requests to be fulfilled with contiguous blocks, but file systems typically are designed to be able to use any collection of available blocks (fragments) to assemble a file which logically appears contiguous. Therefore, if a highly fragmented file or many small files are deleted from a full volume and then a new file with size equal to the newly freed space is created, the new file will simply reuse the same fragments that were freed by the deletion. If what was deleted was one file, the new file will be just as fragmented as that old file was, but in any case there will be no barrier to using all the (highly fragmented) free space to create the new file. In RAM, on the other hand, the storage systems used often cannot assemble a large block to meet a request from small noncontiguous free blocks, and so the request cannot be fulfilled and the program cannot proceed to do whatever it needed that memory for (unless it can reissue the request as a number of smaller separate requests). ==Problems== ===Storage failure=== The most severe problem caused by fragmentation is causing a process or system to fail due to premature resource exhaustion: if a contiguous block must be stored and cannot be stored, failure occurs. Fragmentation causes this to occur even if there is enough of the resource, but not a contiguous amount. For example, if a computer has 4 GiB of memory and 2 GiB are free, but the memory is fragmented in an alternating sequence of 1 MiB used, 1 MiB free, then a request for 1 contiguous GiB of memory cannot be satisfied even though 2 GiB total are free. In order to avoid this, the allocator may, instead of failing, trigger a defragmentation (or memory compaction cycle) or other resource reclamation, such as a major garbage collection cycle, in the hope that it will then be able to satisfy the request. This allows the process to proceed, but can severely impact performance. ===Performance degradation=== Fragmentation causes performance degradation for a number of reasons. Most basically, fragmentation increases the work required to allocate and access a resource. For example, on a hard drive or tape drive, sequential data reads are very fast, but seeking to a different address is slow, so reading or writing a fragmented file requires numerous seeks and is thus much slower, in addition to causing greater wear on the device. Further, if a resource is not fragmented, allocation requests can simply be satisfied by returning a single block from the start of the free area. However, if it is fragmented, the request requires either searching for a large enough free block, which may take a long time, or fulfilling the request by several smaller blocks (if this is possible), which results in this allocation being fragmented, and requiring additional overhead to manage the several pieces. A subtler problem is that fragmentation may prematurely exhaust a cache, causing thrashing, due to caches holding blocks, not individual data. For example, suppose a program has a working set of 256 KiB, and is running on a computer with a 256 KiB cache (say L2 instruction+data cache), so the entire working set fits in cache and thus executes quickly, at least in terms of cache hits. Suppose further that it has 64 translation lookaside buffer (TLB) entries, each for a 4 KiB page: each memory access requires a virtual-to-physical translation, which is fast if the page is in cache (here TLB). If the working set is unfragmented, then it will fit onto exactly 64 pages (the page working set will be 64 pages), and all memory lookups can be served from cache. However, if the working set is fragmented, then it will not fit into 64 pages, and execution will slow due to thrashing: pages will be repeatedly added and removed from the TLB during operation. Thus cache sizing in system design must include a margin to account for fragmentation. Memory fragmentation is one of the most severe problems faced by system managers. Over time, it leads to degradation of system performance. Eventually, memory fragmentation may lead to complete loss of (application-usable) free memory. Memory fragmentation is a kernel programming level problem. During real-time computing of applications, fragmentation levels can reach as high as 99%, and may lead to system crashes or other instabilities. This type of system crash can be difficult to avoid, as it is impossible to anticipate the critical rise in levels of memory fragmentation. However, while it may not be possible for a system to continue running all programs in the case of excessive memory fragmentation, a well-designed system should be able to recover from the critical fragmentation condition by moving in some memory blocks used by the system itself to enable consolidation of free memory into fewer, larger blocks, or, in the worst case, by terminating some programs to free their memory and then defragmenting the resulting sum total of free memory. This will at least avoid a true crash in the sense of system failure and allow the system to continue running some programs, save program data, etc. Fragmentation is a phenomenon of system software design; different software will be susceptible to fragmentation to different degrees, and it is possible to design a system that will never be forced to shut down or kill processes as a result of memory fragmentation. ==Analogous phenomena== While fragmentation is best known as a problem in memory allocation, analogous phenomena occur for other resources, notably processors. For example, in a system that uses time-sharing for preemptive multitasking, but that does not check if a process is blocked, a process that executes for part of its time slice but then blocks and cannot proceed for the remainder of its time slice wastes time because of the resulting internal fragmentation of time slices. More fundamentally, time-sharing itself causes external fragmentation of processes due to running them in fragmented time slices, rather than in a single unbroken run. The resulting cost of process switching and increased cache pressure from multiple processes using the same caches can result in degraded performance. In concurrent systems, particularly distributed systems, when a group of processes must interact to progress, if the processes are scheduled at separate times or on separate machines (fragmented across time or machines), the time spent waiting for each other or in communicating with each other can severely degrade performance. Instead, performant systems require coscheduling of the group. Some flash file systems have several different kinds of internal fragmentation involving "dead space" and "dark space". ==See also== Defragmentation File system fragmentation Memory management Memory management (operating systems) Block (data storage) Data cluster ==References== ==Sources== http://www.edn.com/design/systems-design/4333346/Handling-memory-fragmentation http://www.sqlservercentral.com/articles/performance+tuning/performancemonitoringbyinternalfragmentationmeasur/2014/ C++ Footprint and Performance Optimization, R. Alexander; G. Bensley, Sams Publisher, First edition, Page no:128, ISBN no:9780672319044 Ibid, Page no:129
References
No reference rows published for this article.
Cite this article
MLA
"Fragmentation (computing)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/fragmentation-computing. Accessed 24 November 2026.
Chicago
"Fragmentation (computing)." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/fragmentation-computing.
APA
encyclopegia.org. (2026). Fragmentation (computing). Retrieved November 24, 2026, from https://encyclopegia.org/wiki/fragmentation-computing
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON