TLB & Address Translation
A page table lives in memory, so every translation could mean an extra memory access. The TLB is a tiny cache that makes the common case fast.
In plain English
The TLB is a sticky note of recent address translations, so the CPU does not reread the whole map.
By the end you will be able to
- Explain a TLB hit and a TLB miss.
- Trace the hit and miss paths.
- Compute effective access time from a hit ratio.
- Explain why locality makes the TLB effective.
TLB hits and misses
The Translation Lookaside Buffer is a small associative cache inside the MMU. It stores recent page-number-to-frame translations. On a hit, the CPU gets the frame immediately. On a miss, the hardware or kernel walks the page table, finds the frame, and inserts the translation into the TLB. If the page is not present, the miss becomes a page fault.
if (TLB contains vpn):
frame = TLB[vpn] /* hit */
else:
frame = page_table[vpn] /* miss: walk */
TLB[vpn] = frameEffective access time
Suppose a TLB lookup takes 10 ns, a memory access takes 100 ns, and the hit ratio is 90%. A hit costs 10 + 100 = 110 ns. A miss costs 10 + 100 + 100 = 210 ns because the page table must also be read. Effective access time = 0.9 × 110 + 0.1 × 210 = 120 ns. Without a TLB, every access would cost at least 200 ns.
EAT = h * (tlb + mem) + (1 - h) * (tlb + mem + mem)
= 0.9 * 110 + 0.1 * 210
= 120 nsLocality and TLB reach
Programs tend to access a small set of pages repeatedly. That locality keeps the TLB hit rate high. TLB reach is the amount of memory the TLB can cover: number of entries times page size. If the working set is larger than the reach, the hit rate drops and performance suffers.
Watch it happen
Step through the worked example. Play it, pause it, or move one step at a time.
step-by-step
Step 1 of 6
Virtual address
The CPU generates 0x1A2B. The TLB will be checked first.
Key takeaways
- The TLB caches page-table translations.
- A hit avoids the page-table walk.
- A miss costs an extra memory access; a missing page becomes a fault.
- EAT depends on hit ratio, TLB access time, and memory access time.
- Locality keeps the TLB effective.
Common pitfalls
- Forgetting to include the TLB lookup time on a miss.
- Assuming a TLB miss always means a page fault.
- Ignoring TLB reach when the working set grows.
Kernel notes
- Compute EAT with a given hit ratio.
- Trace the hit and miss paths.
- Explain why a TLB miss is not necessarily a page fault.
Quick check
1. What happens on a TLB miss?
2. With a 90% hit ratio, 10 ns TLB lookup, and 100 ns memory access, what is the EAT?