CS61C: Great Ideas in Computer Architecture (aka Machine Structures)
Lecture 24: Virtual Memory
Instructor: Justin Yokota�Slide Credit: Lisa Yan
CS 61C
Summer 2026
Agenda
2
CS 61C
Summer 2026
Agenda
3
CS 61C
Summer 2026
How much memory is my computer using?
CS 61C
Summer 2026
Virtual Memory
CS 61C
Summer 2026
Virtual Memory
CS 61C
Summer 2026
Virtual Memory Saves Unused Pages
Program 1 Virtual Memory |
Stack Page |
Stack Page |
Unused |
… |
|
|
|
|
|
|
|
|
… |
Unused |
Heap Page |
Heap Page |
Data Page |
Code Page |
Code Page |
Physical Memory |
Stack Page |
Stack Page |
Data Page |
|
Heap Page |
Heap Page |
|
Code Page |
Code Page |
|
|
|
|
|
CS 61C
Summer 2026
Virtual Memory Protects Programs from Each Other
Banking Program |
Password Page |
… |
|
|
|
|
|
Physical Memory |
Banking Password Page |
|
|
|
|
|
|
|
|
|
|
|
Hacker Password Page |
|
Hacker Program |
Page in the same place as Password |
… |
|
|
|
|
|
CS 61C
Summer 2026
The Illusion of Virtual Address Space
Processes use virtual addresses.�Many processes, all using same (conflicting) addresses
Different processes run simultaneously
0xF…F
0x0…0
0xF…F
0x0…0
0xF…F
0x0…0
CS 61C
Summer 2026
The Translation to Virtual Address Space
Different processes run simultaneously
0x07FF FFFF
0x0000 0000
Translator/Memory Manager
Memory uses physical addresses.
CS 61C
Summer 2026
Address Sizes: The Hive Machines
CS 61C
Summer 2026
Virtual Addresses vs. Physical Addresses
CS 61C
Summer 2026
How is the Memory Hierarchy Managed?
CS 61C
Summer 2026
For Today: Assume Caches Don't Exist
Processor chip
DRAM chip –e.g. �DDR3/4/5�HBM/HBM2/3
SSD, HDD�Drives
(assume this doesn’t exist)
CS 61C
Summer 2026
Agenda
15
CS 61C
Summer 2026
Paged Memory
0xF…F
0x0…0
text
stack
heap
data
Page Number 0
Page Number 1
(paged) virtual address space
CS 61C
Summer 2026
Paged Memory
Virtual and physical pages are the same size. Same # bits to address offset within a page!
PPN (36 bits) | offset (12 bits) |
Virtual address (e.g. 32 bits)
Physical address (e.g. 48 bits)
VPN (20 bits) | offset (12 bits) |
CS 61C
Summer 2026
Address Translation
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
…
Program�(32b virtual address space)
Page Table
(Conceptual for now; design discussed later)
CS 61C
Summer 2026
Analogy: Return of the Librarian
CS 61C
Summer 2026
Address Translation Example 1
Assume each page is 4 KiB and we have 4 physical pages
Step 1: Program tries load data at 0xFFFF F004.
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | disk |
… | … |
0xFFFFF | 1 |
CS 61C
Summer 2026
Address Translation Example 1
Step 2: OS translates VA to the physical address (PA) in memory.
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | disk |
… | … |
0xFFFFF | 1 |
CS 61C
Summer 2026
Address Translation Example 1
Step 3: Page table lists VPN as corresponding to a physical page. Page hit.
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | disk |
… | … |
0xFFFFF | 1 |
CS 61C
Summer 2026
Address Translation Example 1
Step 4: Read data at the corresponding memory location, and return it to the program
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | disk |
… | … |
0xFFFFF | 1 |
0x43
CS 61C
Summer 2026
Address Translation Example 2
Assume each page is 4 KiB and we have 4 physical pages
Step 1: Program tries to malloc new location. C library translates this to an sbrk, which requests an extra page of memory from the OS
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Request malloc(10)�sbrk requests page at VPN 0x60000
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | disk |
… | … |
0xFFFFF | 1 |
CS 61C
Summer 2026
Address Translation Example 2
Step 2: OS finds empty physical page
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Request malloc(10)
sbrk requests page at VPN 0x60000
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | disk |
… | … |
0xFFFFF | disk |
CS 61C
Summer 2026
Address Translation Example 2
Step 3: OS updates Page Table, and returns the new location
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Request malloc(10)
sbrk requests page at VPN 0x60000
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | 1 |
… | … |
0xFFFFF | disk |
CS 61C
Summer 2026
Address Translation Example 3
Let's try accessing the address that was just sent to disk
Step 1: Program tries load data at 0xFFFF F004.
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | 1 |
… | … |
0xFFFFF | disk |
CS 61C
Summer 2026
Address Translation Example 3
Step 2: OS translates VA to the physical address (PA) in memory.
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | 1 |
… | … |
0xFFFFF | disk |
CS 61C
Summer 2026
Address Translation Example 3
Step 3: Page table doesn't have the PPN listed. Page Fault
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | 1 |
… | … |
0xFFFFF | 2 |
CS 61C
Summer 2026
Address Translation Example 3
Step 4: Read data at the corresponding memory location, and return it to the program
Physical Page 0 |
Physical Page 1 |
Physical Page 2 |
Physical Page 3 |
DRAM�(physical address space)
assume 4 x 4KiB pages
Load byte @ 0xFFFF F004 �to register t0
Program�(32b virtual address space)
Page Table
VPN | PPN |
0x40000 | disk |
0x60000 | 1 |
… | … |
0xFFFFF | 2 |
0x43
CS 61C
Summer 2026
Agenda
31
CS 61C
Summer 2026
Translation Example
What Physical Address does this Virtual Address translate to?
0x00003450
A. 0x00003450
B. 0x0000250
C. 0x00503450
D. 0x0F543450
E. 0x0F54450
F. Disk/Other
CS 61C
Summer 2026
Translation Example: Solution
What Physical Address does this Virtual Address translate to?
0x00003450
A. 0x00003450
B. 0x0000250
C. 0x00503450
D. 0x0F543450
E. 0x0F54450
F. Disk/Other
CS 61C
Summer 2026
Translation Example: Solution
What Physical Address does this Virtual Address translate to?
0x00003450
A. 0x00003450
B. 0x0000250
C. 0x00503450
D. 0x0F543450
E. 0x0F54450
F. Disk/Other
CS 61C
Summer 2026
Translation Example: Solution
What Physical Address does this Virtual Address translate to?
0x00003450
A. 0x00003450
B. 0x0000250
C. 0x00503450
D. 0x0F543450
E. 0x0F54450
F. Disk/Other
CS 61C
Summer 2026
Determining VPN/PPN size
| | A. | B. | C. | D. | E. | F. |
1. | Page offset | 14 | 15 | 16 | 19 | 20 | Other |
2. | VPN | 14 | 15 | 16 | 19 | 20 | Other |
3. | PPN | 14 | 15 | 16 | 19 | 20 | Other |
VPN | offset |
PPN | offset |
Virtual address
Physical address
CS 61C
Summer 2026
Determining VPN/PPN size
| | A. | B. | C. | D. | E. | F. |
1. | Page offset | 14 | 15 | 16 | 19 | 20 | Other |
2. | VPN | 14 | 15 | 16 | 19 | 20 | Other |
3. | PPN | 14 | 15 | 16 | 19 | 20 | Other |
VPN | offset |
PPN | offset |
Virtual address
Physical address
CS 61C
Summer 2026
Determining VPN/PPN size
| | A. | B. | C. | D. | E. | F. |
1. | Page offset | 14 | 15 | 16 | 19 | 20 | Other |
2. | VPN | 14 | 15 | 16 | 19 | 20 | Other |
3. | PPN | 14 | 15 | 16 | 19 | 20 | Other |
VPN | offset |
PPN | offset |
Virtual address
Physical address
CS 61C
Summer 2026
Determining VPN/PPN size
| | A. | B. | C. | D. | E. | F. |
1. | Page offset | 14 | 15 | 16 | 19 | 20 | Other |
2. | VPN | 14 | 15 | 16 | 19 | 20 | Other |
3. | PPN | 14 | 15 | 16 | 19 | 20 | Other |
VPN | offset |
PPN | offset |
Virtual address
Physical address
CS 61C
Summer 2026
Agenda
40
CS 61C
Summer 2026
What does a Page Table look like?
Page table
0x00000 | | | | | 0 |
| | | | | … |
0x06000 | | | | | 2 |
| | | | | … |
| | | | | disk |
| | | | | … |
0xFFFFF | | | | | 1 |
PPN
status bits
CS 61C
Summer 2026
What does a Page Table Entry look like?
Page table
0x00000 | | | | | 0 |
| | | | | … |
0x06000 | | | | | 2 |
| | | | | … |
| | | | | disk |
| | | | | … |
0xFFFFF | | | | | 1 |
PPN
status bits
CS 61C
Summer 2026
Valid Bit
CS 61C
Summer 2026
Dirty Bit
CS 61C
Summer 2026
Write Protection Bit
CS 61C
Summer 2026
Write Protection bit use case: Safe Memory Sharing
CS 61C
Summer 2026
How big is a page table?
We have a system with:
How much memory does our page table take? How many pages?
CS 61C
Summer 2026
How big is a page table?
We have a system with:
How much memory does our page table take?
How many pages?
CS 61C
Summer 2026
Page Tables are Stored in Memory
CS 61C
Summer 2026
4 MiB is still kind of big
CS 61C
Summer 2026
Multi-level page tables
CS 61C
Summer 2026
Multi-level page tables
L1 Page table
0x000 | | | | | 0 |
| | | | | … |
0x060 | | | | | 1 |
| | | | | … |
| | | | | NA |
| | | | | … |
0xFFF | | | | | 2 |
L2
status bits
L2 Page table
0x00 | | | | | 3 |
| | | | | … |
| | | | | … |
| | | | | … |
| | | | | disk |
| | | | | … |
| | | | | … |
PPN
status bits
L2 Page table
| | | | | 4 |
| | | | | … |
| | | | | … |
| | | | | … |
| | | | | disk |
| | | | | … |
0xFF | | | | | … |
PPN
status bits
L2 Page table
0x00 | | | | | … |
| | | | | … |
| | | | | … |
| | | | | … |
| | | | | disk |
| | | | | … |
0xFF | | | | | 5 |
PPN
status bits
CS 61C
Summer 2026
How big is each L1/L2 page table?
We have a system with:
How much memory does each L1/L2 page table take? How many pages?
CS 61C
Summer 2026
How big is a page table?
We have a system with:
How much memory does our page table take?
CS 61C
Summer 2026
The "Magic" Page Table
CS 61C
Summer 2026
Agenda
56
CS 61C
Summer 2026
Address Translation: Avoid Page Table Walks
VPN | offset |
PPN | offset |
Physical address
Virtual address
possible page table walk?
address translation
CS 61C
Summer 2026
The TLB Caches Address Lookups
VPN | PPN |
0x00004 | 0x60C25E6 |
0x00005 | 0x71DB139 |
0x00009 | 0x45099CD |
The TLB
VPN | PPN |
... | ... |
0x00004 | 0x60C25E6 |
0x00005 | 0x71DB139 |
0x00006 | 0xEC70DB7 |
0x00007 | 0xAB12BF4 |
0x00008 | 0x2158D55 |
0x00009 | 0x45099CD |
... | ... |
Process 1�Page Table
CS 61C
Summer 2026
TLB Details
VPN | PPN |
0x00004 | 0x60C25E6 |
0x00005 | 0x71DB139 |
0x00009 | 0x45099CD |
The TLB
VPN | PPN |
... | ... |
0x00004 | 0x60C25E6 |
0x00005 | 0x71DB139 |
0x00006 | 0xEC70DB7 |
0x00007 | 0xAB12BF4 |
0x00008 | 0x2158D55 |
0x00009 | 0x45099CD |
... | ... |
Process 1�Page Table
CS 61C
Summer 2026
Agenda
60
CS 61C
Summer 2026
Address Translation Example
firefox
intellij
"I want to read 0x00004ABC."
CPU
Page Table 1.
Page Table 2.
orange
…banana…
…apple…
…orange…
…
(page with data)
Disk
TLB
Page Tables
Each entry 4 bytes.
Main Memory
Each page 0x1000 bytes.
CS 61C
Summer 2026
[Case 1, Best] TLB Hit
Address Translation: Instant (~1 clock cycle)
| ... |
VPN 3 | 0xAB12BF5 |
VPN 4 | 0x82C121D |
VPN 5 | 0xD01A3F1 |
| ... |
| ... |
banana | 0xD01A3F1000 |
| ... |
apple | 0xAB12BF5000 |
potato | 0xAB12BF4000 |
| ... |
orange | 0x82C121D000 |
| ... |
carrot | 0x2158D55000 |
| ... |
Page Table | 0x120331D000 |
Page Table | 0x120331C000 |
lw s5 12(a2)
srli t2 t0 3
…
firefox
addi s2 x0 3
jal label
…
intellij
| ... |
VPN 3 | 0xAB12BF4 |
VPN 4 | disk |
VPN 5 | 0x2158D55 |
| ... |
Disk
... |
... |
... |
beans |
orange |
... |
... |
... |
... |
VPN | PPN |
0x00004 | 0x8C121D |
0x00005 | 0x2158D55 |
0x00009 | 0x45099CD |
"I want to read 0x00004ABC."
Page Tables
Each entry 4 bytes.
Main Memory
Each page 0x1000 bytes.
VPN 4 in TLB!
✅
TLB
CPU
CS 61C
Summer 2026
[Case 2, Worse] TLB Miss + Page Table Walk
Page table walk (~100 cycles): Go to main memory, read page table.
| ... |
VPN 3 | 0xAB12BF5 |
VPN 4 | 0x82C121D |
VPN 5 | 0xD01A3F1 |
| ... |
| ... |
banana | 0xD01A3F1000 |
| ... |
apple | 0xAB12BF5000 |
potato | 0xAB12BF4000 |
| ... |
orange | 0x82C121D000 |
| ... |
carrot | 0x2158D55000 |
| ... |
Page Table | 0x120331D000 |
Page Table | 0x120331C000 |
lw s5 12(a2)
srli t2 t0 3
…
firefox
addi s2 x0 3
jal label
…
intellij
| ... |
VPN 3 | 0xAB12BF4 |
VPN 4 | disk |
VPN 5 | 0x2158D55 |
| ... |
Disk
... |
... |
... |
beans |
orange |
... |
... |
... |
... |
VPN | PPN |
0x00002 | 0x30219D |
0x00005 | 0x2158D55 |
0x00009 | 0x45099CD |
"I want to read 0x00004ABC."
Page Tables
Each entry 4 bytes.
Main Memory
Each page 0x1000 bytes.
TLB
CPU
VPN 4 NOT in TLB.
❌
VPN 4 in Page Table!
✅
CS 61C
Summer 2026
[Case 2, Worse] TLB Miss + Page Table Walk, cont.
Page table walk (~100 cycles): Go to main memory, read page table.�Update TLB so we have this VPN/PPN mapping handy for next time.
| ... |
banana | 0xD01A3F1000 |
| ... |
apple | 0xAB12BF5000 |
potato | 0xAB12BF4000 |
| ... |
orange | 0x82C121D000 |
| ... |
carrot | 0x2158D55000 |
| ... |
Page Table | 0x120331D000 |
Page Table | 0x120331C000 |
lw s5 12(a2)
srli t2 t0 3
…
firefox
addi s2 x0 3
jal label
…
intellij
| ... |
VPN 3 | 0xAB12BF4 |
VPN 4 | disk |
VPN 5 | 0x2158D55 |
| ... |
Disk
... |
... |
... |
beans |
orange |
... |
... |
... |
... |
VPN | PPN |
0x00004 | 0x8C121D |
0x00005 | 0x2158D55 |
0x00009 | 0x45099CD |
"I want to read 0x00004ABC."
Page Tables
Each entry 4 bytes.
Main Memory
Each page 0x1000 bytes.
TLB
CPU
VPN 4 NOT in TLB.
❌
Update TLB.
| ... |
VPN 3 | 0xAB12BF5 |
VPN 4 | 0x82C121D |
VPN 5 | 0xD01A3F1 |
| ... |
VPN 4 in Page Table!
✅
CS 61C
Summer 2026
[Case 3, Worst] Page Fault
Page fault. Go to disk to load page (~1000s cycles)
| ... |
banana | 0xD01A3F1000 |
| ... |
apple | 0xAB12BF5000 |
potato | 0xAB12BF4000 |
| ... |
| 0x82C121D000 |
| ... |
carrot | 0x2158D55000 |
| ... |
Page Table | 0x120331D000 |
Page Table | 0x120331C000 |
lw s5 12(a2)
srli t2 t0 3
…
firefox
addi s2 x0 3
jal label
…
intellij
| ... |
VPN 3 | 0xAB12BF4 |
VPN 4 | disk |
VPN 5 | 0x2158D55 |
| ... |
Disk
... |
... |
... |
beans |
orange |
... |
... |
... |
... |
VPN | PPN |
0x00002 | 0x30219D |
0x00005 | 0x2158D55 |
0x00009 | 0x45099CD |
"I want to read 0x00004ABC."
Page Tables
Each entry 4 bytes.
Main Memory
Each page 0x1000 bytes.
TLB
CPU
VPN 4 NOT in TLB.
❌
| ... |
VPN 3 | 0xAB12BF5 |
VPN 4 | disk |
VPN 5 | 0xD01A3F1 |
| ... |
VPN 4 has no PPN in Page Table.
❌
orange | 0x82C121D000 |
Load page from disk.
CS 61C
Summer 2026
[Case 3, Worst] Page Fault
Update page table with PPN of the newly-loaded page.
Update TLB so we have this VPN/PPN mapping handy for next time.
| ... |
banana | 0xD01A3F1000 |
| ... |
apple | 0xAB12BF5000 |
potato | 0xAB12BF4000 |
| ... |
| 0x82C121D000 |
| ... |
carrot | 0x2158D55000 |
| ... |
Page Table | 0x120331D000 |
Page Table | 0x120331C000 |
lw s5 12(a2)
srli t2 t0 3
…
firefox
addi s2 x0 3
jal label
…
intellij
| ... |
VPN 3 | 0xAB12BF4 |
VPN 4 | disk |
VPN 5 | 0x2158D55 |
| ... |
Disk
... |
... |
... |
beans |
orange |
... |
... |
... |
... |
VPN | PPN |
0x00004 | 0x8C121D |
0x00005 | 0x2158D55 |
0x00009 | 0x45099CD |
"I want to read 0x00004ABC."
Page Tables
Each entry 4 bytes.
Main Memory
Each page 0x1000 bytes.
TLB
CPU
VPN 4 NOT in TLB.
❌
Update TLB
| ... |
VPN 3 | 0xAB12BF5 |
VPN 4 | 0x82C121D |
VPN 5 | 0xD01A3F1 |
| ... |
VPN 4 has no PPN in Page Table.
❌
orange | 0x82C121D000 |
Load page from disk.
Update page table.
CS 61C
Summer 2026
Summary: TLB Hits, Page Table Walk, Page Fault…
| TLB | Page Table Walk | Disk access |
Best | Hit ✅ | Not visited | Not visited |
Worse | Miss ❌ | Page Table Entry Valid ✅ | Not visited |
Worst | Miss ❌ | Page Fault ❌ | Load page�✅ |
CS 61C
Summer 2026
Agenda
68
CS 61C
Summer 2026
The Entire Modern Memory Hierarchy
Processor chip
DRAM chip –e.g. �DDR3/4/5�HBM/HBM2/3
SSD, HDD�Drives
(now assume caches exist)
CS 61C
Summer 2026
Another View of Memory Hierarchy
CS 61C
Summer 2026
Memory Units
CS 61C
Summer 2026
Caches have copies of data
🙂
🙂
🙂
🙂
CS 61C
Summer 2026
Page Tables don't copy data
CS 61C
Summer 2026
Caches vs. Virtual Memory
| Caches | Virtual Memory |
In memory hierarchy | Caches ↔ Memory | Memory ↔ Disk |
Memory unit | Block (~64 bytes) | Page (~4096 bytes) |
Miss | Cache Miss | Page Fault |
Associativity | Direct-mapped, N-way set associative, fully associative | Fully associative (pages can go anywhere in memory) |
Replacement policy | Least-recently-used (LRU) or random | LRU (most common), FIFO, or random |
Write policy | Write-through or write-back | Write-back |
CS 61C
Summer 2026
Putting it All Together: PIPT
VA
data
Load byte @ 0xFFFF F004 �to register t0
CPU
CS 61C
Summer 2026
Putting it All Together: PIPT
Load byte @ 0xFFFF F004 �to register t0
CPU
CS 61C
Summer 2026