Virtual Memory
Virtual Memory
Virtual Memory
Muhammad Tahir
Lecture 22-23
Contents
2 Address Translation
2/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
3/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
4/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
PA Page
VA MMU Tables
CPU
Trap Cache
Data
Data
5/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
D Disk
6/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
Address Translation
Address
Translation Translation
11 0 Physical
Physical page number Page offset Address
Physical Address
7/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
31 12 11 0 Virtual Address
Virtual page number Page offset (from Processor)
20 12
Page Table
8/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
31 10
0
Valid
Readable
Writeable
Executeable
User Mode
Global
Accessed
Dirty
Reserved by Software
10/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
11/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
• Example
• Virtual memory = 4GB, Page size = 4KB, Size of entry is 4B.
4MB Page table/process
• Some processes may actually be smaller than 4MB but their
page table is 4MB!
• How big would the page table be for a 64-bit machine?
12/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
13/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
14/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
15/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
1 0x23F1
1 0x23F1 0
0011 0x23F1
0x23F1
1 0x23F1 1
1 00 0x7FFE
11 0 0x7FFE
0x7FFE 2
V Page Table Addreess 0 1 0x7FFE
0 1 0x7FFE
0 0x1003 0000 .
0 0 .
1 0x40000 00 0 .. .
0 0 . ...
0 . . ..
0
. 0x0073. . . .
00 0x0073
1100 0x0073. .
. First- 0 0x0073..
1
0 1 0x0073
. Level 0 1 0x0073
PTBR + 0x0073
0
Page 0 00 0x72FC
0 0x72FC
0
0 Table 0
11 0 0x72FC
0 0x72FC
1 0x2375000 0011 0x72FC
0x72FC
1 0x72FC Second-
0 00
00 0 Level
00 00x00C1
0x00C1 Page
0
255 1 00 0x00C1 Table 4094
11 0 0x00C1
0x00C1
11 0x00C1
0x00C1 4095
10
15
Physical
0x23F1 FB0
Address
16/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
PTBR +
PTE +
PTE + . . . . . . . . . . . . . . +
Physical Page Number offset
PTE
Physical Address
17/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
Virtual Address 31 12 0
(from Processor) Virtual page number Page offset
12
Virtual Address
(from Processor)
32
31 12 0
Virtual page number Page offset Physical page number Page offset
12 Physical Address
Tag Index
TLB VD Tag Physical page number 31 14 4 20
18 10 2 (word offset)
=
=
TLB =
= Line V D Tag Data (16 byte block)
Hit No.
= 0
= 1
=
. . .
. . .
. . .
=
1022
1023
32 Data
Hit
19/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
TLB access
TLB miss
exception No Yes
TLB hit?
Protection
Page Table
Access Check Access
"Walk"
Denied Permitted
Physical
Page not Page in Address
in Mem Mem Protection Fault No Yes
Page Fault Write?
Update TLB
(OS loads page)
SIGSEGV
Write Yes
No
Find in Disk Find in mem Try to read access bit
data from on?
cache Write protection
exception Try to write
data to cache
Deliver data
to the CPU write data into cache, update
the dirty bit, and put the data
and the address into the write
buffer
20/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
Data
Trap
21/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
(from Processor)
31 12 0
Direct-map Cache
2L Blocks
TLB
2b-byte block
31 12 0
Tag
==
Physical Tag
Hit/Miss Data
22/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
OS
User1 VA1 pages
Page table
User2 VA2
Page table
Page table
23/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
Suggested Reading
24/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
Acknowledgment
25/26
Why Use Virtual Memory? Address Translation Page Table Size TLB & Virtual Cache
References
26/26