CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture Lecture 11 - Virtual Memory and Caches

Chris Fletcher
UC Berkeley, Spring 2026

Modern Virtual Memory Systems

Illusion of a large, private, uniform store

Address Translation: Putting It All Together

Virtual address TLB lookuphardware Protection checkhardware hit Physical address → cache Protection fault (SEGFAULT)software permitted denied Page table walkhardware or software miss Update TLB in memory retry Page fault: OS loads pagesoftware ∉ memory

Page-Fault Handler

  1. Find the missing page on disk (or create a fresh zero-filled page)
  2. No free frame? Pick a victim to swap out
    • Often pseudo-LRU in software; OS may keep a free-page pool in the background
  3. Read the page from disk, update the page table

VM Exceptions in the Pipeline

Check Your Understanding

1. Why are TLB misses sometimes handled in hardware but page faults always in software?
A TLB miss walks tables in DRAM (tens of ns), fast in hardware without a flush. A page fault reads disk (ms, millions of cycles): software overhead is negligible and the OS can switch jobs.
2. Why must a page fault be restartable?
The faulting instruction hasn't accessed its data; after the OS loads the page and updates the table, it must re-execute from the start.

Virtual-Address Caches (VIVT)

CPU →VA Virtual cache →VA TLB →PA Memory   (e.g., StrongARM)

Concurrent TLB and Cache Access (VIPT)

VPN page offset (k bits) Index L b TLB Physical tagData = PPN hit? data

VIPT Caches Larger than a Page

Example: AMD Zen 5 L1D

4 KB pages (k = 12), 64 B lines (b = 6), 48 KB cache, 4-cycle hit at ~5 GHz

  1. Lines: 48 KB / 64 B = 768
  2. Max alias-free index: $L = 12 - 6 = 6$ → 64 sets
  3. Associativity: 768 / 64 = cache / page = 48 KB / 4 KB = 12-way
Each way = 64 sets × 64 B = 4 KB (one page): the rule fixes the way size, not a power-of-2 way count. 12 lines spaced 4 KB apart hit in L1 (4 cycles); 14 spill to L2 (~14 cycles).

Anti-Aliasing Using an Inclusive L2

Check Your Understanding

1. VIPT with k = 12 and 32 B lines (b = 5). Largest alias-free direct-mapped cache? Minimum associativity for 64 KB?
4 KB (L = 7 → 128 sets × 32 B). 64 KB needs 64/4 = 16-way.
2. In the R10000 scheme, why does L2 store the a1 bits in its tag?
When VA2 misses L1 and hits PA in L2, L2 needs a1 to detect the index mismatch and find VA1's L1 set to purge it.

VM Features Track Historical Uses

EraMechanism
Bare machinePhysical addresses only; one program owns the machine
Batch multiprogrammingBase & bound: translation + protection, whole-program swapping; external fragmentation
Time sharingFixed-size pages (no external fragmentation) + demand paging (only working sets resident)
Virtual machine monitorsTwo levels: guest virtual → guest physical → host physical (1970s IBM; now clouds, laptops)

Virtual Memory Use Today

DomainVM supportWhy
Servers, desktops, laptops, phonesFull demand-paged VMPortability, isolation, sharing DRAM, simpler OS
Vector supercomputers, GPUsTranslation + protection, rarely demand pagingCan't waste compute thrashing to disk; restartable vector exceptions are hard
Embedded, DSPsPhysical addresses onlyNo area/power for TLBs; often no disk; fixed memory map; exposed pipelines

Older Crays used base & bound; Japanese supercomputers and Cray X1/X2 used pages.

Check Your Understanding

1. Why do GPUs and vector supercomputers implement translation and protection without full demand paging?
Jobs are sized to fit in memory so expensive compute doesn't sit idle thrashing to disk, and precise restartable exceptions for wide vector instructions are very hard.