Difference Between Paging and Segmentation
Paging vs segmentation compared — fixed vs variable blocks, fragmentation, and address translation — with examples and OS interview questions answered.
Expected Interview Answer
Paging divides memory into fixed-size blocks called pages (mapped to equal-size frames in physical memory), while segmentation divides memory into variable-size, logically meaningful segments such as code, stack, and heap.
In paging, a logical address is split into a page number and an offset; the page table maps the page number to a physical frame, giving a simple mechanism with no external fragmentation but some internal fragmentation and no logical structure. In segmentation, an address is a segment number plus an offset, and a segment table stores each segment’s base and limit; this preserves the program’s logical view and eases protection and sharing but suffers external fragmentation. Many real systems combine both (segmented paging) to gain the logical grouping of segments with the tidy allocation of pages.
- Paging: no external fragmentation, simple allocation
- Paging: fixed frames simplify the hardware mapping
- Segmentation: matches the program’s logical structure
- Segmentation: natural protection and sharing per segment
AI Mentor Explanation
Paging is like dividing a match into fixed six-ball overs — every unit is the same size, easy to schedule and track, even if the last over is not fully bowled (internal waste). Segmentation is like dividing the game into meaningful phases — powerplay, middle overs, death overs — each a different length reflecting its role. Paging is uniform and simple; segmentation mirrors the logical structure of the innings, which is the essence of the difference.
Step-by-Step Explanation
Step 1
Unit size
Paging: fixed-size pages/frames. Segmentation: variable-size logical segments.
Step 2
Address form
Paging: page number + offset. Segmentation: segment number + offset.
Step 3
Fragmentation
Paging: internal fragmentation only. Segmentation: external fragmentation.
Step 4
Logical view
Paging ignores program structure; segmentation reflects code/stack/heap for protection and sharing.
What Interviewer Expects
- Fixed-size pages vs variable-size logical segments
- The two address formats and their lookup tables
- Internal vs external fragmentation for each
- Awareness that real systems combine both (segmented paging)
Common Mistakes
- Swapping which scheme causes internal vs external fragmentation
- Saying pages are variable-sized or segments are fixed-sized
- Ignoring that segmentation maps to logical program structure
- Not knowing paging and segmentation can be combined
Best Answer (HR Friendly)
“Paging chops memory into equal-size blocks, which keeps allocation simple and avoids leftover gaps between blocks. Segmentation splits memory by meaningful parts of a program, like code and stack, which is more natural for protection but can leave awkward gaps. Many systems blend both to get the best of each.”
Code Example
/* Paging: fixed page size, address = page_number : offset */
unsigned page_number = logical_addr / PAGE_SIZE; /* which page */
unsigned offset = logical_addr % PAGE_SIZE; /* within page */
unsigned phys_addr = page_table[page_number] * PAGE_SIZE + offset;
/* Segmentation: address = segment_number : offset, checked vs a limit */
if (offset >= seg_table[segment_number].limit)
raise_segmentation_fault();
else
phys_addr = seg_table[segment_number].base + offset;Follow-up Questions
- What is the difference between internal and external fragmentation?
- What is a translation lookaside buffer (TLB) and why is it used?
- How does segmented paging combine both schemes?
- What is a page fault and how is it handled?
MCQ Practice
1. Which memory scheme uses fixed-size blocks?
Paging divides memory into equal fixed-size pages and frames; segmentation uses variable-size segments.
2. External fragmentation is primarily associated with?
Variable-size segments leave gaps too small to reuse, causing external fragmentation; paging causes only internal fragmentation.
3. A logical address in a paging system is split into?
The page number indexes the page table; the offset locates the byte within the frame.
Flash Cards
Paging vs segmentation size? — Paging: fixed-size pages/frames. Segmentation: variable-size logical segments.
Fragmentation type of each? — Paging → internal fragmentation. Segmentation → external fragmentation.
Address format in paging? — Page number + offset; the page table maps the page number to a physical frame.
Why segmentation? — It matches logical program structure (code, stack, heap), easing protection and sharing.