Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Virtual Memory
What is the size limit of a process
Does it have to be smaller than physical memory
Not really
Not all parts of the process have to be in memory
Memory Hierarchy
Cache
Memory
Disk (swap space, not files)
Down the hierarchy
Decreasing cost
Increasing capacity and access time
Addressing
How to map a logical address to a physical address?
How to know where the page is?
Page table
Need a page table to keep track of the pages of a process
In cache, or memory, or disk
Performance metrics
Time for each memory access (time for page table lookup)
Number of page faults in a time unit
miss
Is it in
Memory?
hit
Fetch the page
from memory
to cache
Memory
Access time = 100 ns
Hit rate = 99.9%
Disk
Access time = 100s
Memory
Access time = 100 ns
Store in disk
Terrible access performance
Offset
yes
Reference
OS init I/O to
bring the page
from disk to memory
Checks PT
in Memory
Checks
cache
Page
in cache
no
Page in
Memory
yes
no
CPU switch
to another
process
I/O transfer
page to
memory
Update
Replace
page table memory page
in memory if necessary
Bring page to cache
Point to PPT
Entry 0 - 1023
Point to page 0
Point to page 1
Point to PPT
Entry 1024 - 2047
Point to PPT
Entry 2048 - 3071 null
Point to PPT
Last 1024 entries
Frame 1
Frame 2
Frame 3
Frame 4
noncontiguous
Frame 5
Frame 6
4K entries
Frame 0
1K entries
contiguous
contiguous
null
p#
Frame #
Offset
Offset
Physical
Address
Root
Page Table
Partial
Page Table
Block
Page
Frame
Frame #
Main Memory
Addressing in Two-Level PT
Addressing
4GB address space, 1KB per page 4M pages
Root page table has 16K entries
Use 14 bits for addressing the root page table
00000000000010000010100000101011
Root table page number = 10 = 2
Partial Page block index = 1010 = 10
Page offset = 101011
00000000000000000101010000101011
Frame number = 21 = 10101
0
1
2
9
10
0
1
2
7
40
1
P.512
P.513
P.514
9 15
10 21
P.521
P.522
Addressing in IPT
page #
hash
offset
frame #
pid 1, page 2
pid 0, page 4
pid 1, page 0
pid 2, page 1
pid 8, page 7
pid 4, page 6
pid 0, page 5
pid 4, page 8
Main Memory
15
2
5
3, 0
2
6
23
12
miss
IPT
hit
Hash table
offset
Addressing in IPT
Addressing
Given (process#, page#) tuple
Locate the corresponding physical frame
Addressing in IPT
Example 2: Find frame number for (1, 2)
h(1, 2) = 0001 0010 = 0011 = 3
hashtable[3] = 3, 0
IPT[3] = (2,1) does not match
IPT[0] = (1,2) Got the match
(process 0, page 5) is also in memory frame 0
Addressing in IPT
Example 3: Find frame number (8, 9)
h(8, 9) = 1000 1001 = 0001 = 1
hashtable[1] = 2
IPT[2] = (1,0) does not match
(process 0, page 1) is not in memory
Issue a page fault
Comparator
Frame #
Comparator
Frame #
If it is too big
May have lower level of concurrency
Memory
Page size = 1K bytes; size(int) = 1 word = 4 bytes
Program and x, y, i, and j are stored in one page
A[0,0]-A[0,127], A[1,0]-A[1,127] in a page
B[0,0]-B[0,127], B[1,0]-B[1,127] in a page
Global
There is no need to consider working set size for each process
May replace any page in the memory
Policies
First-in-first-out policy (FIFO)
Least recently used policy (LRU)
Clock policy
Modified clock policy
Aging policy
Clock Policy
Pointer mrp
points to the most recently loaded page
Flag used
indicates whether a page has been used recently
Page replacement
Scan from mrp, find the first page with used = 0
mrp points to the page next to the most recently loaded page
Principle
Same as clock
First try to find an used = 0 page
Among them, dirty = 0 should be considered first
012|0
012|2
012|3
123|0
230|6
306|3
306|
012|0
120|2
102|3
023|0
230|6
306|3
063|
Most recently used
2* 0 1 | 0
6* 0 3 | 3
0* 1* 5* | 4
2* 0* 1 | 2
6* 0 3* |
|
1w
page
0*
|
Scan and find page with (used=0, dirty=0)
4x Policy
1x 0* Write
| 2 represents
page
page4 1back
selected
to disk, replace it
Modified
Clock
(x
modified)
Page 0 selected
|
1*xwrite
2* 0page
| 1 to disk
4*x 1x 5 | 4x 2* 0*
0*
| 1w
0*
1*x 5* | 4w
2*
0* | 1w
0*
1*x
|5
4*x 1x
0*
1*x 5* | 0
4*x 1x
0* | 2
1*x 2*x 0
0*
1*x 5* | 1w
4x
0* | 0
1x
2*
|0
4x
1*x 2*
2x
| 2w
|4
4* |
Load Control
How many processes should reside in memory
In global policy, this cannot be controlled by working set size
Aging policy
Consider an aging vector
Increase the aging vector whenever the page is accessed
System periodically scan the aging vector and reduce its
value
A page is to be removed if it reaches 0
Does not need to actually remove till receiving a replacement
request
Other Issues in VM
Protection
How to ensure that each process access its own memory
Is it a problem in virtual memory?
Why there are access violations?
How about the buffer overflow attacks?
Frame Locking
Lock pages that cannot be replaced
e.g. OS code and data
Readings
Sections 1.5, 1.6
Sections 8.1, 8.2