Segmentation
Segmentation
Recorded by Dr. Krithika L.B. Slot m4-segmentation
Memory organised as the programmer sees it — variable-size segments with base and limit — and how segmentation combines with paging.
By the end of this session you should be able to:
Programmers do not think of a program as a linear array of bytes, but as a collection of variable-sized logical units: main program, functions, global variables, stack, symbol table, arrays. Segmentation is a memory-management scheme that supports this view: the logical address space is a collection of segments, each with a name (number) and a length.
A logical address is a pair <segment-number s, offset d>. The C compiler, for example, might create separate segments for code, globals, heap, each thread's stack, and the standard library.
Each entry of the segment table has a base (starting physical address of the segment) and a limit (its length). The segment-table base register (STBR) points to the table; STLR holds the number of segments.
CPU issues (s, d).
If s ≥ STLR → trap (no such segment).
Look up entry s: if d ≥ limit → trap: addressing error (segmentation fault).
Physical address = base + d.
| Segment | Limit | Base |
|---|---|---|
| 0 | 1000 | 1400 |
| 1 | 400 | 6300 |
| 2 | 400 | 4300 |
| 3 | 1100 | 3200 |
| 4 | 1000 | 4700 |
Because segments are meaningful units, protection fits naturally: the code segment can be marked read-only/execute, the data segment read–write, and an array can be bounds-checked by the hardware limit. Sharing is also natural — two processes share a library by having segment-table entries with the same base.
| Paging | Segmentation | |
|---|---|---|
| Unit size | Fixed (page) | Variable (segment) |
| Visible to programmer? | No | Yes — logical units |
| Address | Single number split into (p, d) | Explicit pair (s, d) |
| Fragmentation | Internal (last page) | External (variable holes) |
| Table entry | Frame number | Base and limit |
| Protection / sharing | Per page | Per logical unit — more natural |
Segments still need contiguous memory, so external fragmentation returns. Combining both gets the best of each: each segment is itself paged. The logical address (s, d) is first turned into a linear address using the segment table, then the linear address is translated by paging. This is the classic Intel IA-32 design (segmentation unit → paging unit). In 64-bit x86-64, segmentation is essentially disabled (flat segments) and paging does the work.
Segmentation
Recorded by Dr. Krithika L.B. Slot m4-segmentation
Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.
Answer each question in your own words first, then reveal the model answer.
Revealed 0(1,10) → 6310 · (4,1100) → trap (limit 1000) · (3,0) → 3200.
External fragmentation, because segments have variable sizes.
Segments correspond to logical units (code, data, stack) that need different protection; a page may mix different kinds of content.
Segment-table base register (location of the segment table) and segment-table length register (number of segments).
So far a whole process had to be in memory to run. What if only the parts actually being used were loaded? That is virtual memory.
Continue to 4.5 — Virtual memory and demand paging →