5.4.11 · D3 · HinglishMemory Hierarchy & Caches

Worked examplesVirtual memory and paging

3,087 words14 min read↑ Read in English

5.4.11 · D3 · Hardware › Memory Hierarchy & Caches › Virtual memory and paging

Yeh page "no surprises" drill hai. Parent note ne tumhe address translation ki machinery sikhaayi; yahan hum har tarah ke numbers feed karte hain us machinery ko — clean cases, edge cases, degenerate cases, aur woh sneaky exam twists — taaki jab koi exam mein aaye toh tum uska twin pehle se dekh chuke ho.

Yahan sab kuch teen ideas pe based hai jo parent se hain aur hum baar baar use karenge, toh ek baar mein phir se anchor karte hain (koi naya symbol bina picture ke nahi):

Figure — Virtual memory and paging

Figure dekho: ek address ek ruler jaisa hai. Bit par red line woh cut hai. Cut ke left mein sab VPN hai (jo replace hota hai), right mein sab unchanged reh'ta hai. Is page mein yeh red line tab tak nahi move hogi jab tak page size na badle. Woh picture apne dimag mein rakho.


The scenario matrix

Is topic ka har problem in cells mein se ek (ya combo) hota hai. Hum sab hit karenge.

Cell Kya tricky banata hai Covered by
A. Clean split plain hex, digits line up Ex 1
B. Non-nibble page size 4 ka multiple nahi, toh hex digits mid-digit split hoti hain Ex 2
C. Offset = 0 (page boundary) address exactly ek page start par baith'ta hai Ex 3
D. Offset = max (page ka last byte) address rollover se pehle bilkul last byte hai Ex 3
E. Reverse direction PA diya hua, VA recover karo (inverse map) Ex 4
F. Table-size scaling VA bits / entry size ke saath tables ke liye RAM kaise badhti hai Ex 5
G. Multi-level walk VPN khud index levels mein split hota hai Ex 6
H. Performance / EAT limiting behaviour jab hit ratio aur Ex 7
I. Word problem swap/disk timing, "kya yeh ek page fault hai?" Ex 8
J. Degenerate / trap invalid VPN, unmapped page, offset overflow Ex 9

Agar koi cell neeche kisi example mein nahi hai, toh is page mein bug hai. Chalte hain.


Cell A — the clean split


Cell B — woh page size jo ek hex digit split karti hai

Real exams mein jaisi page size bahut pasand hai, jahan 4 ka multiple nahi hota. Ab cut ek hex digit ke beech mein se guzarti hai, aur "last few hex digits rakho" silently fail ho jaata hai. Tumhe binary pe fall back karna hoga.


Cells C & D — dono extremes par offset (page boundaries)

Do sabse zyada misread inputs hain page ka pehla byte (offset ) aur last byte (offset ). Dono ek saath karte hain aur dekhte hain kya hota hai agar last byte ke ek byte aage jaao.

Figure — Virtual memory and paging

Figure yeh dikhata hai: virtual pages 8 aur 9 side by side baithe hain, lekin unke frames (3 aur, maan lo, 7) physical RAM mein scattered hain. Page boundary ek hard wall hai — isko cross karo aur table phir se consult karni padti hai.


Cell E — map ko ulta chalana

Ek physical address diya hua hai, kaun sa virtual address usne produce kiya? Offset trivial hai (unchanged). Page part ke liye tum table invert karte ho: woh VPN dhundho jiska entry yeh PFN hai.


Cell F — table cost kaise scale karta hai


Cell G — the multi-level walk

Cell F ka fix: VPN khud ko index pieces mein split karo, ek per table level, aur sirf woh sub-tables banao jo actually use ho rahe hain.


Cell H — limits par performance

Figure — Virtual memory and paging

Figure EAT versus hit ratio plot karta hai: se tak ek straight line. Steepness ( per unit of hit ratio) hi miss penalty hai. Real TLBs far-right par rehte hain (), ke paas.


Cell I — the word problem (swap timing)


Cell J — degenerate & trap inputs


Recall

Recall Yeh kaun sa cell hai? (answers cover karo)
  • Page size , VA : offset kya hai? ::: (Cell B — mask , non-nibble).
  • PA exactly ek frame boundary par baith'ta hai. Uska offset kya hai? ::: (Cell C).
  • PA diya hua, kya VA recover karna hamesha unique hota hai? ::: Sirf ek process ki page table ke andar (Cell E).
  • 48-bit VA, 4 KiB pages, 8-byte entries — flat table size? ::: , isliye multi-level (Cell F).
  • Two-level walk: TLB miss par translation mein memory accesses kitne? ::: 3 (2 table + 1 data) (Cell G).
  • EAT jab with ? ::: (Cell H).
  • Valid bit 0 hai aur page kabhi allocate nahi hua — kya fire karta hai? ::: Segmentation fault (Cell J).