Not enough RAM. Programs may need more memory than the physical RAM installed. Virtual memory lets us pretend RAM is as big as the disk by swapping inactive pages to disk.
Multiple programs, one RAM. If program A used physical address 0x4000 directly and program B also wanted 0x4000, they'd collide. Virtual memory gives each process its own address space — isolation & protection.
Fragmentation. Programs need contiguous chunks; RAM gets chopped into gaps over time. Paging removes the "must be contiguous in physical RAM" constraint.
Let page size be P=2p bytes. A virtual address of n bits splits into two parts.
Why split? Because within a single page, virtual and physical addresses agree exactly — moving a page to a frame keeps the internal layout identical. Only which page/frame differs. So:
The low p bits = the offset inside the page. These are never translated.
The high n−p bits = the Virtual Page Number (VPN). Only this gets mapped.
VA=n−p bitsVPN∥p bitsoffset
Deriving the split arithmetically. For a virtual address A:
offset=Amod2p=A&(2p−1),VPN=⌊2pA⌋=A≫p
Why the mask/shift? Dividing by 2p throws away the low p bits (giving the page number); the remainder is exactly what's left inside the page.
Then look up the frame:PFN=PageTable[VPN]PA=(PFN×2p)+offset=(PFN≪p)∣offset
Why multiply PFN by 2p? Because frame number f starts at physical byte f⋅P. Add the untouched offset to land on the exact byte.
Effective access time (derive it). Let tTLB = TLB lookup time, tmem = memory access, hit ratio h. On a hit we pay TLB + memory. On a miss we pay TLB + page-table walk (one memory access, single-level) + the real memory access:
EAT=h(tTLB+tmem)+(1−h)(tTLB+tmem+tmem)=tTLB+tmem+(1−h)tmem
Why the last term? The miss penalty is exactly one extra tmem for the table walk, weighted by miss probability (1−h).
What two parts does a virtual address split into, and which one is translated? ⟶ VPN (translated) + offset (untranslated).
Formula for number of entries in a single-level page table? ⟶ 2n−p.
What is a TLB and why does it work? ⟶ Cache of recent translations; works because of locality.
Is a page fault an error? ⟶ No — normal event; page is on disk / lazily allocated.
Why fixed-size pages? ⟶ Any page fits any frame ⇒ no external fragmentation + simple arithmetic translation.
Recall Feynman: explain to a 12-year-old
Imagine your book has page numbers 1, 2, 3... (that's what you see). But the librarian actually stores those pages in random shelves in the back room. You always ask for "page 5"; the librarian secretly looks at a little notebook that says "page 5 is on shelf 200" and fetches it. You never see the shelves — you just enjoy a neat book. The "little notebook" is the page table, "shelf number" is the physical frame, and if a page is in deep storage (disk), the librarian runs to get it — that little wait is a page fault. Every kid gets their own notebook, so kid A's "page 5" and kid B's "page 5" are totally different shelves.
Dekho, virtual memory ka core idea ye hai: har program ko lagta hai ki uske paas ek badi, private memory hai jo address 0 se shuru hoti hai. Lekin asal mein RAM chhoti hoti hai aur usme kayi programs share karte hain. Isliye CPU ke andar MMU chupke se program ke "virtual address" ko "physical address" (asli RAM location) mein translate karta hai. Ye translation page-by-page hoti hai — page ek fixed-size chunk hota hai (aam taur par 4 KiB).
Address ko do hisson mein tod dete hain: upar wale bits = VPN (virtual page number), aur neeche wale p bits = offset. Yaad rakho — VPN translate hota hai, offset waisa ka waisa rehta hai. Kyun? Kyunki page ko frame mein daalna sirf ek shift hai; page ke andar ka layout same rehta hai. Page table ek notebook ki tarah hai jo bolta hai "VPN 0x1A ka frame 0x7 hai". Physical address banane ke liye: frame number ko p se left shift karo, phir offset OR kar do.
Agar page abhi RAM mein nahi hai (disk pe hai), to page fault hota hai — ye koi error/crash nahi hai, ye bilkul normal cheez hai. OS us page ko disk se laata hai aur instruction dobara chala deta hai. Har process ka apna page table hota hai, isliye process A ka 0x4000 aur process B ka 0x4000 alag-alag RAM location pe jaate hain — yahi isolation hai.
Har baar page table ko memory se padhna slow hoga, isliye TLB naam ka chhota cache hota hai jo recent translations yaad rakhta hai. Locality ki wajah se TLB ka hit rate 99%+ hota hai, to translation almost free ho jaati hai. Exam ke liye ye formulas pakad lo: entries =2n−p, aur EAT =tTLB+tmem+(1−h)tmem. Bas itna samajh liya to virtual memory clear hai.