limit ed dram
play

Limit ed DRAM Wit h paging we could pr obably f unct ion wit h j ust - PDF document

Limit ed DRAM Wit h paging we could pr obably f unct ion wit h j ust one r esident memor y page f or each pr ocess (and 14: Memory Management it s Mast er Page Table) But r eading and wr it ing memor y pages t o disk is


  1. Limit ed DRAM � Wit h paging we could pr obably “f unct ion” wit h j ust one r esident memor y page f or each pr ocess (and 14: Memory Management it s Mast er Page Table) � But r eading and wr it ing memor y pages t o disk is expensive so we don’t want t o do it ver y of t en Last Modif ied: � So how much syst em DRAM do we r eally need f or each process? 6/ 28/ 2004 9:53:10 AM � Do we give each process t he same amount of memory? � Do t hey all need t he same amount ? � Do we have enough syst em DRAM t o support all t he processes we want t o run?(We know we can do bet t er t han 4 GB f or each one but t o avoid const ant paging how many do we need) � Two ways t o answer – pr act ical and t heor et ical -1 -2 How much memory do processes Windows Task Manager need? (P ract ical Answer) � t op � SI ZE vs RES � Absolut e? � Relat ive? � Tot al r eal memory � Free � Swap in use -3 -4 Observat ions About Act ual How much memory do processes Memory Usage need? (Theoret ical Answer) � Varies signif icant ly per process � “Working set ” of a process is t he set of virt ual memory pages being act ively used � Are any processes paging “t oo heavily”? by t he process. � Could we t ell j ust f rom t hese st at s? How would � Def ine a wor king set over an int er val we know? � W S P (w)= {pages P accessed in t he last w accesses} � I f w = t ot al number of P accesses P makes t hen W S P (w)= ever y vir t ual memor y page t ouched by P � Small working set = accesses of a process have high degree of localit y -5 -6 1

  2. Changes in Working Set Demand P aging � Wor king set changes over t he lif e of t he pr ocess � When a pr ocess f ir st st ar t s up � Ex. At f irst all t he init ializat ion code is in t he working � I t has brand new page t able wit h all PTE valid bit s set t o set of a process but af t er some t ime if won’t be any f alse because no pages yet mapped t o physical memory longer � As process f et ches inst ruct ions and accesses dat a, t here � I nt uit ively, you need t o keep t he wor king set of a will be “page f ault s” f or each page t ouched � Only pages t hat are needed or “demanded” by t he pr ocess in memor y or t he OS will const ant ly be process will be brought in f rom disk bring pages on and of f of disk � Event ually may br ing so many pages in t hat must � Nor mally when we ask how much memor y a given choose some f or evict ion pr ogr am needs t o r un, t he answer is eit her it s � Once evict ed, if access, will once again demand page in aver age or maximum wor king set (depending on f rom disk how conser vat ive you want t o make your est imat e) -7 -8 Demand P aging P repaging? � When wor king set changes (like at t he beginning � Ant icipat e f ault bef ore it happens and of a pr ocess), you will get disk I / O – r eally no way pref et ch t he dat a around t hat ! � Overlap f et ch wit h comput at ion � BUT if most memor y accesses r esult in disk I / O � Can be hard t o predict and if predict wrong t he pr ocess will r un * painf ully* slow evict somet hing usef ul in exchange � Vir t ual memor y may be invisible f r om a f unct ional st andpoint but cer t ainly not f r om a per f or mance � P rogrammers can give hint s one � vm _advise � There is a perf ormance clif f and if you st ep of f of it you are going t o know � Remember building syst ems wit h clif f s is not good -9 -10 Thrashing Avoiding P aging � Thrashing – spending all your t ime moving � Given t he cost of paging, we want t o make pages t o and f rom disk and lit t le t ime it as inf r equent as we can act ually making progress � Funct ion of : � Syst em is overcommit t ed � Degr ee of localit y in t he applicat ion (size of t he � People get like t his ☺ wor king set over t ime) � Amount of physical memor y � Page r eplacement policy � The OS can only cont rol t he replacement policy -11 -12 2

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

  4. LRU Clock LRU Clock (con’t) � Also called Second Chance � Ar m moves as quickly as evict ion ar e request ed � Logically put all physical page f rames in a circle (clock) � I f evict ions rarely request ed t hen arm moves slowly and pages have a long t ime t o � Maint ain a point er t o a current page (clock prove t heir wort h by being ref erenced hand) � I f evict ions f requent ly request ed t hen arm � When need t o evict a page, look at current moves f ast and lit t le t ime bef ore t he page second chance is up � I f r ef bit of f t hen evict � I f r ef bit on clear it and move on (second chance) -19 -20 Fairness? Fixed vs Variable Space � All t he replacement policies we’ve looked at � Fixed space algorit hms so f ar j ust t ry t o pick t he page t o evict � Give each pr ocess a limit of pages it can use regardless of which process t he page � When it r eaches it s limit , it r eplaces LRU or belongs t o FI FO or what ever f r om it s pages � What if demand page in f rom one process � May be mor e nat ur al t o give pr ocess a say in causes t he evict ion of anot her processes t he r eplacement policy used f or it s pages page? I s t hat f air? � Variable space algorit hms � On t he ot her hand is it f air f or one � Pr ocesses set of pages gr ows and shr inks process t o have 2 t imes t heir working set � One pr ocess can r uin it f or t he r est but while anot her process has ½ t heir working oppor t unit y t o make globally bet t er decisions set and is paging heavily? -21 -22 Use Working Set P age Fault Frequency (P FF) � Could ask each process t o inf orm t he OS � PFF is a variable-space algorit hm t hat t ries t o det ermine t he working set size of t he size of it s wor king set dynamically � OS only allow a pr ocess t o st ar t if it can � Monit or page f ault rage f or each process allocat e t he complet e working set � I f f ault rat e is above a given t hreshold, � How easy f or processes t o report t his? give it more memory � I f f ault rat e is below t hreshhold, t ake away memory � Const ant adj ust ment ? Dampening f act or so only changes occasionally -23 -24 4

Recommend


More recommend