SLIDE 3 3
Goals of Replacement P
Per f or mance
Best t o evict a page t hat will never be accessed again if
possible
I f not possible, evict page t hat won’t be used f or t he
longest t ime
How can we best predict t his?
Fair ness
When OS divides up t he available memory among
processes, what is a f air way t o do t hat ?
- Same amount t o ever yone? Well some pr ocesses may not
need t hat amount f or t heir wor king set while ot her s ar e paging t o disk const ant ly wit h t hat amount of memory
- Give each process it s working set ?
As long as enough memory f or each process t o have it s
working set resident t hen everyone is happy
- I f not how do we resolve t he conf lict ?
- 14
P age replacement algorit hms
Remember all t he dif f erent CP
U scheduling algorit hms t he OS could use t o choose t he next j ob t o run
Similarly, t here are many dif f erent
algor it hms f or picking which page t o kick
- ut when you have t o br ing in a new page
and t her e is no f r ee DRAM lef t
Goal?
Reduce t he over all syst em page f ault r at e? Balance page f ault r at es among pr ocesses? Minimize page f ault s f or high pr ior it y j obs?
Belady’s Algorit hm
Evict t he page t hat won’t be used again f or
t he longest t ime
Much like Short est J obFirst! Has provably opt imal lowest page f ault rat e Dif f icult t o predict which page won’t be
used f or a while
Even if not pr act ical can use it t o compar e
- t her algor it hms t oo
- 16
First -I n-First -Out (FI FO)
Evict t he page t hat was inser t ed t he longest t ime
ago
When page in put on t ail of list Evict head of list
I s is always (usually) t he case t hat t he t hing
accessed t he longest t ime ago will not be accessed f or a long t ime?
What about t hings accessed all t he t ime! FI FO suf f er s an int er est ing anomaly (Belady’s
Anomaly)
I t is possible t o increase t he page f ault rat e by
increasing t he amount of available memory
Least -Recent ly Used (LRU)
I dea: t he past is a good pr edict or of t he f ut ur e
P
age t hat we haven’t used f or t he longest t ime likely not t o be used again f or longest t ime
I s past a good predict or
- Gener ally yes
- Can be exact ly t he wrong t hing! Consider st reaming access
To do t his r equir es keeping a hist or y of past
accesses
To be exact LRU would need t o save a t imest amp on each
access (I .e. writ e t he P TE on each access!)
Too expensive!
Approximat ing LRU
Remember t he r ef er ence bit in t he PTE
Set if read or writ t en
At some r egular int er val (much much less of t en
t han f or each access) clear all t he r ef er ence bit s
Only P
TE wit hout t he ref bit clear are eligible f or evict ion Mor e t han 1 bit of st at e?
Associat e some number of count er bit s At regular int erval, if ref bit is 0 increment count er and
if ref bit is 1 t hen zero count er
Count er t ells you # int ervals since t he last ref erence More bit s you give t o count er = more accurat e
approximat ion