Segmentation Explained
- Process Management
- Memory Management
- Deadlocks
- OS Introduction & Fundamentals
- CPU Scheduling Algorithms
- Threads & Concurrency
- Inter-Process Communication (IPC)
- Process Synchronization
- Virtual Memory & Paging
- File Systems
- Disk Scheduling
- I/O Management
Dividing Memory by Logical Meaning, Not Fixed Size
Paging (covered in the previous note) divides memory into fixed-size chunks with no regard for what they logically represent. Segmentation instead divides a process's memory according to its actual logical structure - separate segments for code, data, stack, and so on - each segment sized exactly to fit what it actually needs.
A process's logical view, divided into segments:
+------------+------------+-----------+
| Code | Data | Stack |
| segment | segment | segment |
+------------+------------+-----------+
(each segment can be a genuinely different size, matching its actual content)The Segment Table: Similar in Spirit to a Page Table
Segment Table
Segment Base (start address) Limit (size)
Code 4000 1500
Data 6200 3000
Stack 9500 2000A segment table tracks where each segment actually lives in physical memory (its base address) and how large it is (its limit) - each memory access specifies both a segment number and an offset within that segment, and the hardware translates this into an actual physical address.
Paging vs Segmentation: A Direct Comparison
| Paging | Segmentation | |
|---|---|---|
| Division basis | Fixed physical size | Logical program structure |
| Segment/page sizes | All identical | Can vary, matching actual content |
| External fragmentation | None | Can still occur, since segments vary in size |
| Programmer/compiler visibility | Invisible to the process | Can align meaningfully with logical program divisions |
Combining Both: Segmentation With Paging
Many real systems use both together - dividing memory logically into segments first, then further dividing each individual segment into fixed-size pages - capturing paging's freedom from external fragmentation while still preserving segmentation's logical, meaningful structure.
Why Understanding Both Approaches Matters
Recognizing these as two genuinely different philosophies - dividing by fixed size versus dividing by logical meaning - makes it much easier to understand why modern systems often blend both ideas together rather than relying on either one in its pure, original form.