Operting Systems Priniples Pge Replement Algorithms Steve Gor gor@se.unl.eu http://www.se.unl.eu/~gor/courses/csce45 Virtul Memory Mngement Funmentl issues Plement strtegy Replement strtegies Lo ontrol strtegies Exmple: Demn pging» No plement strtegy require per se» Lo ontrol: lo pges only when fults our» Replement:... Pge Pge
Pge Replement Algorithms Conept Typilly Σ i VAS i >> Physil Memory With emn pging, physil memory fills quikly So when proess fults & memory is full, some pge must e swppe out (So hnling pge fult now requires isk esses not!) Whih pge shoul e reple?» Lol replement reple pge of the fulting proess» Glol replement possily reple the pge of nother proess Pge Replement Algorithms Evlution methoology Reor tre of pges esse y proess» Exmple: (Virtul) ress tre... (,), (,9), (4,), (,), (5,), (,), (,9), (,4), (,), (4,8)»... genertes pge tre,, 4,, 5,,,,, 4 (represente s,,,, e,,,,, ) Simulte the ehvior of pge replement lgorithm on the tre & reor the numer of pge fults generte» fewer fults == etter performne 4 Pge Pge 4
Lol Pge Replement FIFO replement Simple to implement» A single pointer suffies Physil Memory Optiml Pge Replement Clirvoynt replement Reple the pge tht won t e neee for the longest time in the future Performne with 4 pge frmes: Pge Frmes Pge Tre 4 5 6 7 8 9 e e e e e e Pge Frmes 4 5 6 7 8 9 e e e e e e e Fults Fults 5 pge neee next = 7 = 6 = 9 = = 5 = = = 4 6 Pge 5 Pge 6
Lest Reently Use Replement Bk to the future Lest Reently Use Replement Implementtion Reple the pge tht hsn t een referene for the longest time» Use the reent pst s preitor of the future Pge Frmes 4 5 6 7 8 9 e e e e e e Fults pge lst use = = 4 = = = 7 = 8 e = 5 = = 7 = 8 e = 5 = 9 7 Mintin stk of reently use pges Pge Frmes 4 5 6 7 8 9 e e e e e e Fults LRU Pge Stk e e e e e e 8 Pge 7 Pge 8
Approximte LRU Replement The Clok lgorithm Mintin irulr list of pges resient in memory» Use lok (or use) it to trk how often pge is esse it set whenever pge is referene Clok sweeps over pges looking for one with use it =» Reples pges tht hven t een referene for one omplete revolution of the lok resient it use it frme numer Pg 7: Pg : 5 Pg 4: Pg : Pg : 4 fun Clok_Replement egin while (pge not foun for replement) o if(use it for urrent pge = ) then reple urrent pge else reset use it en if vne lok pointer en while en Clok_Replement 9 Clok Pge Replement Exmple Pge Frmes 4 5 6 7 8 9 e e e e e e Fults Pge tle entries for resient pges: The LRU pge e e e e e Pge 9 Pge
Performne of Pge Replement Algorithms Bely s Anomly More memory Better performne! Lest reently use» Ages pges se on when they were lst use FIFO» Ages pges se on when they re rought into memory The priniple of lolity Pge Frmes FIFO Replement 4 5 6 7 8 9 e e e e e e e e 9% of the exeution of progrm is sequentil Fults Most intertive onstruts onsist of reltively smll numer of instrutions When proessing lrge t strutures, the ominnt ost is sequentil proessing on iniviul struture elements Pge Frmes e e e e e e e Fults Pge Pge
Expliitly Using Lolity The working set moel of pge replement Working Set Pge Replement Implementtion Assume reently referene pges re likely to e referene gin soon...... n only keep those pges reently referene in memory (lle the working set)» pges my e remove even when no pge fult ours» numer of frmes llote to proess will vry over time A proess is llowe to exeute only if its working set fits into memory» impliit lo ontrol Keep trk of the lst τ referenes» The pges referene uring the lst τ memory esses re the working set» τ is lle the winow size Exmple: working set omputtion, τ = 4 referenes: Pges in Memory 4 5 6 7 8 9 e e Pge t = - - - - - Pge - - - - - - - Pge - Pge t = - - - - Pge e t = - - - - - Fults 4 Pge Pge 4
Optiml Pge Replement For proesses with vrile numer of frmes VMIN Reple pge tht is not referene in the next τ esses Exmple: τ = 4 Pges in Memory 4 5 6 7 8 9 e e Pge t = - - - - - - - - - Pge - - - - - - - - - - Pge - - - - Pge - t = - - - - - - Pge e - - - - - - - - Fults Pge-Fult-Frequeny Pge Replement An lternte working set omputtion Expliitly ttempt to minimize pge fults» When pge fult frequeny is high inrese working set» When pge fult frequeny is low erese working set Algorithm:» Keep trk of the rte t whih fults our Reor the time, t lst, of the lst pge fult» If the time etween pge fults is lrge then reue working set If t urrent t lst > τ, then remove from memory ll pges not referene in [t lst, t urrent ]» If the time etween pge fults is smll then inrese working set If t urrent t lst τ, then fulting pge to the working set 5 6 Pge 5 Pge 6
Pge-Fult-Frequeny Pge Replement Exmple, winow size = If t urrent t lst >, remove pges not referene in [t lst, t urrent ] from the working set If t urrent t lst, fulting pge to the working set Pges in Memory 4 5 6 7 8 9 e e Pge - - - - - Pge - - - - - - Pge - Pge - Pge e - - Fults t ur t lst 7 Pge 7