Virtual Memory
Virtual memory applies the same hierarchy idea one level down: main memory acts as a cache for the disk. It lets each program believe it has a huge private address space, while the OS maps it onto whatever physical RAM is actually free.
1. Why virtual memory
- Bigger-than-RAM programs — inactive parts live on disk, pulled in on demand.
- Isolation & protection — each process has its own address space; it can't read another's memory.
- Relocation — a program's virtual addresses can map to any physical frames, so it doesn't care where it's loaded.
2. Pages, frames & the address split
The virtual address space is divided into fixed-size pages; physical memory into equal-size frames. A virtual address splits into a virtual page number (VPN) and a page offset:
Formulas. page offset bits = · VPN bits = · number of virtual pages = .
The page offset is unchanged by translation — only the page number is mapped.
The page offset is unchanged by translation — only the page number is mapped.
3. The page table translates VPN → frame
The page table has one entry (PTE) per virtual page. Indexing it with the VPN gives the physical frame number (plus a valid bit). Concatenating that frame number with the untouched offset yields the physical address.
Virtual address
VPN + page offset
Index the page table with the VPN
page table base + VPN × entry size
Valid bit = 1?
if 0 → PAGE FAULT: OS fetches the page from disk
Physical address = frame number ∥ page offset
4. Vocabulary map: cache ↔ virtual memory
| Cache term | Virtual-memory term |
|---|---|
| Block / line | Page |
| Cache miss | Page fault |
| Miss penalty | Disk access (millions of cycles) |
| Tag + index lookup | Page-table lookup (VPN → frame) |
Because page faults are so costly, virtual memory favours large pages, fully-associative placement (any page in any frame), and clever replacement — the opposite balance from a small fast cache. A TLB (a tiny cache of recent translations) hides the page-table lookup cost.
Section checklist
- Main memory caches the disk; pages ↔ frames.
- Split a virtual address: offset = log₂(page size), VPN = the rest.
- Page table maps VPN → frame; a missing page = page fault.