Exercises — Fragmentation — internal vs external, compaction
Before we start, here is the one-screen toolbox we will reuse. Every symbol is spelled out in words so line one is readable by anyone.
Level 1 — Recognition
Goal: just name the flavour of waste and read the formulas — no arithmetic tricks yet.
Exercise 1.1
A process is given one page but uses only of it. Name the fragmentation type and give the wasted amount.
Recall Solution 1.1
The waste sits inside a single block the process already owns → internal fragmentation. Wasted .
Exercise 1.2
Free memory is split as holes of , , . A process wants and is refused. Name the fragmentation type.
Recall Solution 1.2
Total free , yet no single hole is big enough. Waste lives between blocks → external fragmentation.
Exercise 1.3
Which of the two schemes, Paging or Segmentation, suffers from external fragmentation, and which from internal?
Recall Solution 1.3
Paging uses fixed-size frames → any free frame fits any request → no external, but a partly-used last page gives internal. Segmentation uses variable-size segments → awkward leftover holes → external.
Level 2 — Application
Goal: plug numbers into the two formulas correctly, especially the ceiling.
Exercise 2.1
A process needs bytes. Blocks are bytes. Compute the number of blocks and the internal fragmentation.
Recall Solution 2.1
Blocks: . Why 6? Five blocks give , so one more is forced. Given: bytes. Internal waste: bytes.
Exercise 2.2
Three processes of sizes , , bytes are each paged with . Find the total internal fragmentation across all three.
Recall Solution 2.2
- : , given , waste .
- : , given , waste . Why 2 blocks? One byte over a full block still forces a whole second block.
- : , given , waste . A perfect multiple wastes nothing. Total internal bytes.
Exercise 2.3
Free holes are , , . Compute the external fragmentation ratio.
Recall Solution 2.3
Total free . Largest hole . Over half the free memory is unusable for any request larger than .
Level 3 — Analysis
Goal: reason about averages, trade-offs, and sequences of allocations.
Exercise 3.1
A system runs processes, each paged with bytes, and process sizes are effectively random relative to . Estimate the total internal fragmentation, and explain the reasoning.
Recall Solution 3.1
For a random size, the last (partial) block is on average half full, so expected waste per process bytes. Why ? The leftover is uniform over , so the wasted tail averages . Total estimate bytes .
Exercise 3.2
Same processes. An engineer halves the block size to . What happens to expected internal fragmentation, and what is the hidden cost?
Recall Solution 3.2
New expected waste per process bytes; total bytes . Internal waste roughly halves. Hidden cost: smaller blocks mean more blocks per process, so the page table grows (more entries to store and walk). It is a trade-off, not a free win — see Memory Allocation Strategies.
Exercise 3.3
Memory of is allocated with variable partitions. Requests arrive: allocate (A), (B), (C); then free B; then request (D). Using first-fit (Dynamic Memory Allocation / Memory Allocation Strategies), does D fit? Compute the external fragmentation ratio at the moment D arrives.
Recall Solution 3.3
Layout after A, B, C (addresses low→high): , with a tail hole of . Free B: layout . Free holes now: and ; total free , largest . D needs : first-fit scans holes, finds and → D fails, even though . See the picture below.

Level 4 — Synthesis
Goal: combine tools — compaction, ratios, and before/after reasoning.
Exercise 4.1
Take the failing state from Exercise 3.3: inside . Apply compaction, then re-attempt request D (). Show the layout, the new ratio, and how many kilobytes were moved.
Recall Solution 4.1
Compact: slide C down against A so both holes pool at the top:
.
Now the single free block is → D fits. After placing D: .
New ratio (before placing D): one hole of → (perfectly consolidated).
Bytes moved: only had to slide (A already at the bottom). So were copied. Cost is proportional to bytes moved.

Exercise 4.2
A colleague proposes: "compact after every free to keep the ratio at ." Give two reasons this is a bad idea, and name the scheme that sidesteps the whole problem.
Recall Solution 4.2
- Compaction copies memory and pauses processes ("stop the world"); doing it after every free wastes huge CPU time relocating blocks that may be freed again seconds later.
- It requires processes to be relocatable at run time and re-updates base registers each time — overhead on every event. Sidestep: Paging uses fixed frames so external fragmentation cannot occur — any frame fits any request — at the price of small internal waste. See also Virtual Memory, which layers on top of paging.
Exercise 4.3
A region is fully carved into fixed partitions of each. Nine processes of sizes MB are placed one per partition. Compute total internal fragmentation and the number of empty partitions left.
Recall Solution 4.3
Partitions available . Processes placed , so empty partitions . Internal waste per placed process (each fills exactly one partition): Note: the empty partitions () are unallocated free space, not internal fragmentation — internal counts only waste inside allocated partitions.
Level 5 — Mastery
Goal: design, quantify a full trade-off, and defend the choice.
Exercise 5.1
You must serve processes averaging bytes each, on a machine with a page-table cost of bytes per page-table entry (one entry per frame a process uses). Compare block size vs on (a) total expected internal fragmentation and (b) total page-table bytes. Which do you pick, and why?
Recall Solution 5.1
(a) Internal fragmentation (expected per process):
- : bytes .
- : bytes .
(b) Page-table bytes (entries per process , ):
- : entries → bytes.
- : entries → bytes.
Combined overhead (waste + table):
- : bytes.
- : bytes.
Pick : its total overhead is far smaller here because the internal-fragmentation saving () dwarfs the extra page-table cost (). Caveat: if processes were tiny (near one page each), the table cost could dominate — always run the numbers.
Exercise 5.2
Design decision: a real-time system cannot tolerate long pauses but runs variable-size segments that fragment externally. It refuses to use compaction (too disruptive). Propose a scheme that removes external fragmentation without a stop-the-world pause, and state the fragmentation cost you accept in return.
Recall Solution 5.2
Switch from Segmentation (variable blocks) to Paging (fixed frames). Because every frame is identical and any frame satisfies any request, external fragmentation is eliminated with no relocation pass at all — no copying, no pause. Cost accepted: a small internal fragmentation on each process's last partial page (expected ). This is the classic trade: give up a little internal waste to buy freedom from external waste and from compaction pauses. Layering Virtual Memory on top then also frees you from needing all frames resident at once.
Recall One-line recap of every level
L1 name the flavour ::: inside a block = internal; between blocks = external. L2 plug the formulas ::: and ; always round up. L3 reason about averages ::: expected internal waste per process; smaller helps but bloats the page table. L4 apply compaction ::: it merges holes to ratio , cost bytes moved; empty partitions are not internal waste. L5 design & defend ::: minimise total overhead = internal waste + table cost; paging kills external without a pause.