5.4.13 · D4 · HinglishMemory Hierarchy & Caches

ExercisesPage tables and multi-level paging

3,041 words14 min read↑ Read in English

5.4.13 · D4 · Hardware › Memory Hierarchy & Caches › Page tables and multi-level paging

Shuru karne se pehle, ek shared picture. Inn problems mein har virtual address bits ki ek row hai jo named fields mein cut ki gayi hai — blue aur yellow blocks milke VPN banate hain, aur green block woh offset hai jo bina kisi badlaav ke through chali jaati hai. Hum is picture ka seedha reference Solutions 2.1 aur 2.2 mein karte hain, isliye ise abhi dhyan se dekho.

Figure — Page tables and multi-level paging

L1 — Recognition

Problem 1.1

Ek system mein -bit virtual addresses hain aur page size hai. (offset bits), (VPN bits), aur flat page table ko kitni entries chahiye hogi, yeh batao.

Recall Solution 1.1

KYA compute karein: field widths, phir table length. KYUN: bytes. Ek page ke andar kisi byte ka naam lene ke liye kitne bits chahiye, yeh exactly hai kitne bytes woh hold karta hai: Address ka baaki hissa page ka naam batata hai: Flat table mein har possible page ke liye ek entry hoti hai, yaani har VPN value ke liye ek: Answer: , , entries .

Problem 1.2

Har item ko match karo ki woh kya store karta hai: (a) page table ka index, (b) ek page table entry (PTE).

Recall Solution 1.2

KYA/KYUN: Parent ka rule "position is the key, entry is the value" yeh decide karta hai.

  • (a) Index khud VPN hai (ya us level ka VPN ka slice) — yeh position se implied hota hai, yeh khud kuch store nahi karta.
  • (b) PTE store karta hai PFN + flags (valid, read/write, user/supervisor, dirty, accessed). Answer: index ↔ virtual page number (positional); PTE ↔ physical frame number + flags.

L2 — Application

Problem 2.1

, . Virtual address 0x00003FFF ke liye offset aur VPN compute karo.

Recall Solution 2.1

KYA: address ko bit par split karo — exactly shared picture (figure s01) mein green/coloured boundary. KYUN offset pehle: low bits offset hain (green block); unhe mask karne par VPN bachta hai (blue+yellow blocks). Bit Manipulation and Masking dekho. Symbol list se yaad karo ki remainder rakhta hai aur whole-number quotient rakhta hai: 0x00003FFF = 0x3 * 0x1000 + 0xFFF, toh offset (remainder). Yahan (right mein 12 shift, symbol list se) 12 offset bits right end se hata deta hai — exactly wahi undo jab address se banaya gaya tha. Answer: offset , VPN .

Problem 2.2

Same system. Do-level split 10 / 10 / 12 ( = top 10 bits, = next 10, offset = 12). Virtual address 0x00801234 ke liye , , offset nikalo. Agar L2[i2].PFN = 0x000AB hai, toh final physical address do.

Recall Solution 2.2

KYA: address ko teen fields mein kato — literally shared picture (figure s01) ke blue , yellow , green offset blocks — phir physical address reassemble karo. Address ko binary mein likho. 0x00801234: Offset = low 12 bits = 0001 0010 0011 0100... last 12 lo: 0010 0011 0100 . KYUN: , toh 12 low bits bina badlaav ke through jaate hain. Baaki top 20 bits hain 0000 0000 1000 0000 0001 . Un 20 bits ko (top 10) aur (next 10) mein split karo:

  • top 10: 0000 0000 10 , toh .
  • next 10: 00 0000 0001 , toh . Final PA: deliver kiye gaye PFN ko bina chhue offset ke saath glue karo: Answer: , , offset , PA .
Figure — Page tables and multi-level paging

L3 — Analysis

Problem 3.1

, ke liye, flat table 4 MiB use karta hai (4-byte PTEs ke saath). Explain karo kyun 10/10/12 two-level split har table ko exactly ek page banata hai — aur arithmetic dikhao.

Recall Solution 3.1

KYA: entries per table count karo aur PTE size se multiply karo. Har 10-bit index entries mein se ek select karta hai. 4-byte PTEs ke saath: KYUN yeh elegant hai: ek table jo exactly ek page hai, khud wahi machinery use karke page, allocate, aur swap ho sakta hai jo woh describe karta hai — koi special "bada region" nahi chahiye. 10/10/12 numbers isliye choose kiye gaye hain taaki ho. Answer: har level ki table ek page.

Problem 3.2

Ek process exactly ek code page aur ek stack page use karta hai, address space mein door door. (a) flat, (b) two-level 10/10/12 ke liye total page-table memory compute karo. Batao yeh kyun alag hain.

Recall Solution 3.2

KYA: actually allocate hue tables ka sum karo. (a) Flat: table fixed-size hai chahe usage kuch bhi ho: (b) Two-level: tumhe hamesha ek top table chahiye (4 KiB). Code aur stack "door hain," toh woh alag top-level entries ke neeche aate hain ⇒ do inner tables (4 KiB har ek): KYUN alag hain: flat table saare pages ke liye slot pre-reserve karta hai chahe sab untouched hon. Concretely: top table mein slots hain; process sirf use karta hai, baaki unused top-level slots hain. Un slots mein se har ek entries wali ek inner table point karta, yaani woh page-entries ki jagah le leti jo flat table reserve karta hai par tree kabhi allocate nahi karta. Tree un unused top entries ko invalid mark karta hai, unke liye koi inner table allocate nahi karta (dekho Page Faults and Demand Paging ki "invalid" access par kya trigger hota hai). Answer: flat ; two-level .


L4 — Synthesis

Problem 4.1

Ek 64-bit machine aur four-level page table use karta hai jisme 48-bit usable virtual address hai (jaise x86-64), har level ek 9-bit index. Field widths verify karo ki add up hote hain, aur compute karo ki full walk mein kitne RAM accesses chahiye, phir actual target byte padhne ke liye total.

Recall Solution 4.1

KYA: check karo , phir accesses count karo. Offset bits: . Chaar index levels 9 bits each: KYUN 9-bit levels: — har table ek page hai (64-bit PTEs 8 bytes hote hain). Same "table = ek page" trick jaise L3 mein. Walk cost: har level ek memory read hai jo next-level pointer fetch karta hai, toh 4-level walk = 4 reads. Phir actual data byte ke liye ek aur read: Answer: widths sum to 48; walk = 4 reads; data tak pahunchne ke liye total = 5 reads.

Problem 4.2

Model use karke, maano cycle, walk cost memory reads 100 cycles/read cycles, aur TLB miss rate hai. Average translation time compute karo. Phir woh miss rate nikalo jo ise double kar de.

Recall Solution 4.2

Term note: yahan "walk cost" ka matlab sirf woh page-table reads hain jo frame dhundh lete hain — Problem 4.1 ke 4 translation accesses, final data fetch nahi. Data read ek alag cost hai jo translation ke baad hoti hai chahe kuch bhi ho, isliye yeh translation-time model mein nahi aati. (Agar kabhi include karo, kaho "translation + data" = 5 reads, jaise Problem 4.1 mein.) KYA: plug in karo, phir target ke liye invert karo. Double matlab target cycles. Miss rate ke liye solve karo: KYUN yeh matter karta hai: walk cost dominate karta hai jab miss rate non-tiny hoti hai, isliye TLB exist karta hai — Cache Memory Basics mein same "hit fast / miss slow" trade-off dekho. Answer: avg cycles; double karne ke liye miss rate () chahiye.


L5 — Mastery

Problem 5.1

Tum ek naye 32-bit CPU ke liye paging design kar rahe ho. Tum page size aur 1, 2, ya 3 levels choose kar sakte ho. Requirement: har table exactly ek page mein fit hona chahiye, PTEs 4 bytes hain. ke liye, ek page-table page mein kitni entries fit hongi, kitne index bits hote hain, aur kya ek clean 2-level design saare bits cover kar sakta hai? Split dikhao.

Recall Solution 5.1

KYA: per-page index width derive karo, phir levels ko mein fit karo. bytes ⇒ offset bits, VPN bits. Ek-page table mein entries: entries, yaani 12-bit index per level. Kya 2 levels 18 VPN bits cover kar sakte hain? Do 12-bit indices bits ki indexing capacity dete hain — hamare zaroorat ke se zyada, toh haan, aaram se. Ek clean split ek pura 12-bit level aur ek chhota top level use karta hai: KYUN top level sirf 6 bits ka hai: top table tab apne 4096 possible slots mein se sirf use karta hai — ise pura hona zaruri nahi; unused high slots simply invalid mark ho jaate hain. Yeh legal hai kyunki indexing capacity () VPN width (). Answer: ⇒ 4096 entries/page = 12-bit index; 2 levels (12+12=24 ≥ 18) kafi hain; split .

Problem 5.2

Defend ya refute karo: "Is same 32-bit, machine ke liye, ek single-level flat table ab bilkul theek hai — koi tree ki zarurat nahi." Ek size calculation aur ek design caveat se support karo.

Recall Solution 5.2

KYA: flat table ko size karo, phir judge karo. Flat table entries . 4-byte PTEs ke saath: Verdict — thoda defensible: 1 MiB 4 KiB-page case ke 4 MiB se kaafi chhota hai, kyunki bade pages matlab track karne ke liye kam pages hain ( 20 se 18 gira, aur har page 4× zyada memory cover karta hai). Kam processes wali machine ke liye, 1 MiB flat acceptable ho sakta hai. Caveat (kyun hum phir bhi tree prefer karte hain): flat 1 MiB poora allocate hota hai chahe process sirf do pages touch kare; tree ko sirf top table used inner tables chahiye hoti. Aur 16 KiB pages internal fragmentation se memory waste karte hain (ek 1-byte allocation bhi ek poora 16 KiB frame jalata hai). Trade-off yahan space-vs-space hai, usual space-vs-time nahi. Answer: flat table ; kam process counts ke liye defensible hai lekin tree sparse usage par phir bhi jeet jaata hai; 16 KiB pages internal fragmentation badhate hain.


Recall Self-quiz ke liye one-line summaries

Page size se offset bits ::: . Flat 32-bit / 4 KiB table size ::: . Two-level, 1 code + 1 stack page ::: (top + 2 inner tables). x86-64 4-level walk memory reads (miss) ::: translate karne ke liye 4, data read including 5. Tree kya kharidta hai vs TLB kya kharidta hai ::: tree space kharidta hai, TLB time kharidta hai.


Parent: Page tables and multi-level paging · See also Address Space Layout, Virtual Memory, TLB and Translation Caching.