CS162 Operating Systems and Systems Programming Page Allocation and Replacement
CS162 Operating Systems and Systems Programming Page Allocation and Replacement
Lec 15.2
Lec 15.3
Software-Loaded TLB
MIPS/Nachos TLB is loaded by software
Lec 15.4
Faulting
Inst 2
Faulting
Inst 2
User
Faulting
Inst 1
Faulting
Inst 1
Transparent Exceptions
TLB Faults
OS
Load TLB
Fetch page/
Load TLB
has side-effects?
What if an instruction
Kubiatowicz CS162 UCB Fall 2009
10/21/09
Lec 15.5
bne somewhere
ld r1,(sp)
Precise exception state consists of two PCs: PC and nPC
Delayed exceptions:
10/21/09
Precise
Exceptions
Precise state of the machine is preserved as if
program executed up to the offending instruction
Lec 15.7
10/21/09
Lec 15.8
Example:
EAT
= (1 p) x 200ns + p x 8 ms
= (1 p) x 200ns + p x 8,000,000ns
= 200ns + p x 7,999,800ns
If one access out of 1,000 causes a page fault, then
EAT = 8.2 s:
This is a slowdown by a factor of 40!
Lec 15.9
Capacity Misses:
Conflict Misses:
Policy Misses:
MIN (Minimum):
RANDOM:
10/21/09
Lec 15.11
Replace page that hasnt been used for the longest time
Programs have locality, so if something not used for a
while, unlikely to be used in the near future.
Seems like LRU should be a good approximation to MIN.
Page 6
Page 7
Page 1
Page 2
Tail (LRU)
In practice, people
approximate
(more later)
10/21/09
Kubiatowicz
CS162 UCBLRU
Fall 2009
Lec 15.12
Administrivia
Exam not graded yet
Hopefully get it back to you in section on Tuesday
Will get solutions up early next week
Project II
Due by Friday at midnight
Good Luck!
In the news: Sunday (10/18)
First use of On Star to recover stolen vehicle
Two guys carjacked in 2009 Chevy Tahoe
On Star locates vehicle and while police chasing it, give command
to SUV to slow down
On Star operator flashed lights first so that police could make sure
that they had correct car
Hapless crook tries to escape on foot, falls in swimming pool
10/21/09
Example: FIFO
Suppose we have 3 page frames, 4 virtual pages, and
following reference stream:
A B C A B D A D B C B
2
3
D
B
C
A
FIFO: 7 faults.
When referencing D, replacing A is bad choice, since need
10/21/09A again right away
Kubiatowicz CS162 UCB Fall 2009
Lec 15.15
Example: MIN
Suppose we have the same reference stream:
A B C A B D A D B C B
C
B
MIN: 5 faults
Where will D be brought in? Look for page not referenced
farthest in future.
10/21/09
Same
CS162
UCB
Fall 2009
decisions asKubiatowicz
MIN here,
but
wont
always be true!
Lec 15.16
D
B
3
10/21/09
C
A
Page:
Ref: A
B
C is D
A fault!
B
C
reference
a page
Every
C
A
B
C
CKubiatowicz
D
Lec 15.17
10/21/09
Lec 15.18
E
B
3
4
D
A
C
B
Ref:
Page:
E
B
Implementing LRU
Perfect:
Details:
On page fault:
bits set,
will
eventually
Even if all use
Kubiatowicz
CS162
UCB
Fall 2009 loop aroundFIFO
Lec 15.20
How do we pick N?
10/21/09
Lec 15.23
When clock hand passes by, reset use and modified bits
and mark page as invalid again
10/21/09
Lec 15.24
w
lo
rf
ve
O
Marked: RW
List: FIFO
ss
e
c
c
A
Page-in
From disk
New
Active
Pages
LRU victim
Second
Chance List
Marked: Invalid
List: LRU
New
SC
Victims
If 0 FIFO
If all LRU, but page fault on every page reference
10/21/09
Lec 15.26
Free
List
Single
Clock
Hand:
Advances as needed to keep
freelist full (background)
D
D
Free Pages
For Processes
10/21/09
Lec 15.27
Core Map
Page tables map virtual page physical page
Do we need a reverse mapping (i.e. physical page
virtual page)?
Yes. Clock algorithm runs through page frames. If sharing,
then multiple virtual-pages per physical page
Cant push page out to disk without invalidating all PTEs
10/21/09
Lec 15.28
Summary
Precise Exception specifies a single instruction for
which:
Replacement policies