csc 252: computer organization spring 2020: lecture 22 · csc 252: computer organization spring...

115
CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of Rochester

Upload: others

Post on 28-May-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

CSC 252: Computer Organization Spring 2020: Lecture 22

Instructor: Yuhao Zhu

Department of Computer ScienceUniversity of Rochester

Page 2: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

!2

Announcement• Programming assignment 4 is out

• Details: https://www.cs.rochester.edu/courses/252/spring2020/labs/assignment4.html

• Due on Apr. 17, 11:59 PM • You (may still) have 3 slip days

Today Due

Page 3: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

A System Using Virtual Addressing

!3

0:1:

M-1:

Main memory

MMU

2:3:4:5:6:7:

Physical address(PA)

Data word

8:...

CPUVirtual address

(VA)

CPU Chip

44100

Page 4: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

A System Using Virtual Addressing

• On a 64-bit machine, virtual memory size = 264• Physical memory size is much much smaller:

• iPhone 8: 2 GB (231)• 15-inch Macbook Pro 2017: 16 GB (234)

!3

0:1:

M-1:

Main memory

MMU

2:3:4:5:6:7:

Physical address(PA)

Data word

8:...

CPUVirtual address

(VA)

CPU Chip

44100

Page 5: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts• Conceptually, virtual memory is an array of N pages stored on

disk.• The physical memory is an array of M pages stored in DRAM.•M << N• Store only the most frequently used pages in the physical

memory• If a page is not on the physical memory, have to first swap it

from the disk to the DRAM.

!4

Page 6: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts

!5

• Divide both virtual memory (VM) and physical memory (PM) into “pages”

offsetVirtual Page Number

offsetPhysical Page Number

Page 7: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts

!5

• Divide both virtual memory (VM) and physical memory (PM) into “pages”• Page size is the same for VM and PM

offsetVirtual Page Number

offsetPhysical Page Number

Page 8: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts

!5

• Divide both virtual memory (VM) and physical memory (PM) into “pages”• Page size is the same for VM and PM• In a 64-bit machine, VA is 64-bit long. Assuming PM is 4 GB. Assuming

4KB page size.

offsetVirtual Page Number

offsetPhysical Page Number

Page 9: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts

!5

• Divide both virtual memory (VM) and physical memory (PM) into “pages”• Page size is the same for VM and PM• In a 64-bit machine, VA is 64-bit long. Assuming PM is 4 GB. Assuming

4KB page size.• How many bits for page offset?

• 12. Same for VM and PM

offsetVirtual Page Number

offsetPhysical Page Number

Page 10: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts

!5

• Divide both virtual memory (VM) and physical memory (PM) into “pages”• Page size is the same for VM and PM• In a 64-bit machine, VA is 64-bit long. Assuming PM is 4 GB. Assuming

4KB page size.• How many bits for page offset?

• 12. Same for VM and PM• How many bits for Virtual Page Number?

• 52, i.e., 252 virtual pages

offsetVirtual Page Number

offsetPhysical Page Number

Page 11: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

VM Concepts

!5

• Divide both virtual memory (VM) and physical memory (PM) into “pages”• Page size is the same for VM and PM• In a 64-bit machine, VA is 64-bit long. Assuming PM is 4 GB. Assuming

4KB page size.• How many bits for page offset?

• 12. Same for VM and PM• How many bits for Virtual Page Number?

• 52, i.e., 252 virtual pages• How many bits for Physical Page Number?

• 20, i.e., 220 physical pages

offsetVirtual Page Number

offsetPhysical Page Number

Page 12: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Page Table: Enabling VA to PA Translation• A page table is an array of page table entries (PTEs) that maps

every virtual page to its physical page.

!6

null

null

Valid

01

010

10

1

Physical page number or

disk addressPTE 0

PTE 7

Page 13: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Page Table: Enabling VA to PA Translation• A page table is an array of page table entries (PTEs) that maps

every virtual page to its physical page.

!6

null

null

Disk

Valid

01

010

10

1

Physical page number or

disk addressPTE 0

PTE 7

VP 1VP 2

VP 4VP 6VP 7

VP 3

VP 0

Page 14: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Page Table: Enabling VA to PA Translation• A page table is an array of page table entries (PTEs) that maps

every virtual page to its physical page.

!6

null

null

Physical memory (DRAM)

VP 7VP 4Disk

Valid

01

010

10

1

Physical page number or

disk addressPTE 0

PTE 7

PP 0VP 2VP 1

PP 3

VP 1VP 2

VP 4VP 6VP 7

VP 3

VP 0

Page 15: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Page Table: Enabling VA to PA Translation• A page table is an array of page table entries (PTEs) that maps

every virtual page to its physical page.

!6

null

null

Physical memory (DRAM)

VP 7VP 4Disk

Valid

01

010

10

1

Physical page number or

disk addressPTE 0

PTE 7

PP 0VP 2VP 1

PP 3

VP 1VP 2

VP 4VP 6VP 7

VP 3

VP 0

Page 16: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Page Table: Enabling VA to PA Translation• A page table is an array of page table entries (PTEs) that maps

every virtual page to its physical page.• 64-bit machine, 4KB page size, how many PTEs?

• Every virtual page has a PTE, so 252 PTEs.

!6

null

null

Physical memory (DRAM)

VP 7VP 4Disk

Valid

01

010

10

1

Physical page number or

disk addressPTE 0

PTE 7

PP 0VP 2VP 1

PP 3

VP 1VP 2

VP 4VP 6VP 7

VP 3

VP 0

Page 17: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Virtual page number (VPN)

Address Translation With a Page Table

!7

Virtual page offset (VPO)

Physical page number (PPN) Physical page offset (PPO)

Virtual address

Physical address

0p-1pn-1

0p-1pm-1

Page 18: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Virtual page number (VPN)

Address Translation With a Page Table

!7

Virtual page offset (VPO)

Physical page number (PPN) Physical page offset (PPO)

Virtual address

Physical address

Valid Physical page number (PPN)Page table (in the physical memory)

0p-1pn-1

0p-1pm-1

Page 19: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Virtual page number (VPN)

Address Translation With a Page Table

!7

Virtual page offset (VPO)

Physical page number (PPN) Physical page offset (PPO)

Virtual address

Physical address

Valid Physical page number (PPN)Page table (in the physical memory)

Page table base register

(PTBR)

Physical page table address for the current process

0p-1pn-1

0p-1pm-1

Page 20: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Virtual page number (VPN)

Address Translation With a Page Table

!7

Virtual page offset (VPO)

Physical page number (PPN) Physical page offset (PPO)

Virtual address

Physical address

Valid Physical page number (PPN)Page table (in the physical memory)

Page table base register

(PTBR)

Physical page table address for the current process

0p-1pn-1

0p-1pm-1

PTEA = PTBR + VPN * sizeof (PTE)

Page 21: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Virtual page number (VPN)

Address Translation With a Page Table

!7

Virtual page offset (VPO)

Physical page number (PPN) Physical page offset (PPO)

Virtual address

Physical address

Valid Physical page number (PPN)Page table (in the physical memory)

Page table base register

(PTBR)

Physical page table address for the current process

Valid bit = 0: Page not in memory

(page fault)

0p-1pn-1

0p-1pm-1

PTEA = PTBR + VPN * sizeof (PTE)

Page 22: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Virtual page number (VPN)

Address Translation With a Page Table

!7

Virtual page offset (VPO)

Physical page number (PPN) Physical page offset (PPO)

Virtual address

Physical address

Valid Physical page number (PPN)Page table (in the physical memory)

Page table base register

(PTBR)

Physical page table address for the current process

Valid bit = 0: Page not in memory

(page fault)

0p-1pn-1

0p-1pm-1

Valid bit = 1

PTEA = PTBR + VPN * sizeof (PTE)

Page 23: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Hit

!8

MMUMemory

CPU

CPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 24: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Hit

1) Processor sends virtual address to MMU

!8

MMUMemory

CPU

CPU Chip

VA1

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 25: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Hit

1) Processor sends virtual address to MMU

!8

MMUMemory

CPU

CPU Chip

VA1

PTEA2

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 26: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Hit

1) Processor sends virtual address to MMU

2-3) MMU fetches PTE from page table in memory

!8

MMUMemory

CPU

CPU Chip

VA1

PTEA2

PTE3

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 27: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Hit

1) Processor sends virtual address to MMU

2-3) MMU fetches PTE from page table in memory

4) MMU sends physical address to cache/memory

!8

MMUMemory

CPU

CPU Chip

VA1

PTEA2

PTE3

PA4

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 28: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Hit

1) Processor sends virtual address to MMU

2-3) MMU fetches PTE from page table in memory

4) MMU sends physical address to cache/memory

5) Cache/memory sends data word to processor

!8

MMUMemory

CPU

CPU Chip

VA1

PTEA2

PTE3

PA4

Data5

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 29: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

!9

MemoryCPU

CPU Chip

DiskMMU

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 30: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU

!9

MemoryCPU

CPU Chip

VA1

DiskMMU

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 31: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU

!9

MemoryCPU

CPU Chip

VA1

PTEA2

DiskMMU

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 32: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory

!9

MemoryCPU

CPU Chip

VA1

PTEA2

PTE3 DiskMMU

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 33: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory4) Valid bit is zero, so MMU triggers page fault exception

!9

MemoryCPU

CPU Chip

VA1

PTEA2

PTE3 Disk

4

Exception

MMU

Page fault handler

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 34: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory4) Valid bit is zero, so MMU triggers page fault exception5) Handler identifies victim (and, if dirty, pages it out to disk)

!9

MemoryCPU

CPU Chip

VA1

PTEA2

PTE3 Disk

5

Victim page

4

Exception

MMU

Page fault handler

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 35: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory4) Valid bit is zero, so MMU triggers page fault exception5) Handler identifies victim (and, if dirty, pages it out to disk)6) Handler pages in new page and updates PTE in memory

!9

MemoryCPU

CPU Chip

VA1

PTEA2

PTE3 Disk

5

Victim page

4

Exception

New page

6

MMU

Page fault handler

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 36: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Address Translation: Page Fault

1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory4) Valid bit is zero, so MMU triggers page fault exception5) Handler identifies victim (and, if dirty, pages it out to disk)6) Handler pages in new page and updates PTE in memory7) Handler returns to original process, restarting faulting instruction

!9

MemoryCPU

CPU Chip

VA1

PTEA2

PTE3 Disk

5

Victim page

4

Exception

New page

6

7MMU

Page fault handler

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 37: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Integrating VM and Cache

!10

CPU MMU Memory

CPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 38: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMU Memory

CPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 39: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA Memory

CPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 40: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

Memory

CPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 41: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

Memory

PTEAmiss

PTEA

CPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 42: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

Memory

PTEAmiss

PTEA

PTECPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 43: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

Memory

PTEAmiss

PTE

PTEA hit

PTEA

PTECPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 44: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

PAMemory

PTEAmiss

PTE

PTEA hit

PTEA

PTECPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 45: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

PAMemory

PAPAmiss

PTEAmiss

PTE

PTEA hit

PTEA

PTECPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 46: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

PAMemory

PAPAmiss

PTEAmiss

PTE

PTEA hit

PTEA

Data

PTECPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 47: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

L1 cache

Integrating VM and Cache

!10

CPU MMUVA

PTEA

PAMemory

PAPAmiss

PTEAmiss

PTE

PTEA hit

Data

PA hit

PTEA

Data

PTECPU Chip

VA: virtual address, PA: physical address, PTE: page table entry, PTEA = PTE address

Page 48: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Today• Three Virtual Memory Optimizations

• TLB • Page the page table (a.k.a., multi-level page table) • Virtually-indexed, physically-tagged cache

• Case-study: Intel Core i7/Linux example

!11

Page 49: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Address Translation

!12

Page 50: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Address Translation• Problem: Every memory load/store requires two memory

accesses: one for PTE, another for real• The PTE access is kind of an overhead • Can we speed it up?

!12

Page 51: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Address Translation• Problem: Every memory load/store requires two memory

accesses: one for PTE, another for real• The PTE access is kind of an overhead • Can we speed it up?

• Page table entries (PTEs) are already cached in L1 data cache like any other memory data. But:• PTEs may be evicted by other data references • PTE hit still requires a small L1 delay

!12

Page 52: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Translation with a TLB• Solution: Translation Lookaside Buffer (TLB)

• Think of it as a dedicated cache for page table • Small set-associative hardware cache in MMU • Contains complete page table entries for a small number of pages

!13

Page 53: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Translation with a TLB• Solution: Translation Lookaside Buffer (TLB)

• Think of it as a dedicated cache for page table • Small set-associative hardware cache in MMU • Contains complete page table entries for a small number of pages

!13

Tag Set Index

Page 54: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Translation with a TLB• Solution: Translation Lookaside Buffer (TLB)

• Think of it as a dedicated cache for page table • Small set-associative hardware cache in MMU • Contains complete page table entries for a small number of pages

!13

Datatagv

…DatatagvSet 0

Datatagv DatatagvSet 1

Datatagv DatatagvSet T-1

Tag Set Index

A Conventional Data Cache

Page 55: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Translation with a TLB• Solution: Translation Lookaside Buffer (TLB)

• Think of it as a dedicated cache for page table • Small set-associative hardware cache in MMU • Contains complete page table entries for a small number of pages

!13

Datatagv

…DatatagvSet 0

Datatagv DatatagvSet 1

Datatagv DatatagvSet T-1

Tag Set Index

Set Index selects a set

A Conventional Data Cache

Page 56: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Speeding up Translation with a TLB• Solution: Translation Lookaside Buffer (TLB)

• Think of it as a dedicated cache for page table • Small set-associative hardware cache in MMU • Contains complete page table entries for a small number of pages

!13

Datatagv

…DatatagvSet 0

Datatagv DatatagvSet 1

Datatagv DatatagvSet T-1

Tag Set Index

Set Index selects a set

Compare tag to decide cache hit/miss

A Conventional Data Cache

Page 57: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Accessing the TLB•MMU uses the Virtual Page Number portion of the virtual

address to access the TLB:

!14

TLB tag (TLBT) TLB index (TLBI)0p-1pn-1

Offset

PTEtagv

…PTEtagvSet 0

PTEtagv PTEtagvSet 1

PTEtagv PTEtagvSet T-1 A Page Table Cache

Virtual Page Number

Page 58: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Accessing the TLB•MMU uses the Virtual Page Number portion of the virtual

address to access the TLB:

!14

TLB tag (TLBT) TLB index (TLBI)0p-1pn-1

Offset

Virtual Page Number

p+t-1p+t

PTEtagv

…PTEtagvSet 0

PTEtagv PTEtagvSet 1

PTEtagv PTEtagvSet T-1 A Page Table Cache

Page 59: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Accessing the TLB•MMU uses the Virtual Page Number portion of the virtual

address to access the TLB:

!14

TLB tag (TLBT) TLB index (TLBI)0p-1pn-1

Offset

Virtual Page Number

p+t-1p+t

PTEtagv

…PTEtagvSet 0

PTEtagv PTEtagvSet 1

PTEtagv PTEtagvSet T-1

TLBI selects the set

A Page Table Cache

Page 60: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Accessing the TLB•MMU uses the Virtual Page Number portion of the virtual

address to access the TLB:

!14

TLB tag (TLBT) TLB index (TLBI)0p-1pn-1

Offset

Virtual Page Number

p+t-1p+t

PTEtagv

…PTEtagvSet 0

PTEtagv PTEtagvSet 1

PTEtagv PTEtagvSet T-1

TLBI selects the set

TLBT matches tag of line within set

A Page Table Cache

Page 61: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU ChipTLB

Page 62: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU Chip

VA1

TLB

Page 63: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU Chip

VA1

TLB

2VPN

Page 64: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU Chip

VA1

TLB

2VPN

PTE3

Page 65: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU Chip

VA1

PA4

TLB

2VPN

PTE3

Page 66: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU Chip

VA1

PA4

Data5

TLB

2VPN

PTE3

Page 67: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Hit

!15

MMU Cache/ Memory

CPU

CPU Chip

VA1

PA4

Data5

A TLB hit eliminates a memory access

TLB

2VPN

PTE3

Page 68: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Miss

!16

MMU Cache/ Memory

CPU VA

CPU Chip

1

2

TLB

VPN

Page 69: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Miss

!16

MMU Cache/ Memory

CPU VA

CPU Chip

1

2

TLB

VPN

PTEA3

Page 70: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Miss

!16

MMU Cache/ Memory

CPU VA

CPU Chip

1

2

TLB

VPN

PTEA3

PTE4

Page 71: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Miss

!16

MMU Cache/ Memory

CPU VA

CPU Chip

1

2

PA5

TLB

VPN

PTEA3

PTE4

Page 72: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

TLB Miss

!16

MMU Cache/ Memory

CPU VA

CPU Chip

1

2

PA5

Data6

TLB

VPN

PTEA3

PTE4

Page 73: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Today• Three Virtual Memory Optimizations

• TLB • Page the page table (a.k.a., multi-level page table) • Virtually-indexed, physically-tagged cache

• Case-study: Intel Core i7/Linux example

!17

Page 74: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Where Does Page Table Live?

!18

Page 75: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Where Does Page Table Live?• It needs to be at a specific location where we can find it

• In main memory, with its start address stored in a special register (PTBR)

!18

Page 76: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Where Does Page Table Live?• It needs to be at a specific location where we can find it

• In main memory, with its start address stored in a special register (PTBR)

• Assume 4KB page, 48-bit virtual memory, each PTE is 8 Bytes• 236 PTEs in a page table • 512 GB total size per page table??!!

!18

Page 77: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Where Does Page Table Live?• It needs to be at a specific location where we can find it

• In main memory, with its start address stored in a special register (PTBR)

• Assume 4KB page, 48-bit virtual memory, each PTE is 8 Bytes• 236 PTEs in a page table • 512 GB total size per page table??!!

• Problem: Page tables are huge• One table per process! • Storing them all in main memory wastes space

!18

Page 78: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Page 79: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Page 80: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Page 81: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Page 82: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Page 83: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Virtual address

Page 84: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Virtual address

Page 85: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Solution: Page the Page Table• Observation: Only a small number of pages (working set) are

accessed during a certain period of time, due to locality• Put only the relevant page table entires in main memory• Idea: Put Page Table in Virtual Memory and swap it just like data

!19

VMPM

Virtual address

Page 86: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Effectively: A 2-Level Page Table• Level 1 table:

• Always in memory at a known location. • Each L1 PTE points to the start address

of a L2 page table. • Bring that table to memory on-demand.

• Level 2 table:• Each PTE points to an actual data page

!20

Level 1 Table

...

Level 2 Tables

...

Page 87: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

A Two-Level Page Table Hierarchy

!21...

VP 0...

VP 1023VP 1024

...VP 2047

unallocatedpages

unallocated pages

VP 9215

Virtualmemory

32 bit addresses, 4KB pages, 4-byte PTEs

Page 88: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

A Two-Level Page Table Hierarchy

!21...

Level 2page tables

VP 0...

VP 1023VP 1024

...VP 2047

unallocatedpages

unallocated pages

VP 9215

Virtualmemory

PTE 0...

PTE 1023

PTE 0...

PTE 1023

1023 null PTEs

PTE 1023

32 bit addresses, 4KB pages, 4-byte PTEs

Page 89: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

A Two-Level Page Table Hierarchy

!21

Level 1page table

...

Level 2page tables

VP 0...

VP 1023VP 1024

...VP 2047

unallocatedpages

unallocated pages

VP 9215

Virtualmemory

PTE 0...

PTE 1023

PTE 0...

PTE 1023

1023 null PTEs

PTE 1023(1K - 9)

null PTEs

PTE 0PTE 1

PTE 2 (null)PTE 3 (null)PTE 4 (null)PTE 5 (null)PTE 6 (null)PTE 7 (null)

PTE 8

32 bit addresses, 4KB pages, 4-byte PTEs

Page 90: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

A Two-Level Page Table Hierarchy

!21

Level 1page table

...

Level 2page tables

VP 0...

VP 1023VP 1024

...VP 2047

unallocatedpages

unallocated pages

VP 9215

Virtualmemory

PTE 0...

PTE 1023

PTE 0...

PTE 1023

1023 null PTEs

PTE 1023(1K - 9)

null PTEs

PTE 0PTE 1

PTE 2 (null)PTE 3 (null)PTE 4 (null)PTE 5 (null)PTE 6 (null)PTE 7 (null)

PTE 8

32 bit addresses, 4KB pages, 4-byte PTEs

• Level 2 page table size:• 232 / 212 * 4 = 4 MB • Level 1 page table

size:• (232 / 212 * 4) / 212 *

4 = 4 KB

Page 91: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!22

VPOVPN

Page Table

...

0000000100100011

0100010101100111

1100110111101111

0001

Page 92: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!23

...

Level 2 Tables

Level 1 Table

...

00011011

00011011

VPOVPN

00011011

0001

11

0001

Page 93: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!23

...

Level 2 Tables

Level 1 Table

...

00011011

00011011

VPO

00011011

0001

11

VPN 1 VPN 2

0001

Page 94: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!23

...

Level 2 Tables

Level 1 Table

...

00011011

00011011

VPO

00011011

0001

11

VPN 1 VPN 2

01

Page 95: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!23

...

Level 2 Tables

Level 1 Table

...

00011011

00011011

VPO

00011011

0001

11

VPN 1 VPN 2

00

01

Page 96: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!24

Page table base register

(PTBR)

0p-1n-1VPOVPN

PPN

0p-1m-1PPOPPN

VIRTUAL ADDRESS

PHYSICAL ADDRESS

page table

Page 97: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

How to Access a 2-Level Page Table?

!25

Page table base register

(PTBR)

VPN 10p-1n-1

VPOVPN 2

PPN

0p-1m-1PPOPPN

VIRTUAL ADDRESS

PHYSICAL ADDRESS

Level 1 page table

Level 2 page table

Page 98: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Translating with a k-level Page Table

!26

Page table base register

(PTBR)

VPN 10p-1n-1

VPOVPN 2 ... VPN k

PPN

0p-1m-1PPOPPN

VIRTUAL ADDRESS

PHYSICAL ADDRESS

... ...

Level 1 page table

Level 2 page table

Level k page table

Page 99: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Today• Three Virtual Memory Optimizations

• TLB • Page the page table (a.k.a., multi-level page table) • Virtually-indexed, physically-tagged cache

• Case-study: Intel Core i7/Linux example

!27

Page 100: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Performance Issue in VM• Address translation and cache accesses are serialized

• First translate from VA to PA • Then use PA to access cache • Slow! Can we speed it up?

!28

L1 cache

CPU MMUVAPA

MemoryPAPA

miss

Data

PA hit

Data

CPU Chip

Page 101: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Physical page number (PPN)

Cache Line Offset

Performance Issue in VM

!29

Virtual page number (VPN) Page Offset

Page Offset

VirtualAddress

PhysicalAddress

Set IndexTagL1

cache

Page 102: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Physical page number (PPN)

Cache Line Offset

Performance Issue in VM

!29

Virtual page number (VPN) Page Offset

Page Offset

VirtualAddress

PhysicalAddress

Set IndexTagL1

cache

Unchanged!!

Page 103: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Physical page number (PPN)

Cache Line Offset

Performance Issue in VM

!29

Virtual page number (VPN) Page Offset

Page Offset

VirtualAddress

PhysicalAddress

Set IndexTagL1

cache

Unchanged!!

Set IndexTag

=

Page 104: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Physical page number (PPN)

Cache Line Offset

Performance Issue in VM

!29

Virtual page number (VPN) Page Offset

Page Offset

VirtualAddress

PhysicalAddress

Set IndexTagL1

cache

Unchanged!!

Set IndexTag

=• Set Index + Cache Line Offset = Page Offset• Indexing into cache in parallel with translation (TLB access)• If TLB hits, can get the data back in one cycle

Page 105: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Physical page number (PPN)

Cache Line Offset

Performance Issue in VM

!29

Virtual page number (VPN) Page Offset

Page Offset

VirtualAddress

PhysicalAddress

Set IndexTagL1

cache

Unchanged!!

Set IndexTag

=• Set Index + Cache Line Offset = Page Offset• Indexing into cache in parallel with translation (TLB access)• If TLB hits, can get the data back in one cycle

Virtually-Indexed,Physically-Tagged

Cache

Page 106: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!30

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

Page 107: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!30

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

• Assuming 4K page size, cache line size is 16 bytes.

12 bits

4 bits

Page 108: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!30

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

• Assuming 4K page size, cache line size is 16 bytes.• Set Index = 8 bits. Can only have 256 Sets => Limit cache size

12 bits

4 bits8 bits

Page 109: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!30

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

• Assuming 4K page size, cache line size is 16 bytes.• Set Index = 8 bits. Can only have 256 Sets => Limit cache size• Increasing cache size then requires increasing associativity

12 bits

4 bits8 bits

Page 110: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!30

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

• Assuming 4K page size, cache line size is 16 bytes.• Set Index = 8 bits. Can only have 256 Sets => Limit cache size• Increasing cache size then requires increasing associativity

• Not ideal because that requires comparing more tags

12 bits

4 bits8 bits

Page 111: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!30

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

• Assuming 4K page size, cache line size is 16 bytes.• Set Index = 8 bits. Can only have 256 Sets => Limit cache size• Increasing cache size then requires increasing associativity

• Not ideal because that requires comparing more tags• Solutions?

12 bits

4 bits8 bits

Page 112: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!31

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

•What if we use 9 bits for Set Index? More Sets now.

12 bits

4 bits9 bits

Page 113: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!31

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

•What if we use 9 bits for Set Index? More Sets now.• How can this still work???

12 bits

4 bits9 bits

Page 114: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!31

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

•What if we use 9 bits for Set Index? More Sets now.• How can this still work???• The least significant bit in VPN and PPN must be the same

12 bits

4 bits9 bits

Page 115: CSC 252: Computer Organization Spring 2020: Lecture 22 · CSC 252: Computer Organization Spring 2020: Lecture 22 Instructor: Yuhao Zhu Department of Computer Science University of

Carnegie Mellon

Tag

Any Implications?

!31

Virtual page number (VPN) Page OffsetVirtual

Address

Cache Line Offset

Set Index

PhysicalAddress

•What if we use 9 bits for Set Index? More Sets now.• How can this still work???• The least significant bit in VPN and PPN must be the same• That is: an even VA must be mapped to an even PA, and an odd

VA must be mapped to an odd PA

12 bits

4 bits9 bits