5.4.12 · HinglishMemory Hierarchy & Caches

TLB (translation lookaside buffer)

1,812 words8 min readRead in English

5.4.12 · Hardware › Memory Hierarchy & Caches


TLB exist kyun karta hai?


Yeh precisely kya hai?

Ek address page part aur offset mein split hota hai:

Offset translate nahi hota — sirf page number hota hai. Toh TLB VPN → PFN (physical frame number) map karta hai, aur:

jahan = page size hai.


Lookup kaise kaam karta hai (flow derive karo)

Har memory access par:

  1. VA ko VPN + offset mein split karo.
  2. TLB mein VPN lookup karo.
    • TLB hit → PFN turant milo → PA banao → cache/memory access karo.
    • TLB miss → poora page-table walk karo (hardware ya OS) PFN lene ke liye → TLB mein insert karo → retry karo.
  3. Valid aur permission bits bhi check karo (read/write/execute, user/kernel). Violation fault raise karta hai.
Figure — TLB (translation lookaside buffer)

Performance: Effective Memory Access Time

Maano:

  • = TLB hit rate, = TLB search karne ka time,
  • = ek memory access time,
  • ek walk mein memory accesses lagte hain (single-level ke liye 1, -level ke liye ).

Hit par: TLB search + ek data access = . Miss par: TLB search + walk () + data access = .

Probability se weight karke:


Context switches aur consistency (tricky part)



The 80/20 core

Recall Feynman: 12-year-old ko samjhao

Socho tumhare school mein hazaaron lockers hain, lekin woh map jo batata hai tumhara locker kaunsa hai woh principal ke office mein door rakha hai. Har baar book lene ke liye tumhe office jaana padta, map padhna padta, phir locker tak jaana padta — bahut slow. Toh tum apni pocket mein ek sticky note rakh lo jisme tumhare sabse zyada use hone wale locker numbers hain. TLB wahi sticky note hai: pehle pocket check karo (fast!), aur sirf tab office (page table) tak jao jab note mein nahi hai.


Flashcards

TLB kya cache karta hai?
Recently-used virtual-page-number → physical-frame-number translations (plus permission/valid bits).
Page offset kabhi translate kyun nahi hota?
Paging poore pages ko frames mein move karta hai; ek byte apni position page ke andar rakhta hai, toh low bits VA aur PA mein identical hote hain.
4KiB page ke liye kitne offset bits?
12, kyunki .
TLB miss par kya hota hai?
Page-table walk PFN dhundh ta hai, mapping TLB mein insert hoti hai, aur access retry hota hai.
TLB miss aur page fault mein kya farq hai?
TLB miss = translation cached nahi lekin page memory mein hai (fast walk); page fault = page physical memory mein nahi (disk se load karna padega).
EMAT formula do.
, jahan hit rate aur walk length accesses hai.
Hit rate itna zyada kyun matter karta hai?
Extra cost miss fraction ke saath scale karta hai; har miss ek poora walk cost karta hai, toh mein thodi si giraawat access time badha deti hai.
Context switch par TLB handle karne ke do tarike?
Poora TLB flush karo, ya entries ko ASID/PCID se tag karo taaki multiple address spaces coexist karein.
TLB shootdown kya hai?
OS page change/unmap kare tab cores mein stale TLB entry invalidate karna (inter-processor interrupt ke zariye).
PFN aur offset se PA kaise banta hai?
.
TLB ko huge kyun nahi banate?
Yeh har access ke critical path par hai; bada = slower/zyada power. Isliye multi-level TLBs (L1 small+fast, L2 bigger).

Connections

  • Virtual Memory — TLB us address translation ko accelerate karta hai jo paging require karta hai.
  • Page Table — woh slow structure jise TLB cache karta hai; miss par consult hota hai (the "walk").
  • Cache (memory hierarchy) — same locality principle; VIPT caches TLB lookup ko cache indexing ke saath overlap bhi karte hain.
  • Context Switch — TLB flush ya ASID handling trigger karta hai.
  • Page Fault — ek alag miss: page RAM se absent hai, sirf TLB se nahi.
  • Locality of Reference — isliye TLB ki small size bhi high hit rates deti hai.

Concept Map

requires

reads

causes

motivates

caches

lives in

splits into

looked up in

hit

miss triggers

inserts into

checks

Virtual memory paging

Page-table walk

Page table in DRAM

2x to 5x slower access

Program locality

TLB cache

VPN to PFN mappings

MMU hardware

Virtual address

VPN + offset

Form physical address

Valid and permission bits