---
title: "Compaction vs coalescing; paging mapping"
subject: "Operating System"
chapter: 4
key: "semester_6/operating_system:compaction-coalescing-paging"
source: https://www.bctengineer.com/q/semester_6/operating_system/compaction-coalescing-paging
site: BCT Engineering
---

# Compaction vs coalescing; paging mapping

Operating System · Chapter 4: Memory Management

- Asked in: 2073 Bhadra, 2+3 marks
- Video: [Compaction And Coalescing Example](https://www.youtube.com/watch?v=3A5W-0Bknv0) — TutorialsPoint
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/compaction-coalescing-paging
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-4

## Question

Differentiate compaction and Coalescing technique. How is logical address mapped to physical address by Paging Technique? Explain with suitable example.

## Short answer

Compaction moves processes together to combine all free space into one; coalescing merges adjacent free blocks without relocating processes. Paging maps logical address by splitting into page number and offset; page table translates page to frame, and physical address = frame×size + offset. Example: with 4KB pages, address 9000 (page 2, offset 808) maps to frame 1 giving physical 4904.

## Answer

#### Compaction vs coalescing
| Point | Coalescing | Compaction |
|---|---|---|
| Meaning | Joins **adjacent** free blocks into one larger block | Shifts all used blocks to one end so free space becomes one block |
| Trigger | When a block is released next to a free block | When free memory exists but is split into small holes |
| Process movement | None | Processes are relocated |
| Overhead | Very low | High (copying, changing base addresses) |
| Requirement | None | Dynamic (run-time) relocation |
| Removes external fragmentation | Only partly | Completely |

Example: free blocks 100 K and 50 K next to each other form a 150 K block after coalescing. Memory with P1 (40 K), hole 20 K, P2 (30 K), hole 25 K: compaction moves P2 down next to P1, giving one 45 K hole.

#### Mapping logical to physical address in paging
Logical memory is split into **pages** and physical memory into **frames** of equal size (power of 2). The CPU generates a logical address = (page number p, offset d). The **page table** (one per process) gives the frame number f for page p. Physical address = (f × page size) + d. The offset is unchanged.

```text
 logical addr           page table           physical memory
 +----+----+          +---+-----+            frame f
 | p  | d  |-- p --> | p |  f  |-- f -->  +---------+
 +----+----+          +---+-----+          |  ...d.. |
```
Example: page size = 4 KB (4096), logical address = 9000. Page table: page 0 → frame 3, page 1 → frame 6, page 2 → frame 1.
- p = 9000 div 4096 = 2; d = 9000 mod 4096 = 808.
- Page 2 is in frame 1.
- Physical address = 1 × 4096 + 808 = **4904**.

Paging avoids external fragmentation but may have internal fragmentation in the last page of a process.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which describes coalescing?
   A. Swapping out a process
   B. Moving processes to one end
   C. Allocating pages
   D. Joining adjacent free blocks into one
   Answer: D. Occurs when a block is freed next to a free block. (Key point: Coalescing)

2. What does compaction achieve?
   A. Nothing, only partly
   B. Completely removes external fragmentation
   C. Speeds up the CPU
   D. Removes internal fragmentation
   Answer: B. All free space becomes one block. (Key point: Compaction effect)

3. Page size 4096, logical 9000, page 2 in frame 1. Physical address?
   A. 4904
   B. 8296
   C. 9000
   D. 808
   Answer: A. p = 2, d = 808; 1*4096 + 808 = 4904. (Key point: Paging mapping)

4. What happens to the offset?
   A. It is unchanged in translation
   B. It is divided by page size
   C. It is replaced by the frame number
   D. It is doubled
   Answer: A. Only page number maps to frame number. (Key point: Offset)

## Related in Operating System

- [Compaction vs coalescing; paging; TLB](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Acompaction-coalescing-paging-tlb) — Operating System, chapter 4
- [Logical and physical address bits](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aresidence-monitor-address-bits) — Operating System, chapter 4
- [TLB, thrashing; coalescing vs compaction](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Atlb-thrashing-coalescing-compaction) — Operating System, chapter 4
- [Page fault, demand paging, address translation](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Apage-fault-demand-paging-address) — Operating System, chapter 4
- [Page fault; virtual to physical address](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Apage-fault-64k-virtual-32k-physical) — Operating System, chapter 4

## Related in other subjects

- [Physical vs logical clock; sync method](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aphysical-clock-sync-difficulty) — Distributed System, chapter 5, asked 2×
- [Physical vs logical clocks; Lamport](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alamport-physical-compare) — Distributed System, chapter 5
