Virtual Memory
1
Virtual Memory 1 Learning to Play Well With Others (Physical) - - PowerPoint PPT Presentation
Virtual Memory 1 Learning to Play Well With Others (Physical) Memory malloc(0x20000) 0x10000 (64KB) Stack Heap 0x00000 Learning to Play Well With Others (Physical) Memory 0x10000 (64KB) Stack Stack Heap Heap 0x00000 Learning to Play
1
0x00000 0x10000 (64KB) Stack Heap (Physical) Memory malloc(0x20000)
Stack Heap (Physical) Memory Stack Heap 0x00000 0x10000 (64KB)
Stack Heap Virtual Memory 0x00000 0x10000 (64KB) Physical Memory 0x00000 0x10000 (64KB) Stack Heap Virtual Memory 0x00000 0x10000 (64KB)
Stack Heap Virtual Memory 0x00000 0x400000 (4MB) Physical Memory 0x00000 0x10000 (64KB) Stack Heap Virtual Memory 0x00000 0xF000000 (240MB) Disk (GBs)
physical addresses.
6
Physical Address Space Virtual Address Space 232 - 1 230 – 1 (or whatever) Stack We need to keep track of this mapping… Heap
8
Virtual Page Number Page Offset (log(page size)) Virtual address (32 bits) Physical address (32 bits) Page Offset (log(page size)) Virtual-to-physical map Physical Page Number
9
10
11
12
Level 1 Page Table Level 2 Page Tables
Data Pages
Parts of the map that exist Root of the Current Page Table
p1
p2
Virtual Address (Processor Register)
Parts that don’t p1 p2 offset
11 12 21 22 31
10-bit L1 index 10-bit L2 index
Adapted from Arvind and Krste’s MIT Course 6.823 Fall 05
14
15
to access it very quickly (i.e., in one clock cycle)
lookaside buffer” or “TLB”
16
walkers” -- specialized state machines that can load page table entries into the TLB without OS intervention
big-A architecture.
its own format.
17
CPU Physical Cache TLB Primary Memory VA PA CPU VA Virtual Cache PA TLB Primary Memory
different physical address.
write to the copy, and do the actual copy lazily.
20
Virtual address space char * A My Big Data memcpy(A, B, 100000) Physical address space My Big Data memcpy(A, B, 100000) char * B; My Empty Buffer Virtual address space char * A My Big Data Physical address space My Big Data char * B; Un- writeable copy By Big Empty Buffer
Two virtual addresses pointing the same physical address
maps to a different physical address.
21
A A 0x1000 0x2000 Address Data Cache 0x1000 0xfff0000 0x2000 0xfff0000 Page Table B A 0x1000 0x2000 Address Data Cache 0x1000 0xfff0000 0x2000 0xfff0000 Page Table
22
Solution (4): Virtually indexed physically tagged
Index L is available without consulting the TLB ⇒ cache and TLB accesses can begin simultaneously Critical path = max(cache time, TLB time)!!! Tag comparison is made after both accesses are completed Work if Cache Size ≤ Page Size ( C ≤ P) because then all the cache inputs do not need to be translated
VPN L = C-b b
TLB
Direct-map Cache Size 2C = 2L+b PPN Page Offset
hit? Data Physical Tag Tag VA PA “Virtual Index”
P
Adapted from Arvind and Krste’s MIT Course 6.823 Fall 05
key idea: page offset bits are not translated and thus can be presented to the cache immediately
go back.
24
data in physical ram.
25
Level 1 Page Table Level 2 Page Tables
Data Pages
page in primary memory page on disk Root of the Current Page Table
p1
p2
Virtual Address (Processor Register)
PTE of a nonexistent page p1 p2 offset
11 12 21 22 31
10-bit L1 index 10-bit L2 index
Adapted from Arvind and Krste’s MIT Course 6.823 Fall 05
27