7.6Virtual memory
The idea
Virtual memory gives each program its own big address space; a page table translates virtual pages to physical frames, and a TLB caches those translations.
Think of it like this: A hotel front desk: you ask for "room 5" and they look up which actual room it is; a small notepad (TLB) remembers recent lookups.
Why it exists
Programs can be larger than RAM, are isolated from each other, and need no fixed placement.
How it works
- Virtual address = page number + offset.
- The TLB checks for a quick translation.
- On a TLB miss, read the page table in memory (extra access).
- If the page is not in RAM: page fault, the OS loads it from disk.
Worked example: Single-level table
TLB hit: t + m. TLB miss: t + 2m. Page fault: millions of times slower.
Now play with it
- →Flip through TLB hit, TLB miss and Page fault and watch where the time goes.
Total 32 bits. Click a field for details.
- CPU issues a virtual address
- TLB lookup: hit, frame number found (cost t)
- Physical address = frame 9 + offset
- One memory access to fetch the data: total t + m
Check yourself
With a single-level page table, a TLB miss costs how many extra memory accesses?
Exam notes (the dense version)
Pages of virtual space map to frames. Page table in memory; TLB caches recent translations. Page fault → OS loads page from disk.
Previous year questions: Memory Hierarchy & Main Memory (16)
PYQs are grouped by topic, so this is the full set for Memory Hierarchy & Main Memory; try the ones that match this subtopic. Open all 16 on the topic page.