Operating System Slides 📂 Introduction · 17 of 22 48 min read

Paging & TLB in OS: Address Translation & Effective Access Time

Learn how paging ends external fragmentation — fixed-size pages and frames mapped by a page table, with logical addresses bit-sliced into <p, d>. Covers the two-memory-access problem, the TLB cache, the Effective Access Time (EAT) formula, valid/RWX bits and copy-on-write, plus two worked numericals — all with animated diagrams.

📑

Paging & the TLB — Address Translation & Effective Access Time

The technique that ended external fragmentation for good: chop memory into fixed-size pages and frames, map them with a page table, and cache the hot translations in a tiny TLB. See the bit-slicing, the two-access problem, and the EAT maths that makes paging practical — with fully animated diagrams and two worked numericals.
Pages & Frames TLB Cache EAT Formula 2 Numericals
Press Next → or use ← → arrow keys
SECTION 01

Why Paging Works — Airport Lockers

Ten Thousand Identical Lockers
Imagine an airport with 10,000 identical storage lockers. You arrive with more than one locker can hold, so you split your belongings: jacket in locker 47, books in 291, toiletries in 8034. They needn't be next to each other — you just keep a small card noting which locker holds what. Retrieval is instant because every locker is the same shape and the card tells you exactly where to look.
🧠
Belongings, Lockers, and a Card

Your belongings are a process's pages; the identical lockers are physical frames; the reference card is the page table. Because all frames are the same size and a page can go in any free frame, memory never breaks into unusable gaps — the flaw that plagued contiguous allocation.

SECTION 02 · DIAGRAM

Pages, Frames & the Page Table

Logical pages Page table Physical RAM (frames) Page 0 Page 1 Page 2 Page 3 pageframe 01 14 23 37 Frame 0 Frame 1 · Page 0 Frame 2 Frame 3 · Page 2 Frame 4 · Page 1 Frame 5 Frame 6 Frame 7 · Page 3
🗂️
Contiguous to the Program, Scattered in RAM

The program sees pages 0, 1, 2, 3 in order; the page table sends them to frames 1, 4, 3 and 7 — wherever RAM had room. A common page (and frame) size is 4 KB. The page table has one entry per page and is the only thing the hardware needs to translate an address.

SECTION 03 · DIAGRAM

Bit-Slicing a Logical Address

logical address (page size = 2ⁿ bytes) page # offset high bitslow n bits Index the page tablep = L >> nf = PageTable[p] Carried through unchangedd = L & (2ⁿ − 1)physical = (f << n) | d
✂️
No Division — Just Bit Shifts

Because page size is a power of two (2ⁿ), the hardware never divides. The low n bits are the offset; the rest are the page number. Only the page number is translated through the table; the offset is copied straight into the physical address — which is why translation is effectively free.

SECTION 04 · WORKED

Translating Address 13 (page size 4)

logical = 13011 · 01 page 011=3 · offset 01=1 PageTable[3]frame = 7 = 111 offset (unchanged)01 = 1 physical address111 · 01 = 11101 = 7×4+1 = 29
🎯
Logical 13 → Physical 29

With a 4-byte page (2 offset bits), address 13 = 01101₂ splits into page 3 and offset 1. The table maps page 3 → frame 7, so the physical address is 7 × 4 + 1 = 29 — or just glue the bits: 111·01 = 11101. Same answer, no arithmetic.

SECTION 05 · DIAGRAM

Fragmentation — The Trade Paging Makes

External · eliminated ✓ Internal · last page ⚠ frame · used frame · used frame · used frame · used identical sizes → no unusable gaps 15 KB used 1 KB wasted 15 KB process → 4 pages = 16 KB avg waste ≈ page_size / 2
⚖️
External Gone, a Little Internal Left

Uniform frames mean a page fits any free frame, so external fragmentation vanishes. The only waste is internal: the last page is rarely full. A 15 KB process needs 4 pages (16 KB) and wastes 1 KB — on average half a page per process. Smaller pages waste less but grow the page table.

SECTION 06 · DIAGRAM

The Cost — Two Memory Accesses

CPU<p, d> ① page tablememory access 1 ② the datamemory access 2 2 × slowerevery reference
🐢
Paging's Hidden Tax

The page table lives in RAM, so a plain paged reference costs two memory accesses: one to read the table entry, one to fetch the data. That halves effective memory speed. The fix is a tiny, fast cache of recent translations — the TLB.

SECTION 06 · DIAGRAM

The TLB in Action

Access sequence · 3-entry TLB (LRU) 3MISS 3HIT 5MISS 3HIT 5HIT 7MISS 2MISS 3MISS Final TLB page 7 → frame …page 2 → frame …page 3 → frame … 3 hits · 5 misseshit rate = 3 / 8 = 37.5%cold start — warms toward 99%
Small, Fully Associative, Blazing Fast

The TLB holds 64–1024 recent (page → frame) pairs and compares them all in parallel in a single cycle. A hit skips the page table entirely; a miss falls back to memory and caches the result, evicting the LRU entry when full. This cold run hits only 37.5%, but a running program's TLB quickly warms to 99%+.

SECTION 06 · DIAGRAM

Translation With the TLB

CPU<p, d> TLBpage p cached?64–1024 entries Physical RAMframe + d HIT · 1 access MISS → page table (extra access)then cache the result in TLB
🔁
Hit = One Access · Miss = Two

The MMU checks the TLB first. On a hit the frame is known instantly and only the data read remains — one access. On a miss it reads the page table (a second access) and caches the translation so the next reference to that page is a hit. On a context switch the OS must flush the TLB or tag entries with an ASID, since each process has its own page table.

SECTION 07 · DIAGRAM

Effective Access Time (EAT)

referencecheck TLB HIT (α)T_TLB + T_mem = 20 + 100 = 120 ns MISS (1−α)T_TLB + 2·T_mem = 20 + 200 = 220 ns EATweighted average
# Galvin's Effective Access Time
EAT = α × (T_TLB + T_mem)  +  (1 − α) × (T_TLB + 2 × T_mem)
    = α × 120          +  (1 − α) × 220        # with T_TLB=20 ns, T_mem=100 ns
⏱️
The Hit Ratio Drives Everything

α is the TLB hit ratio. A hit pays one memory access plus the TLB probe; a miss pays two memory accesses plus the probe. As α → 1, EAT approaches raw memory time (≈ 120 ns) — the TLB is what makes paging cheap.

NUMERICAL 1

EAT at 80% vs 98% Hit Ratio

Given T_mem = 100 ns, T_TLB = 20 ns → hit cost 120 ns, miss cost 220 ns.

Hit ratio αEAT workingEATSlowdown
0.800.80 × 120 + 0.20 × 220 = 96 + 44140 ns1.40×
0.980.98 × 120 + 0.02 × 220 = 117.6 + 4.4122 ns1.22×
1.00 (ideal)1 × 120120 ns1.20×
No TLB2 × 100200 ns2.00×
📈
18 Points of Hit Rate → Half the Overhead

Raising the hit ratio from 80% to 98% cuts EAT from 140 ns to 122 ns — overhead drops from 40% to 22%. Without any TLB, every reference costs 200 ns (100% overhead). Real TLBs run at 99%+, so paging's real-world cost is a few percent.

NUMERICAL 2

Five Address Translations

Page size 1024 B, 8 pages (max address 8191). Page table: 0→8, 1→3, 2→1, 3→5, 4→6, 5→7, 6→2, 7→4. Formula: p = L ÷ 1024, d = L mod 1024, physical = frame × 1024 + d.

Logical Lp, dframePhysical = f×1024 + d
1500p=1, d=47633×1024 + 476 = 3548
2049p=2, d=111×1024 + 1 = 1025
6000p=5, d=88077×1024 + 880 = 8048
1023p=0, d=102388×1024 + 1023 = 9215
8191p=7, d=102344×1024 + 1023 = 5119
🧮
Same Recipe Every Time

Split the logical address into page and offset, look the page up in the table for its frame, then rebuild: frame × page_size + offset. Note L = 8191 is the very last legal byte (page 7, offset 1023) — one more and it would overflow the 8-page space.

SECTION 10 · DIAGRAM

Protection, Sharing & Copy-on-Write

Parent page tablelibc page → frame 12 Child page tablelibc page → frame 12 Frame 12 · shared libcR + X · read-onlyvalid bit = 1 · one physical copy
🚦
Valid / Invalid Bit
Marks whether a page is really in RAM. Touch an invalid page and the hardware raises a page fault for the OS to handle.
🔏
R / W / X Bits
Per-page permissions let the OS mark code read-only and data non-executable — the NX defence, at page granularity.
🐣
Copy-on-Write
After fork(), parent and child share every page read-only; the OS copies a page only on the first write. fork() of a huge process is near-instant.
SECTION 11

Paging in the Real World

🖥️
Every Modern OS
4 KB pages
Linux, Windows, macOS, iOS and Android all page memory with 4 KB pages, and support 2 MB "huge pages" for big workloads.
🏛️
x86-64 MMU
4-level tables
PML4 → PDPT → PD → PT, 512 entries each level, with a TLB of ~64 L1 + 1024 L2 entries per core and aggressive prefetch.
🐣
Linux fork()
COW paging
Copy-on-write means spawning a process duplicates page-table entries, not memory — pages copy only on first write.
🗄️
Memory-Mapped Files
mmap()
Files map into the virtual address space; blocks load on demand via page faults — zero-copy I/O.
📚
Shared Libraries
libc.so
One physical copy of a library is shared across every process through paging, saving hundreds of megabytes.
🎲
KASLR & Sandboxing
Security
Kernel Address Space Layout Randomization shuffles page tables per boot; container isolation is built on paging.
SECTION 12

Eight Rules for Paging & the TLB

📑 PAGING · CHECKLIST
1
A logical address is <p, d>; if page size = 2ⁿ, the low n bits are the offset — pure bit slicing.
2
Translate with physical = PageTable[p] × page_size + d — a shift and an OR, effectively free.
3
Identical frame sizes eliminate external fragmentation — a page fits any free frame.
4
Only internal fragmentation remains, in the last page — about half a page per process.
5
Without a TLB, every reference needs two memory accesses (table + data) — half speed.
6
The TLB is a small, fully-associative cache of recent translations: hit = 1 access, miss = 2.
7
EAT = α(T_TLB + T_mem) + (1−α)(T_TLB + 2·T_mem); higher α approaches raw memory time.
8
Page-table entries carry valid + R/W/X bits — enabling NX, copy-on-write fork, and shared libraries.
FINAL

Fixed-Size Frames, Cached Translations

<p, d>Bit-sliced address
0 externalFragmentation
120 nsTLB-hit access
99%+Real TLB hit rate
COWInstant fork()
🎯
You Now Understand Paging & the TLB

From the page-table map and bit-slicing, through fragmentation and the two-access problem, to the TLB, the EAT formula and copy-on-write — you can translate any address by hand and compute how fast paged memory really runs.

📚
Where To Go Next

Paging plus a valid/invalid bit is the gateway to virtual memory — demand paging, page-fault handling and page-replacement algorithms (FIFO, LRU, Optimal), where a process runs with only part of it in RAM. That's the next tutorial.

📑 End of tutorial · Press to review, or click Restart