5.4.13 · D1 · HinglishMemory Hierarchy & Caches

FoundationsPage tables and multi-level paging

2,280 words10 min read↑ Read in English

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

Pehle aapko parent note Page Tables and Multi-Level Paging padne se pehle har symbol ka malik banana hoga. Yeh page har ek ko ground up se build karta hai: plain words → picture → topic ko iske zaroorat kyun hai. Upar se neeche padho; har idea uske upar waale pe lean karta hai.


1. "Bit" aur "power of two" — sab kuch ka alphabet

switches ek row mein lagao aur har switch independently flip ho sakta hai. Toh distinct patterns ki sankhya ( baar) hai:

Picture: socho ek car odometer, lekin har wheel pe sirf do symbols hain () das ki jagah. 3 wheels se tum dikha sakte ho — yani distinct readings.

Figure — Page tables and multi-level paging

Topic ko iske zaroorat kyun hai: paging mein har "size" — kitne pages, page kitna bada, table entries kitni — power of two hai, kyunki woh kuch address bits se count hoti hai.


2. Bytes aur addresses — har locker ko ek number dena

Picture: identical mailboxes ki ek hallway, har ek pe ek chhoti number plate. Plate address hai; andar jo letter hai woh byte hai.

  • bytes = 4 GiB addressable space.
  • ⇒ ek astronomically bada space (isliye flat tables mar jaate hain).

Topic ko iske zaroorat kyun hai: paging ka poora kaam ek address ko doosre mein badalna hai. batata hai "from" world kitna bada hai.


3. Virtual vs physical — fake number aur real number

Picture: do hallways side by side. Baayaan (virtual) woh hai jo program dekhta hai — clean, complete, sab uska apna. Daayaan (physical) real, shared, aadha-bhara building hai. Arrows left boxes se scattered right boxes ki taraf jaate hain.

Figure — Page tables and multi-level paging

Topic ko iske zaroorat kyun hai: iske bina, do programs dono "locker 5" chahenge toh clash hoga. Virtual addresses har program ko pretend karne dete hain ki woh sab kuch own karta hai, jabki physical reality shared aur safe rehti hai. Badi kahani ke liye Virtual Memory aur Address Space Layout dekho.


4. Pages aur frames — dono hallways ko equal blocks mein kaatna

Picture: figure s02 se dono hallways lo aur har boxes ke baad thick dividers draw karo. Har virtual block (page) ek physical block (frame) se map hota hai. Kyunki blocks same size hain, ek virtual page kisi bhi free frame mein ja sakta hai — jaise same-size bricks kisi bhi same-size slot mein fit hoti hain.

Topic ko iske zaroorat kyun hai: fixed equal-size blocks external fragmentation khatam karte hain aur address ke low bits ko untouchable banate hain — yeh do pillars hain jinpe baaki sab khada hai.


5. Address ko kaatna: page number | offset

Ab Section 4 ke dividers use karke ek single address ko do fields mein kaato.

Yeh do operations kyun?

  • (integer divide, remainder drop karo) jawaab deta hai "is address ke neeche ke kitne whole blocks fit hote hain?" — woh hi block number hai.
  • (bacha hua) jawaab deta hai "current block mein hum kitna andar hain?" — woh hi offset hai.

Picture: ek odometer jahan ek vertical line wheels ko split karti hai. Line ke baayein wheels = page number; daayein = offset. Offset wheels ghoomne se page-number wheels tab tak nahi hilte jab tak woh ke aage roll over nahi ho jaate.

Figure — Page tables and multi-level paging

Topic ko iske zaroorat kyun hai: translation sirf page number rewrite karta hai; offset verbatim copy hota hai. Yeh split hi poora engine hai.


6. Bit operations: masking &, shifting << >>, aur |

Upar ke formulas , , aur use karte hain jo computer pe real division se saste hain. Kyunki power of two hai, "divide" aur "remainder" pure bit surgery hai. (Poori detail Bit Manipulation and Masking mein.)

Topic ko iske zaroorat kyun hai: parent aur har jagah likhta hai. Yeh do tareekon se boli gayi same baat hai — powers of two division ko shifting bana deti hain.


7. Lookup table, entry, aur uske flags

Picture: ek spreadsheet. Row number = VPN (tum ise store nahi karte — yeh bas wahan hai jahan row baithti hai). Cell contents = PFN + flags. Index andar, value bahar.

Topic ko iske zaroorat kyun hai: "array position key hai, entry value hai" parent ki ek steel-manned galti hai. Agar tum table ko VPN se indexed nahi dekhte, toh multi-level walk ka kuch bhi samajh nahi aata.


8. "Level" aur base register — ek table tree kyun banta hai

rows wala ek single flat table ek real program ke liye mostly empty hota hai. Toh hum stages mein index karte hain: VPN ko khud slices mein kaato, aur har slice ko ek chhote tables ke tree ka ek level neeche jaane ke liye use karo.

Picture: ek table of contents (top table) chapters (inner tables) point karta hai, jo pages (frames) point karte hain. Tum sirf woh chapters print karte ho jo koi actually padh raha hai. Har level ek real RAM read maangta hai — yahi woh jagah hai jahan TLB baad mein apna kaam karta hai, bilkul waise jaise ek plain cache slow memory ko rescue karta hai.


Sab kuch topic se kaise connect hota hai

bits and 2 to the n

byte and address width V

virtual vs physical

page size P and log base 2

split address into page number and offset

shift and mask and OR

page table indexed by VPN gives PFN plus flags

multi level tree of tables and base register

Page tables and multi-level paging


Equipment checklist

kya count karta hai?
bits se distinct patterns (jinhe naam de sako) ki sankhya.
kya jawaab deta hai?
cheezein naam lene ke liye kitne bits chahiye.
Ek sentence mein address kya hai?
Memory mein byte-sized locker pe likha number.
-bit address ki space kitni badi hoti hai?
bytes.
Virtual vs physical address?
Virtual woh fake number hai jo program use karta hai; physical real RAM location hai; hardware ek ko doosre mein translate karta hai.
Page kisi bhi free frame mein kyun ja sakta hai?
Pages aur frames same fixed size ke hain, isliye koi bhi page kisi bhi frame slot mein fit hota hai.
Page size diya ho, kaun se bits offset hain?
Low bits.
Bit ops se offset kaise extract karein?
Address ko ones ke mask se AND karo: .
kya karta hai aur ise kyun use karte hain?
bits left shift karo = se multiply; frame number ko offset ke upar wapas rakhne ke liye use hota hai.
Page table ko kya index karta hai, aur PTE mein kya hota hai?
VPN index hai (position); PTE mein PFN plus flag bits hote hain.
Teen PTE flags bolo.
valid, read/write, user/supervisor (dirty aur accessed bhi).
Multi-level paging mein "level" kya hai?
Ek stage jo VPN bits ka ek slice use karke ek row pick karta hai jo agli table point kare.
CR3 (base register) mein kya hota hai?
Top-level page table ka physical address.

Jab upar ki har line obvious lagey, toh parent note padho — ya Hinglish version.