Virtual memory — concept, page table, virtual-to-physical translation
WHY does virtual memory exist?
Three concrete problems it solves:
- Isolation / protection — Process A must not be able to read or smash Process B's memory. If both used raw physical addresses, address
0x4000would mean the same byte for both → chaos. - Relocation / fragmentation — A program shouldn't care where in RAM it lands. We want to load it into any free chunks, even non-contiguous ones.
- Over-commitment — We want to run programs needing more memory than physically exists, by parking unused parts on disk (swap).
WHAT are the key objects?
HOW does an address get split?
The genius trick: the offset within a page is identical in virtual and physical space, because pages and frames are the same size and aligned. Only the page number part needs translating.
Derivation that the offset is preserved. Let virtual address with . Translation replaces the page: . The same off appears, so we never translate offset bits. ∎

Forecast-then-Verify
Verify, step by step:
- Page size → offset = 12 bits. Why? You need exactly 12 bits to address every byte inside one 4096-byte page.
- VPN bits . Why? The remaining high bits identify the page.
- Entries . Why? One entry per possible virtual page.
- If each entry is 4 bytes → table size per process. Why this matters: this huge cost is exactly why real systems use multi-level page tables (only allocate sub-tables for pages actually used).
Worked translation examples
Common mistakes (Steel-manned)
Active recall
Recall Quick self-test (cover answers)
- Q: Which part of the address is NOT translated? A: the offset.
- Q: Page size → how many offset bits? A: bits.
- Q: What triggers a page fault? A: accessing a page whose valid bit is 0.
- Q: Why per-process page tables? A: isolation — same VA maps to different physical frames per process.
- Q: Final PA formula? A: .
Recall Feynman: explain to a 12-year-old
Imagine a huge hotel. Every guest is told "your room is Room 1" — they all think they're in Room 1. But the hotel has a secret notebook (the page table) that says "Guest Alice's Room 1 is really physical Room 305; Bob's Room 1 is really Room 712." When Alice asks for something on her "Room 1, shelf 7", the front desk looks up the notebook, sends her to the real room 305, and shelf 7 is still shelf 7 inside that room (the offset doesn't change). If the real stuff was put in the basement storage (disk), the desk runs to fetch it first (page fault) and updates the notebook. That way everyone feels like they own the whole hotel, nobody walks into anyone else's room, and the hotel can hold more "rooms" than it physically has by stashing extras in storage.
The 80/20 — what to truly internalize
- Offset bits ; it's never translated.
- .
- Page table is per process (isolation) and lives in RAM (→ TLB cache).
- Invalid entry → page fault → OS loads from disk → retry.
Connections
- Paging vs Segmentation
- TLB — Translation Lookaside Buffer
- Multi-level Page Tables
- Cache Memory and Locality
- Page Replacement Algorithms (LRU, FIFO, Clock)
- Context Switching and CR3 / Page-Table Base Register
- Memory Hierarchy
Virtual memory gives each process the illusion of
The unit of the virtual address space is called a
The unit of physical RAM it maps to is called a
A page table maps
The hardware that performs translation on every access is the
For page size 2^p, the number of offset bits is
The part of a virtual address that is NOT translated is
Final physical address formula
Number of entries in a single-level page table for V-bit VA and 2^p pages
A page fault is triggered when
After servicing a page fault the OS does what to the faulting instruction
Why are page tables per-process
Big-page trade-off: fewer entries but
The cache that speeds up VPN→PFN lookups is the
32-bit VA, 4 KiB pages → offset bits / VPN bits / #entries
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, virtual memory ka basic funda ye hai ki har program ko ek jhoothi (illusion) duniya di jaati hai — har process sochta hai ki uske paas poori badi memory hai jo 0 se start hoti hai aur ek dum continuous hai. Asli RAM me uska data chote-chote tukdo (pages/frames) me bikhra padta hai, ya kabhi disk pe bhi hota hai. Is jhooth ko sach me badalne ke liye ek "dictionary" hoti hai jise page table kehte hain, jo har process ke liye alag hoti hai (isi se isolation milta hai — Process A, Process B ki memory ko touch nahi kar sakta).
Address ko samajhna simple hai: virtual address ko do part me kaat do — upar wala part VPN (virtual page number) aur neeche wala part offset. Agar page size bytes hai, to neeche ke bits offset hote hain. Sabse important baat: offset translate NAHI hota — kyunki page aur frame same size ke hote hain, to page ke andar position waisi ki waisi rehti hai. Sirf VPN ko page table me dekh kar PFN (physical frame number) nikaalte hain. Phir final physical address banta hai: (hardware me ye bas concatenation hai).
Agar page table ki entry "valid = 0" bole, matlab data RAM me nahi hai — tab page fault hota hai. OS disk se page laata hai, ek free frame me daalta hai, table update karta hai, aur instruction ko dobara chalata hai. Yahi mechanism allow karta hai ki tum apni physical RAM se bhi zyada memory use kar sako.
Exam aur real coding dono me ye kaam aata hai: jab tum dekhte ho "32-bit VA, 4KB pages", to seedha bolo — offset = 12 bits, VPN = 20 bits, entries = . Mnemonic yaad rakho: "VPN Picks the Frame, Offset Stays the Same." Bas yahi 80/20 hai — baaki TLB, multi-level page tables wagairah isi base pe khade hote hain.