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
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
different physical address.
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
different physical address.
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
VA1 and VA2 are aliases,
VA2 mod (cache size)
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
24
VPN a Page Offset b
TLB
PPN Page Offset b Tag
VA PA Virtual Index L1 VA cache
=
hit? PPNa Data PPNa Data VA1 VA2
Direct-Mapped PA L2
PA a1 Data PPN
into L2 tag
already in L1, L2 (VA1 ≠ VA2)
detected in L2 because the a1 bits don’t match.
loaded ⇒ no aliasing !
Once again, ensure the invariant that only one copy of physical address is in virtually-addressed L1 cache at any one time. The physically-addressed L2, which includes contents of L1, contains the missing virtual address bits that identify the location of the item in the L1. (could be associative too, just need to check more entries)
Adapted from Arvind and Krste’s MIT Course 6.823 Fall 05
go back.
26
Base of Table
hash Offset
PA of Slot
Primary Memory
VPN PPN
Page Table
VPN d 80-bit VA
VPN
searched sequentially
used to look in another slot (“rehashing”) All these steps are done in hardware!
number of physical pages
Adapted from Arvind and Krste’s MIT Course 6.823 Fall 05
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
29
apps
30
disk
31
data in physical ram.
data in physical ram.
33
34
Fast/non-dense/volatile memory Slower/denser/non-volatile memory Physical Address Space Really slow, really dense (Disk/SSD) Buffer cache VA space 1 VA space 2
state
using loads and stores)?
35
for volatile data.
slower.
36