Virtual Memory and Caching
Lesson, slides, and applied problem sets.
View SlidesLesson
Virtual Memory and Caching
Why this module exists
Virtual memory is not just page tables. It is a set of caches and copying rules that make the system fast and safe: TLBs, copy-on-write, and page sharing.
1) TLBs
The Translation Lookaside Buffer (TLB) caches recent page table translations. It reduces translation cost but introduces new invariants:
- TLB entries must be invalidated on page table changes.
- Replacement policy matters under heavy locality shifts.
2) Copy-on-write (COW)
Fork would be too expensive if it copied the entire address space. COW avoids that:
- parent and child share pages marked read-only
- on first write, the page is copied
COW correctness depends on precise reference counting and fault handling.
What you will build
- A TLB simulator with LRU replacement
- A copy-on-write reference count simulator
Key takeaways
- TLBs are a cache, so eviction policy matters.
- COW trades memory for deferred work on writes.
- Small bookkeeping bugs cause silent data corruption.