Introduction
Memory fragmentation appears when available memory is not used efficiently. In contiguous memory allocation, the way RAM is divided for processes decides where unused memory can appear.
Internal fragmentation and external fragmentation both represent memory waste, but the key difference is location. Internal waste is inside an allocated block, while external waste is scattered outside allocated blocks.
Why Fragmentation Occurs
Fragmentation is closely connected to how memory is partitioned.
Fixed partitioning: Memory is divided into partitions in advance. A process may receive a partition larger than it needs.
Variable partitioning: Memory is divided dynamically based on process requirements. As processes finish, free holes can appear between allocated regions.
So, fixed partitioning commonly leads to internal fragmentation, while variable partitioning commonly leads to external fragmentation.
Internal Fragmentation
Internal fragmentation occurs when a process is allocated more memory than it actually uses. The unused space remains inside the allocated block.
This usually happens when memory is allocated in fixed-size blocks or fixed partitions. Since the block cannot always match the exact process size, some memory inside the block may remain unused.
For example, suppose a process needs 700 KB, but it receives a block of 1024 KB.
Therefore, Internal fragmentation = Allocated size - Used size = 1024 KB - 700 KB = 324 KB
The 324 KB is not a separate free hole. It is part of the allocated block, but the process is not using it.
Internal and External Fragmentation
External Fragmentation
External fragmentation occurs when free memory exists, but it is split into multiple separate holes.
The total free memory may be enough for a process, but allocation can still fail because contiguous allocation requires one large continuous block.
For example, suppose free memory is available like this:
Hole 1 | Hole 2 | Hole 3 |
|---|---|---|
100 KB | 150 KB | 200 KB |
Total free memory is 100 KB + 150 KB + 200 KB = 450 KB.
If a process requests 300 KB, the request fails because the largest single hole is only 200 KB. The memory exists in total, but it is scattered.
Internal vs External Fragmentation
Aspect | Internal Fragmentation | External Fragmentation |
|---|---|---|
Location of waste | Inside an allocated block | Between allocated blocks |
Nature of waste | Allocated but unused memory | Free memory split into holes |
Common cause | Fixed-size allocation or fixed partitioning | Variable partitioning with process exits |
Typical result | Some assigned memory remains unused | A new process may fail to get memory |
The easiest rule is: internal means the waste is inside the assigned memory, and external means the free space is outside allocated blocks but scattered.
How to Recognize Each Type
Use the location of memory waste as the deciding point.
Internal Fragmentation: Allocated block or fixed partition is larger than the process needs, leaving unused space inside the allocated block.
External Fragmentation: Enough total free memory exists, but it is divided into separate holes, so a large contiguous allocation may fail.
This avoids confusion because both cases involve memory waste, but the position of that waste is different.
Paging and Compaction
Paging helps reduce external fragmentation because a process does not need one continuous physical memory block. The process can be divided into pages and placed in different frames.
However, paging can still have internal fragmentation. If the last page of a process is not fully filled, the unused part of that page becomes internal waste.
Compaction handles external fragmentation differently. It moves allocated processes closer together so scattered free holes combine into one larger free block.
The basic compaction idea is: Process 1 => Hole => Process 2 => Hole => Process 3 => Hole
After compaction: Process 1 => Process 2 => Process 3 => Large Free Block
Compaction can make free memory usable again, but it requires moving memory and consumes system time.
Paging and Compaction
Summary
Internal fragmentation means unused memory exists inside an allocated block. It commonly appears when fixed-size allocation gives a process more memory than it actually needs.
External fragmentation means free memory is available but scattered into separate holes. Paging reduces the need for one continuous physical block, while compaction tries to merge scattered holes into a larger continuous free region.
Be the first to add a comment.