5.4.11 · D1 · HinglishMemory Hierarchy & Caches

FoundationsVirtual memory and paging

1,752 words8 min read↑ Read in English

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

Yeh page assume karta hai ki aapne koi bhi notation pehle nahi dekha. Hum bits, addresses, powers of two, mod/shift operators, hex, aur split-and-combine machinery ko ek ek brick karke define karenge. Koi cheez use nahi hogi jab tak use draw na kar liya jaye.


0. Ek bit aur ek byte — atoms

Yeh topic ko kyun chahiye. Memory kuch nahi hai siwaay ek behad badi row of bytes ke. Har "address" jo hum translate karte hain woh simply un bytes ko count karne ka ek tarika hai. Agar aap bulbs ki row imagine nahi kar sakte, toh "address", "offset", aur "page" jaise words ki koi base nahi hogi.

Kyunki ek byte mein 8 switches hain, yeh alag alag patterns dikha sakta hai (sab-off se sab-on tak). Woh "" hamaari pehli power of two hai — isko theek se agle section mein milte hain.


1. Powers of two — hardware ka counting ruler

bits patterns kya naam deta hai
on / off
ek KiB (kibi)
ek 4 KiB page
ek million
ek 4 GiB address space

Yeh topic ko kyun chahiye. Paging mein har cheez ek power of two hai — page size , number of pages , address space . Powers of two isliye choose ki jaati hain kyunki yeh bits ke saath perfectly line up karti hain: low bits kaatna se divide karne ke barabar hai. Yeh baat yaad rakho — yeh poora translation trick bann jaata hai.


2. Ek address — ek byte ka ghar ka number

Agar addresses bits wide hain, toh sabse door wala reachable ghar hai, isliye street mein exactly bytes hain. Woh number ko address space kehte hain.

Yeh topic ko kyun chahiye. Poora subject ek machine hai: VA ko PA mein badlo. Do streets, unke beech ek secret map. Baad mein har symbol sirf us map ko describe karne ke liye exist karta hai.


3. Hexadecimal — bits ko bina sir chakraye likhna

Yeh topic ko kyun chahiye. Parent ka worked example likhta hai. Kyunki ek hex digit = 4 bits aur ek 4 KiB page low 12 bits use karta hai 3 hex digits, offset simply "aakhri teen hex digits" hai — aap split aankhon se padh sakte hain. Yeh sirf isliye kaam karta hai kyunki hex bits ko fours mein group karta hai.


4. Offset operators — mod aur shift

Ab hum un do symbols ko earn karte hain jo parent bina ceremony ke use karta hai: aur .

Yeh topic ko kyun chahiye. Yeh do operators hain hi address split. Inhe master karo aur lines jaise magic lagna band ho jaata hai aur "bottom bits rakho / top bits rakho" ban jaata hai.


5. Wapas build karna — shift-left << aur OR |

Yeh topic ko kyun chahiye. Physical address rebuild karne ke liye parent likhta hai . Shift-left gap kholti hai; OR untouched offset ko us mein daal deta hai. Yeh step 4 ka exact reverse hai — alag split karo, phir snap together karo.


6. Page, frame, aur unke beech ka map

Kyunki pages aur frames same size ke hain, ek page ko frame mein move karna ek rigid shift hai: page ka byte 5 frame ka byte 5 ban jaata hai. Isliye exactly offset unchanged copy hota hai aur sirf page/frame number translate hota hai.

Yeh topic ko kyun chahiye. Yeh har pehle brick ki destination hai: bits → address → split → table mein VPN lookup karo → PFN lo → rebuild karo. Agar memory bytes ki row hai aur locality wajah hai kyun cache/replacement machinery kaam aati hai, yeh map dil hai.


Prerequisite map

bit and byte

power of two 2^k

address = byte number

virtual vs physical address

hexadecimal digit = 4 bits

mod and right shift

split into VPN and offset

left shift and OR

rebuild physical address

page and frame same size

Virtual memory and paging 5.4.11


Equipment checklist

Right side cover karo aur parent note par jaane se pehle zor se jawab do.

bits mein kitne patterns ho sakte hain, aur kyun?
, kyunki switches mein se har ek count ko double karta hai.
Ek byte mein kitne bits hain, aur yeh kitni values dikhata hai?
8 bits, values.
Ek hex digit kitne bits ke barabar hai?
Exactly 4 bits.
ko decimal mein likho.
.
kya rakhta hai?
ke low bits (remainder).
kya rakhta hai?
High bits — uske low bits hataane ke baad ().
numerically kya karta hai?
ko se multiply karta hai (neeche ek -bit zero gap kholta hai).
do numbers ko simply kab glue karta hai?
Jab unke -bits kabhi overlap na karein.
Sirf page number kyun translate hota hai, offset kyun nahi?
Ek page aur uska frame same size ke hain, isliye yeh ek rigid shift hai — byte ki andar ki position fixed rehti hai.
4 KiB page ke liye (), offset kitne hex digits ka hoga?
3 (kyunki ).