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 0x10000 (64KB) Stack Heap 0x00000 Learning to Play Well With Others (Physical) Memory malloc(0x20000) 0x10000 (64KB) Stack Heap 0x00000 Learning to Play Well With
1
0x00000 0x10000 (64KB) Stack Heap (Physical) Memory
0x00000 0x10000 (64KB) Stack Heap (Physical) Memory malloc(0x20000)
0x00000 0x10000 (64KB) Stack Heap (Physical) Memory malloc(0x20000)
Stack Heap (Physical) Memory 0x00000 0x10000 (64KB)
Stack Heap (Physical) Memory 0x00000 0x10000 (64KB)
Stack Heap (Physical) Memory Stack Heap 0x00000 0x10000 (64KB)
Stack Heap (Physical) Memory Stack Heap 0x00000 0x10000 (64KB)
Stack Heap Virtual Memory 0x00000 0x10000 (64KB) Stack Heap Virtual Memory 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 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
heap is at the “bottom”
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
maps to a different physical address.
20
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
write to the copy, and do the actual copy lazily.
21
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
write to the copy, and do the actual copy lazily.
21
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
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 the size of one cache way ≤ Page Size because then none of the cache inputs need to be translated (i.e., the index bits in physical and virtual addresses are the same)
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
key idea: page offset bits are not translated and thus can be presented to the cache immediately
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
Stack Heap
1GB
8GB Stack Heap (Physical) Memory
§ We need to make it appear that there is more memory than there is in a system
– Allow many programs to be “running” or at least “ready to run” at
– Absorb memory leaks (sometimes... if you are programming in C or C ++)
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
26
apps
27
28
data in physical ram.
data in physical ram.
30