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 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
5Working / How It Works
- Logical Address Structure: .
- Address Translation Sequence:
- CPU generates logical address .
- MMU looks up index in the Segment Table to retrieve Limit and Base.
- Check Bounds: MMU checks if Offset .
- If , MMU triggers a Trap: Addressing Error (Segmentation Fault).
- Compute Physical Address: Physical Address .
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 Structure | Single Linear Address split into | 2D Logical Address |
| Internal Fragmentation | Minor (Last page) | Zero |
| External Fragmentation | Zero | Present (Variable segment swapping) |
7Solved Examples / Problems
Problem: Given the following Segment Table:
| Segment () | Base | Limit |
|---|---|---|
| 0 | 219 | 600 |
| 1 | 2300 | 140 |
| 2 | 90 | 100 |
Evaluate physical addresses for:
Solution:
- For :
- Check Limit: Is ? Yes (Valid).
- Physical Address = .
- For :
- Check Limit: Is ? 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
- MCQ: What happens when a process attempts to access a segment offset 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. - Conceptual Question: Compare Paging and Segmentation across 4 architectural dimensions.
- Application Question: Translate logical segment addresses to physical addresses using a 4-entry Segment Table.
