Segmentation is a memory-management scheme that supports the user’s view of memory, dividing a process’s logical address space into variable-sized segments—each corresponding to a logical unit such as code, data, stack, or shared libraries. Unlike paging (fixed-size blocks), segmentation preserves the program’s modular structure.
1. Segmentation Concepts
- Logical Address
- Represented as a pair ⟨s, d⟩, where
- s = segment number
- d = offset within that segment
- Segment Table
- Each process has its own table of n entries, one per segment.
- Entry i contains:
- Base\[i] = physical start address of segment i in RAM
- Limit\[i] = length (size) of segment i
- Address Translation
- On a memory reference ⟨s, d⟩:
- Bounds Check:
- If d ≥ Limit\[s], raise a segmentation fault.
- Physical Address:
2. Example
Consider a process with 4 segments:
| Segment (s) |
Logical Unit |
Base (hex) |
Limit (bytes) |
| 0 |
Main code |
0x12000 |
30 000 |
| 1 |
Global data |
0x1A000 |
5 000 |
| 2 |
Heap (dynamic alloc) |
0x1C800 |
10 000 |
| 3 |
Stack |
0x22000 |
4 096 |
- Reference 1: ⟨0, 12 000⟩
- Check: 12 000 < 30 000 ✔
- Physical = 0x12000 + 12 000 = 0x15000
- Reference 2: ⟨3, 5 000⟩
- Check: 5 000 ≥ 4 096 ✖ → Segmentation fault
This illustrates how each logical reference maps to a unique, variable-length region in physical memory.
3. Advantages of Segmentation
- User-View Alignment: Segments reflect logical program structure (modules, routines), easing protection and sharing.
- Protection & Sharing:
- Each segment can have distinct access rights (read-only code, read/write data).
- Individual segments (e.g., libraries) can be shared among processes by mapping their tables to the same frames.
- Dynamic Growth: Segments like the heap or stack can grow independently (by updating Limit and Base).
4. Disadvantages of Segmentation