What Is Internal & External Memory Fragmentation?

by Erica Kasper

Memory fragmentation occurs when a system contains memory that is technically free but that the computer can’t utilize. The memory allocator, which assigns needed memory to various tasks, divides and allocates memory blocks as they are required by programs; when data is deleted, more memory blocks are freed up in the system and added back to the pool of available memory. When the allocator’s actions or the restoration of previously occupied memory segments leads to blocks or even bytes of memory that are too small or too isolated to be used by the memory pool, fragmentation has occurred. Fragmentation can take a significant bite out of a computer's free memory and it is often the cause of frustrating out-of-memory error messages.

Internal Fragmentation

Internal fragmentation can cause a slow but steady erosion of free memory.

Internal fragmentation occurs when the memory allocator leaves extra space empty inside of a block of memory that has been allocated for a client. This usually happens because the processor’s design stipulates that memory must be cut into blocks of certain sizes -- for example, blocks may be required to be evenly be divided by four, eight or 16 bytes. When this occurs, a client that needs 57 bytes of memory, for example, may be allocated a block that contains 60 bytes, or even 64. The extra bytes that the client doesn’t need go to waste, and over time these tiny chunks of unused memory can build up and create large quantities of memory that can’t be put to use by the allocator. Because all of these useless bytes are inside larger memory blocks, the fragmentation is considered internal.

External Fragmentation

External fragmentation can create out-of-memory errors despite the presence of free memory.

External fragmentation happens when the memory allocator leaves sections of unused memory blocks between portions of allocated memory. For example, if several memory blocks are allocated in a continuous line but one of the middle blocks in the line is freed (perhaps because the process that was using that block of memory stopped running), the free block is fragmented. The block is still available for use by the allocator later if there’s a need for memory that fits in that block, but the block is now unusable for larger memory needs. It cannot be lumped back in with the total free memory available to the system, as total memory must be contiguous for it to be useable for larger tasks. In this way, entire sections of free memory can end up isolated from the whole that are often too small for significant use, which creates an overall reduction of free memory that over time can lead to a lack of available memory for key tasks.

Fragmentation Can Mean Big Problems for Systems

Fragmentation can slow computer performance and even stop it completely if too little available memory is left.

Fragmentation can become an issue because it builds up over time, creating small and useless blocks of memory and limiting the amount of a computer’s available free memory. As it progresses, fragmentation can cause system performance to become slow and sluggish in the short term; in the long term, fragmentation can shorten the life of a computer or server by 30 percent on average. Of the two types of fragmentation, internal is more predictable than external because the amount of wasted space is determined by the memory allocator’s parameters (how big the allocated blocks must be), which is a constant. In addition, the amount of overall memory lost to internal fragmentation is usually less than what’s lost to external fragmentation, although it can gradually accumulate. External fragmentation, on the other hand, is harder to predict because in most cases several processes are regularly starting and stopping in the system and blocks of memory that are used for varying lengths of time are freed up in a different order than they were filled, leaving gaps in the available memory.

Fighting Fragmentation for Improved Performance

Scheduling routine maintenance to combat fragmentation can prevent bigger problems later.

When it comes to optimizing RAM, the only useful solution is to reboot the system, which clears much of the memory in use by long-running programs and gives the computer a fresh start for allocating memory. Tools that claim to defrag RAM are misleading, as the virtual memory manager in modern computers works to optimize RAM usage constantly. For your hard drive, however, some defragmenting may be required to maximize system performance. If you run Windows Vista or later versions, the system automatically defragments your hard drive space periodically for you. If you notice slower system performance and want to run the defragmenter yourself, you can manually start the process by clicking "Start," then "All Programs | Accessories | System Tools | Disk Defragmenter." Finally, click "Defragment Now." The process could take anywhere from minutes to hours depending on how fragmented your hard disk is, but the good news is that you can use your computer while Disk Defragmenter is running. The problem of fragmentation does not apply to all operating systems equally. For Mac computers, defragmenting is not necessary because Mac OS X automatically optimizes disk space when files are written. Linux machines also do not require regular defragmenting because they assign memory in a scattered format instead of a contiguous one, giving the files room to expand. Linux users who see a drop in system performance should consider increasing the size of their hard disk. Finally, you should never defragment a solid state storage drive (such as a USB drive), since defragmentation can actually shorten the usable life of solid state drives.

About the Author

Erica Kasper has been a professional writer and editor since 1999. Based in Jacksonville, Fla., she has written and edited educational, marketing and web copy for nonprofit organizations, technology companies and online marketing firms. She has a Bachelor's degree in journalism (honors) and psychology from Washington and Lee University.

More Articles

Photo Credits