18 VM Details
18 VM Details
0 Address 0
Physical
Virtual
Address VP 1
translation Address
Space for VP 2 PP 2 Space
Process 1: ... (DRAM)
N-1
(e.g., read-only
PP 6 library code)
0
Virtual PP 8
Address VP 1
Space for ...
Process 2: ...
VP k
N-1 M-1
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 2
Carnegie Mellon
Today
Multi-level page tables
Translation lookaside buffers
Activity 1
Concrete examples of virtual memory systems
▪ “Simple memory system” from CSAPP 9.6.4
▪ Intel Core i7
Activity 2
Nifty things virtual memory makes possible
▪ Paging/swapping (disk as extra RAM)
▪ Memory-mapped files (RAM as cache for disk)
▪ Copy-on-write sharing
Activity 3
Level 1 Level 2
1 allocated page
page table page tables VP 1048576
for the stack
Page table
base register
(PTBR)
VIRTUAL ADDRESS
n-1 p-1 0
VPN 1 VPN 2 ... VPN k VPO
PP
N
m-1 p-1 0
PPN PPO
PHYSICAL ADDRESS
Page table
base register
(PTBR)
VIRTUAL ADDRESS
n-1 p-1 0
VPN 1 VPN 2 ... VPN k VPO
PP
N
TLB Hit
CPU Chip
TLB
2 PTE
VPN 3
1
VA PA
CPU MMU
4 Cache/
Memory
Data
5
TLB Miss
CPU Chip
TLB
4
2 PTE
VPN
1 3
VA PTEA
CPU MMU
Cache/
PA Memory
5
Data
6
Today
Multi-level page tables
Translation lookaside buffers
Activity 1
Concrete examples of virtual memory systems
▪ “Simple memory system” from CSAPP 9.6.4
▪ Intel Core i7
Activity 2
Nifty things virtual memory makes possible
▪ Paging/swapping (disk as extra RAM)
▪ Memory-mapped files (RAM as cache for disk)
▪ Copy-on-write sharing
Activity 3
VPN VPO
Virtual Page Number Virtual Page Offset
11 10 9 8 7 6 5 4 3 2 1 0
PPN PPO
Physical Page Number Physical Page Offset
1 0 1 1 0 1 1 0 1 0 0 1
PPN PPO
Idx Tag Valid B0 B1 B2 B3 Idx Tag Valid B0 B1 B2 B3
0 19 1 99 11 23 11 8 24 1 3A 00 51 89
1 15 0 – – – – 9 2D 0 – – – –
2 1B 1 00 02 04 08 A 2D 1 93 15 DA 3B
3 36 0 – – – – B 0B 0 – – – –
4 32 1 43 6D 8F 09 C 12 0 – – – –
5 0D 1 36 72 F0 1D D 16 1 04 96 34 15
6 31 0 – – – – E 13 1 83 77 1B D3
7 16 1 11 C2 DF 03 F 14 0 – – – –
0 0 0 0 1 1 1 1 0 1 0 1 0 0
VPN VPO
0x0F
VPN ___ 0x3 TLBT ____
TLBI ___ 0x03 Y
TLB Hit? __ N
Page Fault? __ 0x0D
PPN: ____
Set Tag PPN Valid Tag PPN Valid Tag PPN Valid Tag PPN Valid
TLB
0 03 – 0 09 0D 1 00 – 0 07 02 1
1 03 2D 1 02 – 0 04 – 0 0A – 0
2 02 – 0 08 – 0 06 – 0 03 – 0
3 07 – 0 03 0D 1 0A 34 1 02 – 0
Physical Address
11 10 9 8 7 6 5 4 3 2 1 0
0 0 1 1 0 1 0 1 0 1 0 0
PPN PPO
Processor package
Core x4
Instruction MMU
Registers
fetch (addr translation)
Main memory
32/64
CPU L2, L3, and
Result
Virtual address (VA) main memory
36 12
VPN VPO L1 L1
hit miss
32 4
TLBT TLBI
L1 d-cache
TLB (64 sets, 8 lines/set)
hit
TLB ...
...
miss
L1 TLB (16 sets, 4 entries/set)
9 9 9 9 40 12 40 6 6
VPN1 VPN2 VPN3 VPN4
PPN PPO CT CI CO
Physical
CR3 address
PTE PTE PTE PTE (PA)
Page tables
63 62 52 51 12 11 9 8 7 6 5 4 3 2 1 0
XD Unused Page table physical base address Unused G PS A CD WT U/S R/W P=1
63 62 52 51 12 11 9 8 7 6 5 4 3 2 1 0
XD Unused Page physical base address Unused G D A CD WT U/S R/W P=1
9 9 9
VPN 1 VPN 2 VPN 3 VPN 4
9 12
VPO
Virtual
address
L1 PT L2 PT L3 PT L4 PT
Page global Page upper Page middle Page
40 directory 40 directory 40 directory 40 table
CR3 / / / /
Physical
address Offset into
of L1 PT / 12 physical and
L1 PTE L2 PTE L3 PTE L4 PTE virtual page
Physical
address
512 GB 1 GB 2 MB 4 KB of page
region region region region
per entry per entry per entry per entry
40
/
40 12
PPN PPO
Physical
address
40 6 6
Physical CT CI CO
address
(PA) PPN PPO
Address No
Translation Change
Virtual
CI
address
(VA)
VPN VPO L1
36 12 Cache
Observation
▪ Bits that determine CI identical in virtual and physical address
▪ Can index into cache while address translation taking place
▪ Generally we hit in TLB, so PPN bits (CT bits) available quickly
▪ “Virtually indexed, physically tagged”
▪ Cache carefully sized to make this possible
Today
Multi-level page tables
Translation lookaside buffers
Activity 1
Concrete examples of virtual memory systems
▪ “Simple memory system” from CSAPP 9.6.4
▪ Intel Core i7
Activity 2
Nifty things virtual memory makes possible
▪ Paging/swapping (disk as extra RAM)
▪ Memory-mapped files (RAM as cache for disk)
▪ Copy-on-write sharing
Activity 3
Consequences
▪ Large page (block) size: 4KB and bigger
▪ Always write-back and fully associative
▪ Managed entirely in software
▪ Plenty of time to execute complex replacement algorithms
Memory-Mapped Files
Paging = every page of a program’s physical RAM is
backed by some page of disk*
Normally, those pages belong to swap space
But what if some pages were backed by … files?
Memory-Mapped Files
Process Physical
virtual memory memory
Swap space
File on disk
Memory-Mapped Files
Swap space
File on disk
Copy-on-write sharing
fork creates a new Parent Physical
virtual memory memory
process by copying the
entire address space
of the parent process Swap space
▪ That sounds slow
▪ It is slow File on disk
Clever trick:
▪ Just duplicate the page tables
▪ Mark everything read only
▪ Copy only on write faults
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 30
Carnegie Mellon
Copy-on-write sharing
Child Parent Physical
virtual memory virtual memory memory
Swap space
File on disk
Clever trick:
▪ Just duplicate the page tables
▪ Mark everything read only
▪ Copy only on write faults
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 31
Carnegie Mellon
Copy-on-write sharing
Child Parent Physical
virtual memory virtual memory memory
Clever trick:
▪ Just duplicate the page tables
▪ Mark everything read only
▪ Copy only on write faults
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 32
Carnegie Mellon
Today
Multi-level page tables
Translation lookaside buffers
Activity 1
Concrete examples of virtual memory systems
▪ “Simple memory system” from CSAPP 9.6.4
▪ Intel Core i7
Activity 2
Nifty things virtual memory makes possible
▪ Paging/swapping (disk as extra RAM)
▪ Memory-mapped files (RAM as cache for disk)
▪ Copy-on-write sharing
Activity 3