Topic 8.2 · Paging, Segmentation & Virtual Memory

Segmentation & Hybrid Paged-Segmentation

3 min read1 question to test yourself

1Definition

Segmentation is a memory management scheme that views memory from the user's perspective, partitioning a process into variable-sized logical modules called Segments (such as Main Function, Symbol Table, Stack, Library Functions). A Segment Table maps logical segment addresses ⟨s,d⟩\langle s, d\rangle to physical memory.

2Simple Explanation

Paging is designed for the computer hardware's convenience—it blindly chops a program into fixed 4KB blocks regardless of whether a block splits a function down the middle. Segmentation is designed for the user's and compiler's convenience. It divides the program into logical sections based on user view: Segment 0 is the main() function, Segment 1 is the math library, Segment 2 is the stack.

Each segment gets a variable size matching its content. Because segments vary in size, pure segmentation suffers from External Fragmentation. Modern systems combine both techniques into Hybrid Paged-Segmentation: memory is segmented logically for the user, and each segment is then paged physically for the hardware!

3Real-Life Example / Analogy

A Multi-Chapter Course Textbook: Segmentation is organizing a textbook by logical chapters (Chapter 1: Intro, Chapter 2: Math, Chapter 3: Appendices). Each chapter has a variable number of pages based on topic depth.

4Diagram / Visual Representation

No

Yes

Logical address
Segment number (s) + Offset (d)

Read segment table
Base and Limit

Is offset < segment limit?

Trap · Addressing error

Physical address = Base + Offset

Access RAM

5Working / How It Works

  • Logical Address Structure: ⟨Segment Number s,Offset d⟩\langle \text{Segment Number } s, \text{Offset } d\rangle.
  • Address Translation Sequence:
    1. CPU generates logical address ⟨s,d⟩\langle s, d\rangle.
    2. MMU looks up index ss in the Segment Table to retrieve Limit and Base.
    3. Check Bounds: MMU checks if Offset d<Limitd < \text{Limit}.
      • If d≥Limitd \ge \text{Limit}, MMU triggers a Trap: Addressing Error (Segmentation Fault).
    4. Compute Physical Address: Physical Address P=Base+dP = \text{Base} + d.

6Types / Components / Characteristics

  • Paging vs. Segmentation Comparison:
Feature / Metric Paging Architecture Segmentation Architecture
Design Viewpoint Hardware / OS View User / Programmer View
Block Size Fixed Size (Frames/Pages e.g., 4KB) Variable Size based on logical functions
Address StructureSingle Linear Address split into (p,d)(p, d)2D Logical Address ⟨s,d⟩\langle s, d\rangle
Internal FragmentationMinor (Last page)Zero
External FragmentationZeroPresent (Variable segment swapping)

7Solved Examples / Problems

Problem: Given the following Segment Table:

Segment (ss) Base Limit
0 219 600
1 2300 140
2 90 100

Evaluate physical addresses for:

  1. ⟨s=1,d=100⟩\langle s=1, d=100\rangle
  2. ⟨s=2,d=120⟩\langle s=2, d=120\rangle

Solution:

  1. For ⟨s=1,d=100⟩\langle s=1, d=100\rangle:
    • Check Limit: Is d(100)<Limit (140)d (100) < \text{Limit } (140)? Yes (Valid).
    • Physical Address = Base+d=2300+100=2400\text{Base} + d = 2300 + 100 = \mathbf{2400}.
  2. For ⟨s=2,d=120⟩\langle s=2, d=120\rangle:
    • Check Limit: Is d(120)<Limit (100)d (120) < \text{Limit } (100)? No (Out of Bounds!).
    • Result: Traps to OS with a Segmentation Fault.

8Advantages, Disadvantages & Applications

  • Segmentation Advantages: Matches user program structures cleanly, zero internal fragmentation, simplified shared module protection.
  • Disadvantages: Variable segment sizes cause severe external fragmentation.
  • Hybrid Paged-Segmentation: Used in modern architectures (x86-64) to get the logical benefits of segmentation with the external-fragmentation-free benefits of paging.

9Important Points to Remember

  • Paging represents the OS view of memory; Segmentation represents the User view.
  • Segmentation suffers from External Fragmentation; Paging suffers from minor Internal Fragmentation.

10Test Your Understanding

  1. MCQ: What happens when a process attempts to access a segment offset dd that is greater than the Segment Limit register value?
    • A) Page Fault
    • B) Segmentation Fault (Addressing Error Trap)
    • C) Automatic Compaction
    • D) TLB Refresh
    Show answer
    B.
  2. Conceptual Question: Compare Paging and Segmentation across 4 architectural dimensions.
  3. Application Question: Translate logical segment addresses to physical addresses using a 4-entry Segment Table.

Finished this topic?

0 of 27 topics read in Operating Systems

Handwritten notes for the exam

Unit-wise SPPU notes and PYQs for this subject.

Helpful? Share it with your class

Free for everyone, no login needed.

Share topic