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

limit ed dram
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

  • 1

14: Memory Management

Last Modif ied: 6/ 28/ 2004 9:53:10 AM

  • 2

Limit ed DRAM

Wit h paging we could pr obably “f unct ion” wit h j ust

  • ne r esident memor y page f or each pr ocess (and

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

So how much syst em DRAM do we r eally need f or

each process?

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

  • 3

How much memory do processes need? (P ract ical Answer)

  • t op
  • SI ZE vs RES

Absolut e? Relat ive?

  • Tot al r eal

memory

Free Swap in use

  • 4

Windows Task Manager

  • 5

Observat ions About Act ual Memory Usage

Varies signif icant ly per process Are any processes paging “t oo heavily”?

Could we t ell j ust f rom t hese st at s? How would

we know?

  • 6

How much memory do processes need? (Theoret ical Answer)

“Working set ” of a process is t he set of

virt ual memory pages being act ively used by t he process.

Def ine a wor king set over an int er val

W SP(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 SP(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

slide-2
SLIDE 2

2

  • 7

Changes in Working Set

Wor king set changes over t he lif e of t he pr ocess

  • Ex. At f irst all t he init ializat ion code is in t he working

set of a process but af t er some t ime if won’t be any longer I nt uit ively, you need t o keep t he wor king set of a

pr ocess in memor y or t he OS will const ant ly be bring pages on and of f of disk

Nor mally when we ask how much memor y a given

pr ogr am needs t o r un, t he answer is eit her it s aver age or maximum wor king set (depending on how conser vat ive you want t o make your est imat e)

  • 8

Demand P aging

When a pr ocess f ir st st ar t s up

I t has brand new page t able wit h all PTE valid bit s set t o

f alse because no pages yet mapped t o physical memory

As process f et ches inst ruct ions and accesses dat a, t here

will be “page f ault s” f or each page t ouched

Only pages t hat are needed or “demanded” by t he

process will be brought in f rom disk Event ually may br ing so many pages in t hat must

choose some f or evict ion

Once evict ed, if access, will once again demand page in

f rom disk

  • 9

Demand P aging

When wor king set changes (like at t he beginning

  • f a pr ocess), you will get disk I / O – r eally no way

around t hat !

BUT if most memor y accesses r esult in disk I / O

t he pr ocess will r un * painf ully* slow

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

  • ne

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

  • 10

P repaging?

Ant icipat e f ault bef ore it happens and

pref et ch t he dat a

Overlap f et ch wit h comput at ion Can be hard t o predict and if predict wrong

evict somet hing usef ul in exchange

P

rogrammers can give hint s

vm

_advise

  • 11

Thrashing

Thrashing – spending all your t ime moving

pages t o and f rom disk and lit t le t ime act ually making progress

Syst em is overcommit t ed People get like t his ☺

  • 12

Avoiding P aging

Given t he cost of paging, we want t o make

it as inf r equent as we can

Funct ion of :

Degr ee of localit y in t he applicat ion (size of t he

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

slide-3
SLIDE 3

3

  • 13

Goals of Replacement P

  • licy

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?

  • 15

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

  • 17

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!

  • 18

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

slide-4
SLIDE 4

4

  • 19

LRU Clock

Also called Second Chance Logically put all physical page f rames in a

circle (clock)

Maint ain a point er t o a current page (clock

hand)

When need t o evict a page, look at current

page

I f r ef bit of f t hen evict I f r ef bit on clear it and move on (second

chance)

  • 20

LRU Clock (con’t)

Ar m moves as quickly as evict ion ar e

request ed

I f evict ions rarely request ed t hen arm

moves slowly and pages have a long t ime t o prove t heir wort h by being ref erenced

I f evict ions f requent ly request ed t hen arm

moves f ast and lit t le t ime bef ore t he second chance is up

  • 21

Fairness?

All t he replacement policies we’ve looked at

so f ar j ust t ry t o pick t he page t o evict regardless of which process t he page belongs t o

What if demand page in f rom one process

causes t he evict ion of anot her processes page? I s t hat f air?

On t he ot her hand is it f air f or one

process t o have 2 t imes t heir working set while anot her process has ½ t heir working set and is paging heavily?

  • 22

Fixed vs Variable Space

Fixed space algorit hms

Give each pr ocess a limit of pages it can use When it r eaches it s limit , it r eplaces LRU or

FI FO or what ever f r om it s pages

May be mor e nat ur al t o give pr ocess a say in

t he r eplacement policy used f or it s pages Variable space algorit hms

Pr ocesses set of pages gr ows and shr inks One pr ocess can r uin it f or t he r est but

  • ppor t unit y t o make globally bet t er decisions
  • 23

Use Working Set

Could ask each process t o inf orm t he OS

  • f t he size of it s wor king set

OS only allow a pr ocess t o st ar t if it can

allocat e t he complet e working set

How easy f or processes t o report t his?

  • 24

P age Fault Frequency (P FF)

PFF is a variable-space algorit hm t hat t ries

t o det ermine t he working set size dynamically

Monit or page f ault rage f or each process I f f ault rat e is above a given t hreshold,

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

  • nly changes occasionally
slide-5
SLIDE 5

5

  • 25

Best page replacement ?

Of course it depends ☺ I nt erest ingly if have t oo much memory it

doesn’t mat t er

anyt hing you do will be ok (over pr ovisioning)

Also doesn’t mat t er if have t oo lit t le

memory

Thr ashing and not hing you can do t o st op it

(over commit t ed) So much does it cost j ust t o overprovision?

  • 26

Summary

Demand paging

St art wit h no physical memory pages mapped and load

t hem in on demand Page r eplacement Algor it hms

Belady – opt imal but unrealizable FI FO – replace page loaded earliest LRU – replace page ref erenced earliest Working Set –keep set of pages in memory t hat induces

minimal f ault rat e (need program specif icat ion)

PFF – Grow/ shrink page set as a f unct ion of f ault rat e

Fair ness – globally opt imal r eplacement vs

pr ot ect ing pr ocesses f r om each ot her ?

  • 27

Out t akes

Shared memory machines Expanding address spaces 16 t o 32 bit I nvert ed page t ables Mult ics