RAM kaafi nahi. Programs ko physical RAM se zyada memory ki zaroorat pad sakti hai. Virtual memory humein pretend karne deta hai ki RAM disk jaisi badi hai — inactive pages ko disk par swap karke.
Multiple programs, ek RAM. Agar program A ne directly physical address 0x4000 use kiya aur program B bhi 0x4000 chahta, toh woh collide karte. Virtual memory har process ko uska apna address space deta hai — isolation & protection.
Fragmentation. Programs ko contiguous chunks chahiye; RAM time ke saath gaps mein cut ho jaati hai. Paging "physical RAM mein contiguous hona zaroori hai" wali constraint hata deta hai.
Maano page size P=2p bytes hai. n bits ka ek virtual address do parts mein split hota hai.
Split kyun? Kyunki ek single page ke andar, virtual aur physical addresses bilkul same hote hain — ek page ko frame mein move karne se internal layout identical rehta hai. Sirf kaunsa page/frame hai yeh alag hota hai. Isliye:
Low p bits = page ke andar offset. Yeh kabhi translate nahi hote.
High n−p bits = Virtual Page Number (VPN). Sirf yahi map hota hai.
VA=n−p bitsVPN∥p bitsoffset
Split ko arithmetically derive karna. Ek virtual address A ke liye:
offset=Amod2p=A&(2p−1),VPN=⌊2pA⌋=A≫p
Mask/shift kyun?2p se divide karne par low p bits chhoot jaate hain (page number milta hai); remainder exactly wahi hai jo page ke andar bacha hai.
PFN ko 2p se multiply kyun karte hain? Kyunki frame number f physical byte f⋅P se shuru hota hai. Exact byte par pahunchne ke liye untouched offset add karo.
Effective access time (derive karo). Maano tTLB = TLB lookup time, tmem = memory access, hit ratio h. Hit par hum TLB + memory pay karte hain. Miss par hum TLB + page-table walk (ek memory access, single-level) + real memory access pay karte hain:
EAT=h(tTLB+tmem)+(1−h)(tTLB+tmem+tmem)=tTLB+tmem+(1−h)tmem
Last term kyun? Miss penalty exactly ek extra tmem hai table walk ke liye, miss probability (1−h) se weighted.
Ek virtual address kin do parts mein split hoti hai, aur kaunsa part translate hota hai? ⟶ VPN (translated) + offset (untranslated).
Single-level page table mein entries ki sankhya ka formula? ⟶ 2n−p.
TLB kya hai aur yeh kaam kyun karta hai? ⟶ Recent translations ka cache; locality ki wajah se kaam karta hai.
Kya page fault ek error hai? ⟶ Nahi — normal event; page disk par hai / lazily allocated hai.
Fixed-size pages kyun? ⟶ Koi bhi page kisi bhi frame mein fit hota hai ⇒ external fragmentation nahi + simple arithmetic translation.
Recall Feynman: ek 12-saal ke bacche ko explain karo
Socho tumhari book mein page numbers 1, 2, 3... hain (yahi tum dekhte ho). Lekin librarian actually un pages ko backroom mein random shelves par rakhta hai. Tum hamesha "page 5" maangoge; librarian secretly ek choti notebook dekhta hai jisme likha hai "page 5 shelf 200 par hai" aur use le aata hai. Tum kabhi shelves nahi dekhte — tum bas ek saaf book enjoy karte ho. Woh "choti notebook" page table hai, "shelf number" physical frame hai, aur agar ek page deep storage (disk) mein hai, toh librarian use laane daudta hai — woh choti wait page fault hai. Har bacche ko unki apni notebook milti hai, isliye bacche A ka "page 5" aur bacche B ka "page 5" bilkul alag shelves hain.
Ek trap jo tab raise hota hai jab referenced page abhi RAM mein nahi hai; OS use disk se load karta hai aur resume karta hai — normal event hai, crash nahi.
TLB kya hai aur yeh fast kyun hai?
Recent VPN→PFN translations ka ek chota associative cache; locality ki wajah se effective hai, >99% hit rates deta hai isliye translation almost free hai.
Hit ratio h ke saath effective access time (single-level table)?
EAT=tTLB+tmem+(1−h)tmem.
Variable regions ki jagah fixed-size pages kyun?
Koi bhi page kisi bhi frame mein fit hota hai ⇒ external fragmentation nahi, aur translation shift+lookup+add tak reduce ho jaata hai.
Bahut bade pages ka downside kya hai?
Internal fragmentation (waste hua RAM) aur fault par heavier per-fault disk I/O.
Process A ka VA 0x4000 process B ke saath clash kyun nahi karta?
Har process ka apna page table hota hai, isliye identical VAs alag physical frames mein map hoti hain (isolation).