Professional Documents
Culture Documents
15 VirtualMemory PDF
15 VirtualMemory PDF
Address Translation
Review
2
Virtual Memory
Concept
(fMAX-1,oMAX-1)
Physical memory partitioned into equal sized
page frames
¾ Page
g frames avoid external fragmentation.
g
(f,o)
A memory address is a pair (f, o)
f — frame number (fmax frames) o
o — frame offset (omax bytes/frames)
Physical address = omax×f + o Physical
Memory
f
PA:
log2 (fmax × omax) log2 omax 1
f o
(0,0) 4
Physical Address Specifications
Frame/Offset pair v. An absolute index
o
3 6
Physical
Memory
PA: 0000011000000110
16 10 9 1 f
1,542
(0,0) 0
Questions
6
Realizing Virtual Memory
Paging
2n-1 =
(pMAX-1,oMAX-1)
A process’s virtual address space is
partitioned into equal sized pages
¾ page = page frame
(p,o)
o
A virtual address is a pair (p, o)
p — page number (pmax pages) Virtual
o — page offset (omax bytes/pages)
Address
Virtual address = omax×p + o
Space
p
VA:
log2 (pmax×omax) log2 oMAX 1
p o (0,0) 7
Paging
Mapping virtual addresses to physical addresses
Physical
(p2,o2) Memory
(p1,o1)
(f2,o2)
8
Frames and pages
Paging
Virtual address translation
CPU
P’s p o f o
Virtual Physical
Address 20 10 9 1 16 10 9 1
Memory
Space
Virtual
Addresses
Add Physical
(p,o)
Addresses
f
Page Table 10
Virtual Address Translation Details
Page table structure
CPU
p o f o
20 10 9 1 16 10 9 1
Virtual
Addresses Physical
Addresses
PTBR + 010 f
Page Table 11
10000000
01100100
(0,0)
Page Table 12
Virtual Address Translation
Performance Issues
Page table can be very large; a part of the page table can be on
disk.
¾ For a machine with 64-bit addresses and 1024 byte pages, what is
the size of a page table?
What to do?
¾ Most computing problems are solved by some form of…
Caching
Indirection
13
p o
Virtual
20 10 9 1
Addresses ?
Key Value
p f f
TLB p
X Page Table 14
Dealing With Large Page Tables
Multi-level paging
Virtual Address p2
p1 p2 p3 o
p3
p1
Third-Level
First-Level Page Tables
Page Table
15
CPU Memory
p1 p2 o f o
Virtual Physical
20 16 10 1
Addresses Addresses 16 10 1
First-Level Second-Level
Page Table Page Table
16
The Problem of Large Address Spaces
Use one entry for each physical page with a hash table
¾ Size of translation table occupies a very small fraction of physical
memory
¾ Size of translation table is independent of VM size
17
18
Page Registers
How does a virtual address become a physical address?
19
CPU Memory
Virtual
p o Address PID f o
Physical
running
g Addresses
20 9 1 16 9 1
tag check
Hash =? =?
fmax– 1
PTBR + PID page 0 1 1 fmax– 2
h(PID, p)
0
Inverted Page Table 20
Searching Inverted Page Tables
Using Hash Tables
21
Minor complication
¾ Since the number of pages is usually larger than the number of
slots in a hash table, two or more items may hash to the same
l
location
ti
22
Questions
23
Data
A process’s VAS is its context
¾ Contains its code, data, and stack
Stack
Code pages are stored in a user’s
user s file on disk
¾ Some are currently residing in memory; most are
not
OS/MMU
Physical
Memory
24
Virtual Memory
Page fault handling Physical
Memory
Disk
25
Example:
¾ Memory access time: 60 ns
¾ Disk access time: 25 ms
¾ Let p = the probability of a page fault
¾ EAT = 60(1–p)
( p) + 25,000,000p
, , p
26
Vista reading from the pagefile
27
28
Virtual Memory
Summary
29
30