4.1.15 · HinglishComputer Architecture (Deep)

TLB — structure, TLB miss handling

2,202 words10 min readRead in English

4.1.15 · Coding › Computer Architecture (Deep)


TLB KYA hai?

Key vocabulary

  • VPN (Virtual Page Number): virtual address ke high bits (page index).
  • PFN / PPN (Physical Frame Number): physical address ke high bits.
  • Page offset: low bits — yeh virtual aur physical addresses mein identical hote hain, isliye inhe kabhi translate nahi kiya jata.

Addresses kaise split hote hain


TLB ki Structure

Ek TLB entry kuch aisi dikhti hai:

Valid ASID/PCID VPN (tag) PFN Dirty Permissions (R/W/X, U/S) Global
Figure — TLB — structure, TLB miss handling

TLB lookup logic


TLB MISS handling — iska dil

Do philosophies hain ki kaun TLB ko refill karta hai.

Step-by-step miss flow (hardware-managed)

Performance model


Common mistakes (Steel-manned)


Flashcards

TLB kya cache karta hai?
Recently-used page-table entries: VPN → PFN mappings plus metadata (valid, dirty, permissions, ASID).
Page offset kabhi translate kyun nahi hota?
Translation per-page hoti hai; offset sirf ek byte ko page ke andar locate karta hai, jo page relocate hone par nahi badalta.
V-bit virtual address aur page size diye hain, VPN mein kitne bits hain?
bits; offset bits hai.
TLB miss aur page fault mein kya fark hai?
TLB miss = translation cached nahi lekin page table mein exist karti hai (sasti walk). Page fault = page physical memory mein nahi hai (slow disk access).
Hardware- vs software-managed TLB?
Hardware: ek page-table walker miss par auto-refill karta hai (x86/ARM). Software: ek trap OS handler ko invoke karta hai jo entry likhta hai (MIPS).
EMAT formula kya hai?
jahan =hit ratio, =page-table levels.
ASID/PCID field kya prevent karta hai?
Context switch par full TLB flushes — alag processes ke entries apne owning address space ke tag se saath coexist karte hain.
TLB hit par physical address kaise banta hai?
.
Global bit kya mark karta hai?
Kernel/shared pages jo saare address spaces mein valid hain — context switch par kabhi flush nahi hote.
Page tables multi-level kyun hote hain (TLB miss cost se relevant)?
flat entries store karne se bachne ke liye; cost yeh hai ki ek miss walk memory accesses leta hai.

Recall Feynman: 12-saal ke bachche ko samjhao

Socho tumhara ghar ka number ek secret code mein likha hai, aur asli street dhundhne ke liye tumhe ek bade phone book mein dekhna padta hai. Har ek kadam par yeh karna exhausting hoga. Toh tum ek tiny notepad rakhte ho apne last few lookups ke saath. Woh notepad hi TLB hai. Agar tumhara chahiye address notepad par hai — instant! Agar nahi, tum bade phone book mein jaate ho (page table), answer apne notepad par copy karte ho, aur continue karte ho. Agar jagah phone book mein bhi nahi hai, toh tume door ke storage se mangwana padta hai — woh slow page fault hai.


Connections

  • Virtual Memory — woh abstraction jise TLB accelerate karta hai.
  • Page Tables (Multi-level) — jo TLB miss walk karta hai.
  • Cache Memory & Associativity — TLB ek cache hai; same set/fully-associative ideas.
  • Page Faults & Demand Paging — kya hota hai jab walk ek invalid PTE paata hai.
  • Context Switching — kyun ASID/PCID aur TLB flushes matter karte hain.
  • Huge Pages / TLB Reach — ek single TLB entry ki coverage tune karna.

Concept Map

split into

split into

passes through untranslated

lookup in

hit gives

combines with offset

entry stores

on miss

finds

fills

organized as

too large to walk each time

Virtual Address

VPN page number

Page Offset

Physical Address

TLB cache of PTEs

Physical Frame Number

Valid ASID Dirty Perms Global

Page Table Walk in DRAM

Page Table Entry

Fully or Set Associative

Multi-level Page Table