Paging and address translation
Paging and address translation
Recorded by Dr. Krithika L.B. Slot m4-paging
Non-contiguous allocation with fixed-size pages and frames: splitting addresses into page number and offset, the page table, the TLB cache and effective access time, protection, sharing and page-table structures.
By the end of this session you should be able to:
Divide physical memory into fixed-size blocks called frames and logical memory into blocks of the same size called pages. A process's pages can be loaded into any free frames. A page table per process records which frame holds each page. No external fragmentation — any free frame will do.
Logical memory
Page table
Physical memory
Every logical address is split into a page number p (index into the page table) and a page offset d. Page sizes are powers of two (4 KB is typical), so the split is just bits: for a logical address space of 2m and page size 2n, the high m − n bits are p and the low n bits are d.
\[ p = \left\lfloor \frac{\text{logical}}{\text{page size}} \right\rfloor, \quad d = \text{logical} \bmod \text{page size}, \quad \text{physical} = f \times \text{page size} + d \]
Page size 1 KB (1024 bytes), page table [5, 2, 7, 0], logical address 2100.
p = ⌊2100 / 1024⌋ = 2, d = 2100 − 2048 = 52. Frame f = table[2] = 7. Physical = 7 × 1024 + 52 = 7220.
Bits: with 1 KB pages, d is the low 10 bits; a 16-bit logical address has a 6-bit page number → 64 pages.
Paging has no external fragmentation but has internal fragmentation in the last page: a process of 72 766 bytes with 2048-byte pages needs 36 pages (35 full + 1086 bytes), wasting 962 bytes. On average half a page per process is wasted — an argument for small pages; page-table size argues for large pages.
Page tables are large, so they live in main memory, pointed to by the page-table base register (PTBR). A context switch just changes the PTBR. But now every data access needs two memory accesses — one for the page-table entry, one for the data — halving speed.
The fix is a small, fast associative cache of recent translations: the Translation Look-aside Buffer (TLB), with typically 32–1024 entries searched in parallel.
The CPU produces logical address (p, d).
The TLB is searched for p — all entries compared in parallel.
Hit: frame f is available immediately → access memory at (f, d). One memory access in total.
Miss: read the page-table entry from memory (extra access), get f, and insert (p, f) into the TLB (replacing an entry, e.g. LRU), then access (f, d).
Entries belong to one process: the TLB is flushed on a switch, or each entry carries an ASID (address-space identifier) so entries of several processes can coexist.
With hit ratio α and memory access time m (TLB search time ignored):
\[ \text{EAT} = \alpha \cdot m + (1-\alpha) \cdot 2m \]
m = 100 ns: α = 80% → 0.8 × 100 + 0.2 × 200 = 120 ns (20% slowdown). α = 99% → 0.99 × 100 + 0.01 × 200 = 101 ns (1% slowdown). If a TLB search takes ε ns, add ε to both terms.
libc can be mapped into the page tables of
many processes, pointing to the same frames — 40 users of a 150 KB editor need one copy, not 40.A 32-bit address space with 4 KB pages needs 220 entries (4 MB per process). Page the page table: an outer table points to pages of the inner table (two-level: p1 | p2 | d). 64-bit x86 uses four levels.
Hash the virtual page number into a table of chains; used for address spaces larger than 32 bits.
One entry per physical frame (pid, page) instead of one table per process — saves memory, but lookup requires a search (use hashing).
Paging and address translation
Recorded by Dr. Krithika L.B. Slot m4-paging
The TLB and effective access time
Recorded by Dr. Krithika L.B. Slot m4-tlb
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 0p = ⌊9000/4096⌋ = 2, d = 9000 − 8192 = 808, f = 1 → physical = 4096 + 808 = 4904.
d = 12 bits (212 = 4096), p = 20 bits → 220 pages.
0.9 × 50 + 0.1 × 100 = 55 ns.
No external fragmentation, but internal fragmentation in the last page of each process.
There is one entry per physical frame for the whole system, instead of a large table for every process.
Paging chops a program into equal pieces that mean nothing to the programmer. Segmentation divides memory along the program's own logical units.
Continue to 4.4 — Segmentation →