Difference Between Internal and External Fragmentation

Difference Between Internal and External Fragmentation

4 mins readComment
Anshuman
Anshuman Singh
Senior Executive - Content
Updated on Mar 20, 2024 12:20 IST

One fundamental difference between internal and external fragmentation is that internal fragmentation occurs instantly during allocation when the allocated fixed-size block is larger than required, wasting space within the block. In contrast, external fragmentation occurs gradually over time due to dynamic allocations/deallocations, fragmenting free memory into small, non-contiguous holes and preventing future allocations despite sufficient total free memory.

Difference Between Internal and External Fragmentation

Another key difference is that internal fragmentation is unavoidable and happens due to the way memory is allocated in fixed-size blocks/chunks. Meanwhile, external fragmentation can be avoided using proper memory management techniques, such as defragmentation or compaction algorithms. These techniques fuse the free memory holes into larger contiguous blocks.

Table of Content (TOC)

Difference Between Internal and External Fragmentation

For better clarity and understandability, here's a tabular comparison between these two fragmentation types. 

Benchmark Internal Fragmentation External Fragmentation
Occurrence During memory allocation Over time due to repeated allocations/deallocations
Cause Fixed-size memory block allocation Dynamic allocation of varying-size memory blocks
Location Within an allocated memory block In the free memory space
Nature Unused memory within an allocated block Free memory fragmented into scattered holes
Avoidability Unavoidable in fixed-size allocations Can be mitigated by defragmentation/compaction algorithms
Impact Inefficient memory utilization within a block Potential allocation failures despite sufficient total memory
Visibility Visible to the memory manager/allocator Visible to the memory manager/allocator
Overhead Minimal overhead Additional overhead for defragmentation/compaction

Memory Management Techniques in Operating System

Segmentation Technique in Operating System

File System in Operating System
Recommended online courses

Best-suited Operating Systems courses for you

Learn Operating Systems with these high-rated online courses

– / –
3 months
– / –
2 months
7 K
3 months
– / –
2 months
12.5 K
75 days
– / –
12 months
– / –
1 year
– / –
5 days

What is Internal Fragmentation?

Internal fragmentation occurs when a memory block larger than the actual requirement is allocated to a process or data structure, resulting in unused memory space within the allocated block.

The memory block goes unutilized because memory is typically allocated in fixed-size chunks or partitions. And if the requested memory size is slightly smaller than the allocated block size, the remaining unused portion within that block becomes internal fragmentation. Internal fragmentation is unavoidable, as it's generally not possible to allocate memory blocks that perfectly match the requested size every time.

Internal Fragmentation Example

Suppose the operating system allocates memory in fixed-size blocks of 4 KB. If a process requests 3 KB of memory, the memory manager will allocate a 4 KB block (smallest available block size) to the process. But, as the process only needs 3 KB, the remaining 1 KB within the allocated 4 KB block will go unused.

This 1 KB of unused memory space within the allocated 4 KB block is internal fragmentation. This internal fragmentation cannot be used by any other process or data structure, as it is part of the block already allocated to the original process.

What is External Fragmentation?

External fragmentation refers to the situation where there is enough total free memory available to satisfy a memory allocation request, but the free memory is fragmented into small, scattered, non-contiguous blocks or holes. And none of them are large enough to accommodate the requested memory size.

External Fragmentation Example

Suppose a system has 16 MB of total memory, initially available as a single 16 MB free block. A process requests 4 MB of memory, which is allocated, leaving a 12 MB free block. Another process requests 2 MB, which is allocated from the 12 MB free block, leaving two free blocks: 10 MB and 2 MB.

The first process (which took 4 MB) terminates and frees its memory. Now, you have two free blocks: 4 MB and 2 MB (in total 6 MB). A new process requests 5 MB of contiguous memory.

Even though you have 6 MB of total free memory, you cannot satisfy this 5 MB request because the free memory is fragmented into two separate blocks of 4 MB and 2 MB. And neither of them is large enough for the 5 MB request.

Key Differences Between Internal and External Fragmentation

Here are the key differences:

  • Internal fragmentation occurs during memory allocation, whereas external fragmentation occurs over time due to repeated allocations and deallocations.
  • The dynamic allocation of varying-size memory blocks causes external fragmentation. Meanwhile, allocating fixed-size memory blocks causes internal fragmentation.
  • Internal fragmentation wastes space within an allocated memory block. In contrast, external fragmentation fragments the free memory space into scattered holes.
  • Internal fragmentation is unavoidable in systems with fixed-size allocations, whereas external fragmentation can be mitigated by defragmentation/compaction algorithms.
  • External fragmentation can lead to allocation failures despite sufficient total memory. On the other hand, internal fragmentation leads to inefficient memory utilization within a block.

Must Read Articles:

5 Important Functions of Operating System Explained

Process Scheduling: Operating System

FAQs

How does the choice of operating system influence fragmentation?

The operating system's memory management strategies significantly impact both types of fragmentation. Operating systems with more advanced memory management techniques, like dynamic partitioning and virtual memory, can mitigate the effects of external fragmentation more effectively than those with simpler strategies.

Can internal fragmentation have any benefits?

While generally seen as wasteful, internal fragmentation can sometimes benefit by preventing the overhead associated with exact-size memory allocations. It can simplify memory management and improve system stability by reducing the number of total allocations required.

About the Author
author-image
Anshuman Singh
Senior Executive - Content

Anshuman Singh is an accomplished content writer with over three years of experience specializing in cybersecurity, cloud computing, networking, and software testing. Known for his clear, concise, and informative wr... Read Full Bio