1 of 76

CS61C: Great Ideas in Computer Architecture (aka Machine Structures)

Lecture 24: Virtual Memory

Instructor: Justin Yokota�Slide Credit: Lisa Yan

CS 61C

Summer 2026

2 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

2

CS 61C

Summer 2026

3 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

3

CS 61C

Summer 2026

4 of 76

How much memory is my computer using?

  • My computer reports that I'm using 13.8 GB of Random Access Memory (out of 15.7 GB total)
  • Let's verify this by calculating from some other data.
    • Might be a bit off because of some factor we don't know yet, but it shouldn't be too far off…
  • Currently my computer is using 422 processes, each of which needs an address space
  • My computer is a 64-bit computer, so memory addresses are 48 bits long
  • Total = 422 * 248 bytes = 100 petabytes (about 8 million times off)
    • Wait…

CS 61C

Summer 2026

5 of 76

Virtual Memory

  • If we gave each process a full 248 bytes of RAM, we won't be able to fit any processes in our RAM.
  • Can we do better?
  • Most processes don't use all their address space.
    • They mostly use one block of memory in the code segment, another block in the stack, and maybe a few blocks in the heap/data segments.
  • Solution: Chop up main memory into "pages" of a few KiB each. Only store pages that a program actually tries to access.
    • Ex. A program may be using 1 page for its code, 1 page for its stack, 4 pages for its heap, etc.
  • When we run a program, it needs to believe that it has access to its full 232 bit address space (on a 32-bit machine). This memory doesn't actually exist; it's "virtual" memory.
  • When a program actually needs a page of memory, we'll allocate a page of physical memory.

CS 61C

Summer 2026

6 of 76

Virtual Memory

  • Virtual memory is the next level in the memory hierarchy:
    • Give each process the illusion of a full memory address space that it has completely for itself.
    • Under the hood: working set of pages reside in main memory;�other pages are on disk.
  • Benefits:
    • Demand paging provides the ability to run programs larger than the primary memory (DRAM).
    • OS can share memory and protect programs from each other.
    • Hides differences between machine configurations.
    • (Historically, virtual memory predates caches.)
  • Logic here wants more flexibility than hardware can permit. So we'll incorporate it in the OS.

CS 61C

Summer 2026

7 of 76

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

8 of 76

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

9 of 76

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

10 of 76

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

11 of 76

Address Sizes: The Hive Machines

CS 61C

Summer 2026

12 of 76

Virtual Addresses vs. Physical Addresses

  • Address Space: set of addresses for all available memory locations.
    • Now, two kinds of memory addresses!
  • Virtual Address Space
    • Set of addresses that the user program knows about
  • Physical Address Space
    • Set of addresses that map to actual physical locations in memory
    • Hidden from user applications
  • For each process, the memory manager maps (translates) between these two address spaces.

CS 61C

Summer 2026

13 of 76

How is the Memory Hierarchy Managed?

  • registers ↔ memory
    • By compiler (or assembly level programmer)
  • cache ↔ main memory
    • By the cache controller hardware
  • main memory ↔ disks (secondary storage)
    • By the operating system (virtual memory)
    • Virtual to physical address mapping assisted by the hardware (‘translation lookaside buffer’ or TLB)
    • By the programmer (files)

CS 61C

Summer 2026

14 of 76

For Today: Assume Caches Don't Exist

  • Virtual Memory is much easier to understand if we assume no caches.
    • We’ll reintroduce caches along with Translation Lookaside Buffers (TLBs) later.

Processor chip

DRAM chip –e.g. �DDR3/4/5�HBM/HBM2/3

SSD, HDD�Drives

(assume this doesn’t exist)

CS 61C

Summer 2026

15 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

15

CS 61C

Summer 2026

16 of 76

Paged Memory

  • Physical memory (DRAM) is broken into pages.
  • A disk access loads an entire page into memory.
    • Should be large enough to amortize high access time.
  • Typical page size: 4 KiB+ (on modern OSes)
    • Need 12 bits of page offset to address all 4 KiB bytes.

0xF…F

0x0…0

text

stack

heap

data

Page Number 0

Page Number 1

(paged) virtual address space

CS 61C

Summer 2026

17 of 76

Paged Memory

  • Physical memory (DRAM) is broken into pages.
  • A disk access loads an entire page into memory.
    • Should be large enough to amortize high access time.
  • Typical page size: 4 KiB+ (on modern OSes)
    • Need 12 bits of page offset to address all 4 KiB bytes.
  • Memory translation maps a Virtual Page Number (VPN) to a Physical Page Number (PPN).

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

18 of 76

Address Translation

  • A page table translates virtual addresses to physical addresses for a given process. Each entry in the table:
    • Corresponds to a virtual page number.
    • If page is in memory, entry has corresponding physical page number.
    • Else, entry should tell OS to trigger page fault to load page from disk.

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

19 of 76

Analogy: Return of the Librarian

  • Earlier, we imagined that memory was a library. For a program to access a memory address:
    • Call the librarian for the data
    • The librarian goes to that data location and responds with the data there.
  • With virtual memory:
    • The librarian doesn't actually have enough books to store everyone's data.
    • So when you first start using some chunk of memory, the librarian takes a spare book and assigns it to you.
    • The librarian is responsible for translating from your memory address to the right book
    • To keep track of this, the librarian reserves one of the books for themselves and writes down each book that's being used, and who it belongs to.

CS 61C

Summer 2026

20 of 76

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

21 of 76

Address Translation Example 1

Step 2: OS translates VA to the physical address (PA) in memory.

    • Split Virtual Address into virtual page number and offset (0xFFFFF 004)
    • Extract virtual page number (VPN) from VA (0xFFFFF)
    • Look up VPN in page table

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

22 of 76

Address Translation Example 1

Step 3: Page table lists VPN as corresponding to a physical page. Page hit.

    • Construct PA: physical page number + offset (from virtual address): 0x1004

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

23 of 76

Address Translation Example 1

Step 4: Read data at the corresponding memory location, and return it to the program

    • Read data at 0x1004 in physical memory
    • Send that data back 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

24 of 76

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

25 of 76

Address Translation Example 2

Step 2: OS finds empty physical page

    • If no page is available, copy (evict) a page to disk and reuse that page
    • OS can choose to decline the new memory allocation, in which case malloc returns NULL

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

26 of 76

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

27 of 76

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

28 of 76

Address Translation Example 3

Step 2: OS translates VA to the physical address (PA) in memory.

    • Split Virtual Address into virtual page number and offset (0xFFFFF 004)
    • Extract virtual page number (VPN) from VA (0xFFFFF)
    • Look up VPN in page table

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

29 of 76

Address Translation Example 3

Step 3: Page table doesn't have the PPN listed. Page Fault

    • Another part of the OS takes over here to decide if the data is on disk, or if the access is illegal
    • In this case, the data is on disk, so the OS loads the data from disk back to a physical page

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

30 of 76

Address Translation Example 3

Step 4: Read data at the corresponding memory location, and return it to the program

    • Read data at 0x2004 in physical memory
    • Send that data back 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

31 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

31

CS 61C

Summer 2026

32 of 76

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

33 of 76

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

34 of 76

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

35 of 76

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

36 of 76

Determining VPN/PPN size

  • Assume a 32-bit machine with 8GiB of RAM and 16KiB pages.
  • How many bits would there be for each of the following?

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

37 of 76

Determining VPN/PPN size

  • Assume a 32-bit machine with 8GiB of RAM and 16KiB pages.
  • 16 KiB = 214 -> 14 bits offset

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

38 of 76

Determining VPN/PPN size

  • Assume a 32-bit machine with 8GiB of RAM and 16KiB pages.
  • 32-bit machine = 32-bit virtual addresses -> 32-14 = 18 bit VPN.

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

39 of 76

Determining VPN/PPN size

  • Assume a 32-bit machine with 8GiB of RAM and 16KiB pages.
  • 233 bytes of RAM = 233-14 pages = 219 pages -> 19 bit PPN

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

40 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

40

CS 61C

Summer 2026

41 of 76

What does a Page Table look like?

  • One page table per process.
    • One entry per virtual page number.
    • Entry has physical page number (if in memory) as well as status bits (more later).
  • A page table is NOT a cache
    • A page table is a lookup table!
    • It does NOT have data.
    • All VPNs have an entry in the page table.
      • Index 0 -> stores which physical page corresponds to VPN 0

Page table

0x00000

0

0x06000

2

disk

0xFFFFF

1

PPN

status bits

CS 61C

Summer 2026

42 of 76

What does a Page Table Entry look like?

  • Each page table entry stores:
    • The physical page number associated with the given VPN
    • Status bits/metadata
  • For this class, we'll talk about the following:
  • Valid Bit
  • Dirty bit
  • Write protection bit

Page table

0x00000

0

0x06000

2

disk

0xFFFFF

1

PPN

status bits

CS 61C

Summer 2026

43 of 76

Valid Bit

  • Page table entries track a valid bit to indicate if the page is in memory (DRAM) or only on disk (similar to valid bit in a cache).
    • On each memory access, first check if page table entry is “valid.”
  • Valid/on → In main memory
    • Read/write data as directed by process.
  • Not Valid/off → On disk
    • Trigger page fault exception
      • OS intervenes to allocate the page into DRAM
    • If out of memory, first select a page to replace in DRAM
      • Store outgoing page to disk.
      • Read requested page from disk into DRAM.
    • Finally, read/write data as directed by process.

CS 61C

Summer 2026

44 of 76

Dirty Bit

  • Main memory acts like a “cache” for secondary memory/disk.
    • Should writes always go directly to disk (write-through), or
    • Should writes only go to disk when page is evicted (write-back)?
  • All virtual memory systems systems use write-back.
    • Disk accesses take way too long!
  • Recall that write-back policy requires a dirty bit to keep track of pages that have an unsynced write.
    • When a page gets replaced:
    • Dirty bit on: Write outgoing page back to disk.
    • Dirty bit off: No disk write.

CS 61C

Summer 2026

45 of 76

Write Protection Bit

  • Page table write protection bit: on = page is “protected.”
    • Writing to a protected page triggers an OS exception.
  • Useful for pages that should never be modified
    • Ex. Program code, system data, etc.
  • The OS acts to protect programs:
    • Isolate memory between processes.
    • Each process gets dedicated “private” memory.
      • Errors in one program won’t corrupt memory of other programs.
      • Prevent user programs from messing with OS’s memory.
    • Allow memory sharing where safe.

CS 61C

Summer 2026

46 of 76

Write Protection bit use case: Safe Memory Sharing

  • Each process gets its own page table
    • Normally, different processes have different data
  • What if two processes want to share the same data?
    • Have their page table map two virtual pages to the same physical page!
  • Common use case: two processes accessing the same dynamically-linked library (like stdlib.h)
  • Don't want to let programs modify stdlib, so turn on write protection for those pages.

CS 61C

Summer 2026

47 of 76

How big is a page table?

We have a system with:

  • 32-bit virtual addresses
  • 4 KiB pages
  • 32-bit page table entries

How much memory does our page table take? How many pages?

CS 61C

Summer 2026

48 of 76

How big is a page table?

We have a system with:

  • 32-bit virtual addresses
  • 4 KiB pages
  • 32-bit page table entries

How much memory does our page table take?

  • 212 bytes per page
  • 32-bit virtual address -> 20 bit VPN, 12 bit page offset
  • 220 PTEs = 222 bytes = 4 MiB

How many pages?

  • 4 MiB / 4 KiB = 1024 pages

CS 61C

Summer 2026

49 of 76

Page Tables are Stored in Memory

  • Each page table is ~4 MiB
    • Not bad compared to main memory (often on the order of GiBs), but too big for a cache.
    • Can be improved with two layer page table (see skipped slides)
  • Solution: store page tables in main memory.
  • Caveat: Two (slow) memory accesses per lw/sw on cache miss!
    • Read page table (stored in main memory) to translate to physical address
    • Read physical page, also in main memory
  • To minimize performance penalty:
    • Transfer cache lines (not words) between DRAM and processor cache
    • Use a cache for frequently used page table entries … (TLB)

CS 61C

Summer 2026

50 of 76

4 MiB is still kind of big

  • Our page table is currently 4 MiB
    • Not bad compared to main memory (often on the order of GiBs), but it's still big
  • We use a page table because most memory in a program is empty
  • Interesting note: Most VPNs in a page table are empty as well…
  • Solution: Make a page table of page tables!
    • Called a multi-level page table

CS 61C

Summer 2026

51 of 76

Multi-level page tables

  • Our page table starts at an L1 page table
    • Each entry in the L1 page table corresponds to a portion of the original (big) page table
      • Corresponds to the top bits of the VPN
  • If any entry in that part of the page table is valid, allocate an L2 page table, and note its location (physical page) in the L1 page table
  • The L2 page table acts as a regular page table and stores PPNs of the corresponding virtual page
    • Slot in L2 page table corresponds to bottom bits of the VPN
  • For optimal size, VPN should be split evenly between L1 and L2 page table

CS 61C

Summer 2026

52 of 76

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

53 of 76

How big is each L1/L2 page table?

We have a system with:

  • 32-bit virtual addresses
  • 4 KiB pages
  • 32-bit page table entries
  • VPN split in half between L1 and L2 tables

How much memory does each L1/L2 page table take? How many pages?

CS 61C

Summer 2026

54 of 76

How big is a page table?

We have a system with:

  • 32-bit virtual addresses
  • 4 KiB pages
  • 32-bit page table entries
  • VPN split in half between L1 and L2 tables

How much memory does our page table take?

  • 212 bytes per page
  • 32-bit virtual address -> 20 bit VPN, 12 bit page offset -> 10 VPN bits per table
  • 210 PTEs = 212 bytes = 4 KiB = 1 page

CS 61C

Summer 2026

55 of 76

The "Magic" Page Table

  • If we use a 2-layer page table with a 10-10-12 split (L1-L2-Page offset), and PTEs are 32 bits long, then every page table takes up exactly one page of memory
  • For 32-bit systems, this is really efficient
    • So page sizes of 4 KiB became fairly common
  • Previous semesters tended to use this particular example for multi-level page tables (which were in scope at that time)
  • Currently out of scope, but interesting to know.

CS 61C

Summer 2026

56 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

56

CS 61C

Summer 2026

57 of 76

Address Translation: Avoid Page Table Walks

  • Good Virtual Memory design should be�fast (~1 clock cycle) and space efficient.
    • However, every instruction/data access needs address translation.
  • A page table walk is the process of accessing the page table in memory.
    • If page tables are in memory, then each memory access takes several memory accesses to complete (very slow)
  • Solution: Cache some address translations in the Translation Lookaside Buffer (TLB).

VPN

offset

PPN

offset

Physical address

Virtual address

possible page table walk?

address translation

CS 61C

Summer 2026

58 of 76

The TLB Caches Address Lookups

  • A page table stores VPN-PPN mappings
  • The translation lookaside buffer (TLB) is a cache of VPN-PPN mappings.
    • The TLB is much closer to CPU and caches.
    • Predates data caches (so uses an older name)
  • Unlike a data cache, does NOT store the data in the page
    • Just speeds up the process of looking for the PPN in the page table, still needs to access the physical page to get actual data

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

59 of 76

TLB Details

  • Technical details:
    • Doesn't store much data, so relatively small
    • Fully associative (usually)
    • Replacement policy: FIFO (stores the most recently accessed pages)
  • Can be multi-level, but we'll restrict to single-level TLB for this class
  • TLB is on the core, but needs care when the core switches active process
    • Each process has different page table, so different VPN-PPN mapping
    • Easiest: OS flushes all/part of the TLB by invalidating its entries.
    • Harder: track which process corresponds to which entries

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

60 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

60

CS 61C

Summer 2026

61 of 76

Address Translation Example

  • Different cases of address translation impact the end-to-end latency of a single memory access.
    • Memory access = address translation + data access

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

62 of 76

[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

63 of 76

[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

64 of 76

[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

65 of 76

[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

66 of 76

[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

67 of 76

Summary: TLB Hits, Page Table Walk, Page Fault…

  • Three cases for an address translation:

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

68 of 76

Agenda

  • Virtual Memory and Virtual Addresses
  • Paged Memory and Address Translations
  • Practice
  • Page Table Details
  • Translation Lookaside Buffer (TLB)
  • Address Translation: Best/Worst Case
  • Caches vs Virtual Memory

68

CS 61C

Summer 2026

69 of 76

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

70 of 76

Another View of Memory Hierarchy

CS 61C

Summer 2026

71 of 76

Memory Units

  • Lines, pages, bytes, words are all units in the memory hierarchy.
    • Cache lines ~ 64 B or 128 B
    • Pages: ~4 KiB

CS 61C

Summer 2026

72 of 76

Caches have copies of data

  • “Cache” Paradigm: Data at each level is a quick-access copy of data at a lower level in the memory hierarchy.
  • Similarly, data pages in main memory are “cached” versions of pages on disk.

🙂

🙂

🙂

🙂

CS 61C

Summer 2026

73 of 76

Page Tables don't copy data

  • A Page Table translates addresses.
  • Page tables facilitate demand paging.
    • Page Table keeps track of page status/location only (not data).

CS 61C

Summer 2026

74 of 76

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

75 of 76

Putting it All Together: PIPT

  • Can a cache hold the requested data if the corresponding page is not in main memory?
  • On a memory reference, what should we access first?
  • When should we translate virtual addresses?

VA

data

Load byte @ 0xFFFF F004 �to register t0

CPU

CS 61C

Summer 2026

76 of 76

Putting it All Together: PIPT

  • Other more complicated designs exist, but in this class we assume physically indexed, physically tagged (PIPT) caches.
    • 1. First translate virtual address to physical address.
    • 2. Then use the physical address to access the data cache.

Load byte @ 0xFFFF F004 �to register t0

CPU

CS 61C

Summer 2026