Segmentation Basics and Motivation
What you'll learn: Why operating systems introduced segmentation as an alternative memory management approach to pure paging.
The Problem with Pure Paging
When you learned about paging, you saw that the OS divides memory into fixed-size chunks (pages and frames). This works well for hardware simplicity, but it doesn't align with how programs are logically structured. A program has distinct parts—code, stack, heap, global variables—yet paging treats everything as an undifferentiated sequence of pages.
What is Segmentation?
Segmentation is a memory management scheme that divides the address space according to the program's logical structure. Instead of uniform pages, the OS creates variable-sized segments that match meaningful program units:
- Code segment (instructions)
- Data segment (global variables)
- Stack segment
- Heap segment
Think of it like organizing a filing cabinet: paging is like splitting all documents into identical 100-page folders regardless of content, while segmentation groups related documents together—contracts in one folder, invoices in another, even if they're different sizes.
Why Segmentation?
Motivation 1: Natural protection. You can set different permissions per segment (execute-only for code, read-write for stack).
Motivation 2: Easy sharing. Two processes can share a code segment without sharing their data—just point both to the same segment.
Motivation 3: Logical growth. The heap can grow independently from the stack, each in its own segment with room to expand.
Key difference from paging: Segmentation respects program semantics. Each segment has meaning and purpose, whereas pages are just arbitrary chunks of bytes.
Key Takeaway: Segmentation was introduced to match memory management to the logical structure of programs, enabling better protection, sharing, and independent growth of different program regions—something pure fixed-size paging doesn't naturally support.