Page Replacement Algorithms. Load pages into memory only when a page fault occurs. Place pages anywhere no placement policy required

Size: px
Start display at page:

Download "Page Replacement Algorithms. Load pages into memory only when a page fault occurs. Place pages anywhere no placement policy required"

Transcription

1 Pg Rplmnt Algorithms Virtul Mmory Mngmnt Funmntl issus : A Rp Ky onpt: Dmn pging Lo pgs into mmory only whn pg fult ours Usr Progrm n Issus: Plmnt strtgis Pl pgs nywhr no plmnt poliy rquir Rplmnt strtgis Wht to o whn thr xist mor jos thn n fit in mmory Lo ontrol strtgis Dtrmining how mny jos n in mmory t on tim... Usr Progrm Usr Progrm Oprting Systm Mmory

2 Pg Rplmnt Algorithms Conpt Typilly Σ i VAS i >> Physil Mmory With mn pging, physil mmory fills quikly Whn pross fults & mmory is full, som pg must swpp out Hnling pg fult now rquirs isk sss not! Though writs r mor ffiint thn rs (why?) Whih pg shoul rpl? Lol rplmnt Rpl pg of th fulting pross Glol l rplmnt Possily rpl th pg of nothr pross Pg Rplmnt Algorithms Evlution mthoology Ror tr of th pgs ss y pross Exmpl: (Virtul) rss tr... (,), (,9), (4,), (,), (5,), (,), (,9), (,4), (,), (4,8) gnrts pg tr,, 4,, 5,,,,, 4 (rprsnt s,,,,,,,,, ) Hrwr n tll OS whn nw pg is lo into th TLB St us it in th pg tl ntry Inrmnt or shift rgistr Simult th hvior of pg rplmnt lgorithm on th tr n ror th numr of pg fults gnrt fwr fults ttr prformn 4

3 Optiml Pg Rplmnt Clirvoynt rplmnt Rpl th pg tht won t n for th longst tim in th futur Tim Rqusts Pg Frms Fults Tim pg n nxt 5 Optiml Pg Rplmnt Clirvoynt rplmnt Rpl th pg tht won t n for th longst tim in th futur Tim Rqusts Pg Frms Fults Tim pg n nxt = 7 = 6 = 9 = = 5 = = = 4 6

4 Lol Pg Rplmnt FIFO rplmnt Simpl to implmnt A singl pointr suffis Physil Mmory Prformn with 4 pg frms: Frm List Tim Rqusts Pg Frms Fults Lol Pg Rplmnt FIFO rplmnt Simpl to implmnt A singl pointr suffis Physil Mmory Prformn with 4 pg frms: Frm List Tim Rqusts Pg Frms Fults 8

5 Lst Rntly Us Pg Rplmnt Us th rnt pst s pritor of th nr futur Rpl th pg tht hsn t n rfrn for th longst tim Tim Rqusts Pg Frms Fults Tim pg lst us 9 Lst Rntly Us Pg Rplmnt Us th rnt pst s pritor of th nr futur Rpl th pg tht hsn t n rfrn for th longst tim Tim Rqusts Pg Frms Fults Tim pg lst us = = 4 = = = 7 = 8 = 5 = = 7 = 8 = 5 = 9

6 Lst Rntly Us Pg Rplmnt Implmnttion Mintin stk of rntly us pgs Tim Rqusts Pg Frms Fults LRU pg stk Pg to rpl Lst Rntly Us Pg Rplmnt Implmnttion Mintin stk of rntly us pgs Tim Rqusts Pg Frms Fults LRU pg stk Pg to rpl

7 Wht is th gol of pg rplmnt lgorithm? A. Mk lif sir for OS implmntr B. Ru th numr of pg fults C. Ru th pnlty for pg fults whn thy our D. Minimiz CPU tim of lgorithm Approximt LRU Pg Rplmnt Th Clok lgorithm Mintin irulr list of pgs rsint in mmory Us lok (or us/rfrn) it to trk how oftn pg is ss Th it is st whnvr pg is rfrn Clok hn swps ovr pgs looking for on with us it = Rpl pgs tht hvn t n rfrn for on omplt rvolution of th lok Pg 7: Pg : 5 Pg 4: Pg : rsint it us it frm numr Pg : 4 fun Clok_Rplmnt gin whil (vitim pg not foun) o if(us it for urrnt pg = ) thn rpl urrnt pg ls rst us it n if vn lok pointr n whil n Clok_Rplmnt 4

8 Clok Pg Rplmnt Exmpl Rqusts Tim Fults Pg Frms q 5 Fults Pg tl ntris for rsint pgs: Clok Pg Rplmnt Exmpl Rqusts Tim Fults Pg Frms q 6 Fults Pg tl ntris for rsint pgs:

9 Optimizing Approximt LRU Rplmnt Th Son Chn lgorithm Thr is signifint ost to rpling irty pgs Moify th Clok lgorithm to llow irty pgs to lwys surviv on swp of th lok hn Us oth th irty it n th us it to riv rplmnt Pg 7: Pg : 5 Pg 4: Pg : rsint it us it irty it 9 Pg : 4 Son Chn Algorithm Bfor lok swp us irty Aftr lok swp us irty rpl pg 7 Th Son Chn Algorithm Exmpl Tim Rqusts w 4 w w 8 9 Pg Frms Fults Pg tl ntris for rsint pgs: * * * * * * * 8

10 Th Son Chn Algorithm Exmpl Tim Rqusts w 4 w w 8 9 Pg Frms Fults Pg tl ntris for rsint pgs: * * * 9 Th Prolm With Lol Pg Rplmnt How muh mmory o w llot to pross? Tim Rqusts Pg Frms Fults Pg Frms Fults

11 Th Prolm With Lol Pg Rplmnt How muh mmory o w llot to pross? Tim Rqusts Fults Pg Frms Pg Frms Fults Pg Rplmnt Algorithms Prformn Lol pg rplmnt LRU Ags pgs s on whn thy wr lst us FIFO Ags pgs s on whn thy r rought into mmory Towrs glol pg rplmnt... with vril numr of pg frms llot to prosss Th prinipl of lolity 9% of th xution of progrm is squntil Most itrtiv onstruts onsist of rltivly smll numr of instrutions Whn prossing lrg t struturs, th ominnt ost is squntil prossing on iniviul strutur lmnts Tmporl vs. physil lolity

12 Optiml Pg Rplmnt For prosss with vril numr of frms VMIN Rpl pg tht is not rfrn in th nxt τ sss Exmpl: τ =4 Tim Rqusts Pgs in Mmo ory Fults Pg t = Pg - Pg - Pg Pg t - = Optiml Pg Rplmnt For prosss with vril numr of frms VMIN Rpl pg tht is not rfrn in th nxt τ sss Exmpl: τ = Pg F - t = Pg F Pg - F - - Pg F Pg t - = F - - Fults s ory Tim Rqusts Pgs in Mmo 4

13 Expliitly Using Lolity Th working st mol of pg rplmnt Assum rntly rfrn pgs r likly to rfrn gin soon... n only kp thos pgs rntly rfrn in mmory (ll th working st) Thus pgs my rmov vn whn no pg fult ours Th numr of frms llot to pross will vry ovr tim A pross is llow to xut only if its working st fits into mmory Th working st mol prforms impliit it lo ontrol 5 Working St Pg Rplmnt Implmnttion Kp trk of th lst τ rfrns Th pgs rfrn uring th lst τ mmory sss r th working st τ is ll th winow siz Exmpl: Working st omputtion, τ = 4 rfrns: Tim Rqusts Pgs in Mmory Fults Pg Pg Pg Pg Pg t = - - t = - t =

14 Working St Pg Rplmnt Implmnttion Kp trk of th lst τ rfrns Th pgs rfrn uring th lst τ mmory sss r th working st τ is ll th winow siz Exmpl: Working st omputtion, τ = 4 rfrns: Wht if τ is too smll? too lrg? Tim Rqusts Pg t = F Pg F - - Pg - F Pg t = F Pg t = F Fults y Pgs in Mmory 7 Pg-Fult-Frquny Pg Rplmnt An ltrnt working st omputtion Expliitly ttmpt to minimiz pg fults Whn pg fult frquny is high inrs working st Whn pg fult frquny is low rs working st Algorithm: Kp trk of th rt t whih fults our Whn fult ours, omput th tim sin th lst pg fult Ror th tim, t lst, of th lst pg fult If th tim twn pg fults is lrg thn ru th working st If t urrnt t lst > τ τ, thn rmov from mmory ll pgs not rfrn in [t lst, t urrnt ] If th tim twn pg fults is smll thn inrs working st If t urrnt t lst τ, thn fulting pg to th working st 8

15 Pg-Fult-Frquny Pg Rplmnt Exmpl, winow siz = If t urrnt t lst >, rmov pgs not rfrn in [t lst, t urrnt ] from th working st If t urrnt t lst, just fulting pg to th working st Tim Rqusts P gs in Mmory Fults Pg Pg Pg Pg Pg t ur t lst Pg-Fult-Frquny Pg Rplmnt Exmpl, winow siz = If t urrnt t lst >, rmov pgs not rfrn in [t lst, t urrnt ] from th working st If t urrnt t lst, just fulting pg to th working st Tim Rqusts P gs in Mmory Pg Pg Pg Pg Pg F F - - F - F - - F Fults t ur t lst

16 Lo Control Funmntl troff High multiprogrmming lvl MPL mx = numr of fpg frms minimum numr of frms rquir for pross to xut Low pging ovrh MPL min = pross Issus Wht ritrion shoul us to trmin whn to inrs or rs th MPL? Whih tsk shoul swpp out if th MPL must ru? Lo Control How not to o it: Bs lo ontrol on CPU utiliztion I/O Dvi Assum mmory is nrly full A hin of pg fults our A quu of prosss forms t th pging vi CPU... CPU utiliztion flls Oprting systm inrss MPL Nw prosss fult, tking mmory wy from xisting prosss CPU utiliztion gos to, th OS inrss th MPL furthr... Pging Dvi Systm is thrshing spning ll of its tim pging

17 Lo Control Thrshing Thrshing n mliort y lol pg rplmnt Bttr ritri for lo ontrol: Ajust MPL so tht: mn tim twn pg fults (MTBF) = pg fult srvi tim (PFST) Σ WS i = siz of mmory. CPU Utiliztion. MTBF PFST N mx N I/O-BALANCE Multiprogrmming Lvl Lo Control Thrshing Ry Running Physil Mmory suspn quu Suspn ry quu? Witing smphor/onition quus Whn th multiprogrmming lvl shoul rs, whih pross shoul swpp out? Lowst priority pross? Smllst pross? Lrgst pross? Olst pross? Fulting pross? Pging Disk 4