5.4.12 · D1 · HinglishMemory Hierarchy & Caches

FoundationsTLB (translation lookaside buffer)

2,751 words13 min read↑ Read in English

5.4.12 · D1 · Hardware › Memory Hierarchy & Caches › TLB (translation lookaside buffer)

Yeh page kuch bhi assume nahi karta aur poori tarah self-contained hai. End tak tum har symbol ke baare mein bol sako ge ki woh kya matlab rakhta hai aur woh kaisa dikhta hai. Hum inhe ek ek karke banate hain, har ek sirf pehle wale ko use karta hai, phir tumhe main TLB (translation lookaside buffer) note par bhejte hain.


1. Ek "byte" aur ek "address" — memory ka alphabet

Yeh matter kyun karta hai: ek TLB jo bhi karta hai woh ek box-number ko doosre box-number mein badalna hai. Agar memory ko numbered boxes ki tarah picture nahi karte, toh translation ki koi bhi baat samajh nahi aayegi.


2. Bits aur — ek number kitne boxes naam de sakta hai?

Hum thodi der mein ek page ke andar bits count karne ke liye use karenge — lekin pehle define karna padega ki page kya hai.


3. Ek address ko split karna: page part aur offset part

Yeh matter kyun karta hai: ek TLB sirf page number translate karta hai aur offset ko akela chhod deta hai. "Offset translate nahi hota" ka idea, bina address ko "do parts mein cut karo" ki mental picture ke, meaningless hai.


4. Virtual vs physical — do alag mailbox streets

Yeh VPN → PFN mapping Page Table mein store hoti hai, aur poora scheme Virtual Memory hai.


5. Page table — bada map (aur yeh slow kyun hai)

Catch yeh hai: kyunki map khud DRAM mein rehta hai, ise padhna ek memory access ki cost lagata hai. Toh ek naive translation hai "map padho (1 access), phir data padho (1 access)" — kam se kam double kaam. Modern maps kaafi levels mein split hote hain, isliye ek poori page-table walk ke liye 4 memory reads ho sakte hain apna data touch karne se pehle bhi. Yeh slowness hi woh poori wajah hai jiske liye TLB banana worth it hai.

Agar ek page ka valid bit off hai, ise touch karna ek Page Fault trigger karta hai — OS ko ise disk se fetch karna padega. Yeh ek alag, bahut slower event hai ek mere translation miss se.


6. Shift, OR, aur frame ka base address

Worked check: PFN 0x0037 ke saath KiB, toh .

  • decimal mein.
  • 0x37000. Yeh frame ka base byte address hai, low 12 bits sab zero ke saath (ek empty offset-slot).
  • Ab offset 0xABC OR karo: kyunki 0x37000 ke low 12 bits mein zeros hain aur 0xABC exactly 12 bits mein fit hota hai, . Offset cleanly hole mein slot ho jaata hai.

7. Locality, caches, aur payoff measure karna

Locality of Reference ki wajah se, sirf last-used thodi VPN → PFN mappings hold karne wali ek notepad zyaatar translations satisfy kar legi. Woh notepad ek cache hai, aur yeh specific wala TLB hai. (General caching idea Cache (memory hierarchy) hai.)


8. Context switch — notepad stale kyun ho sakti hai

Toh Context Switch ke baad, notepad ki yaad ki hui translations galat program ki ho sakti hain — stale entries. Sirf itna jaanna hai kyun hota hai: do programs same VPNs reuse karte hain different frames ke liye.


Prerequisite map

byte and address

bits and log2

split address into page and offset

memory as numbered boxes

virtual VA VPN

physical PA PFN frame

page table map

shift and OR equal place bits

locality of reference

cache hit miss and EMAT

TLB

context switch

Ise bottom-up padho: sab kuch K = TLB mein funnel hota hai. Agar koi bhi upstream box fuzzy hai, K mein jaane wale arrows toot jaate hain.


Equipment checklist

Khud test karo — right side cover karo aur zor se jawab do.

Ek byte mein kitne bits hote hain, aur woh kitni values hold kar sakta hai?
8 bits, 256 possible values.
Ek address plain words mein kya hai?
Mailbox par painted number — kisi ek storage location ko naam dene ka tarika.
Memory sizes powers of two mein kyun aati hain?
Addresses bits se bane hote hain; bits locations ko naam dete hain.
aur yeh kya count karta hai?
12; 4096 cheezein naam dene ke liye needed bits ki sankhya, kyunki .
Page size power of two kyun honi chahiye?
Taaki address, page-number aur offset mein clean bit-cut se split ho jaye, ko offset bits ka poora number banata hai.
Symbol ka kya matlab hai?
Concatenation — do bit-groups ko side by side ek number mein chipkao (multiply nahi).
Bitwise OR () yahan kya karta hai?
Ek bit ko 1 set karta hai agar kisi bhi input mein woh ho; frame ke base address ke empty low bits mein offset drop karne ke liye use hota hai.
Jab address split karte ho, konsa part translate hota hai?
Sirf page-number part; offset unchanged nikal jaata hai.
VPN vs PFN ek ek line mein?
VPN = konsa pretend (virtual) page; PFN = konsa real (physical) frame.
Baayein se shift karna se multiply kyun karta hai?
Bits ka har ek baayein slide value double karta hai; baar karo → se multiply.
Page table physically kahan rehta hai, aur yeh problem kyun hai?
DRAM mein; ise padhna ek full memory access cost karta hai, isliye translation har access ko double kar deta.
Locality of reference kya hai?
Programs same kuch pages baar baar touch karte hain, isliye translations cache karna faaydemand hota hai.
EMAT kiska short form hai aur kya measure karta hai?
Effective Memory Access Time — fast hits aur slow misses mix karke har access ka average time.
Cache hit vs miss?
Hit = answer already stored (fast); miss = stored nahi, ek baar slow path pay karo, phir yaad karo.
Context switch ke baad TLB galat data kyun hold kar sakta hai?
Alag programs same VPNs ko alag frames ke liye reuse karte hain, isliye purani entries stale ho jaati hain.