Memory management

reelingripehalfSoftware and s/w Development

Dec 14, 2013 (3 years and 7 months ago)

60 views

Outline
Addressspacesandaddressbinding
compile-time
load-time
run-time
Memorymanagement:mappingvirtualaddresstophysicaladdresses
contiguousallocationandfragmentation
Paging
paginghardware
multi-levelandhashedpagetables
protectionandsharing
Segmentation
Swapping
Demandpaging
pagefaults
pagereplacement
FIFO
optimal
LRU
LRUapproximations
countingalgorithms
Frameallocation
Thrashing
Performanceofdemandpaging:issuesandimprovements
OperatingSystems:MemoryManagementp.1
Section8.1.1
Addressspaces
Code Data Stack Heap
Program address
space
...
Memory
CPU
Bus
Physical addresses
Addressbinding:mappingfromoneaddressspacetoanother
addressspace
OperatingSystems:MemoryManagementp.2
Addressbinding
Compile-timebinding
Locationofprograminphysicalmemorymustbeknownat
compiletime
Compilergeneratesabsolutecode
compilerbindsnamestoactualphysicaladdresses
Loading≡copyingexecutableletoappropriatelocationin
memory
Ifstartinglocationchanges,programwillhavetoberecompiled
Example:.COMprogramsinMS-DOS
OperatingSystems:MemoryManagementp.3
Addressbinding
Load-timebinding
Compilergeneratesrelocatablecode
compilerbindsnamestorelativeaddresses(offsetsfrom
startingaddress)
compileralsogeneratesrelocationtable
Linkerresolvesexternalnamesandcombinesobjectlesinto
oneloadablemodule
(Linking)loaderconvertsrelativeaddressestophysical
addresses
Norelocationallowedduringexecution
OperatingSystems:MemoryManagementp.4
Addressbinding
Run-timebinding
Programs/compiledunitsmayneedtoberelocatedduring
execution
CPUgeneratesrelativeaddresses
Relativeaddressesboundtophysicaladdressesatruntime
basedonlocationoftranslatedunits
Suitablehardwaresupportrequired
OperatingSystems:MemoryManagementp.5
Section8.2
Memorymanagementunit
Logical/virtualaddress:addressgeneratedbyCPU
Physicaladdress:addressseenbymemoryhardware
Compile-time/load-timebinding⇒logicaladdress=physical
address
Run-timebinding⇒logicaladdress6=physicaladdress
MMU:h/wdevicethat
mapsvirtualaddressesto
physicaladdressesatrun
time
(alsocalledaddress
translationhardware)
...
Memory
CPU
Bus
MMU
Logicaladdress
Physicaladdress
OperatingSystems:MemoryManagementp.6
MMU
Kernelloadsrelocationregisterwhenschedulingaprocess
OperatingSystems:MemoryManagementp.7
Section8.4
Memoryprotection
Preventsprocessfromaccessinganymemoryoutsideitsown
addressspace
AllowsOSsizetochangedynamically
transientcode(code/datacorrespondingtoinfrequently
useddevices/services)mayberemovedfrommemory
whennotinuse
OperatingSystems:MemoryManagementp.8
Contiguousallocation
Memoryisdividedintovariable-sizedpartitions
OSmaintainsalistofallocated/freepartitions(holes)
Whenaprocessarrives,itisallocatedmemoryfromahole
largeenoughtoaccommodateit
Memoryisallocatedtoprocessesuntilrequirementsofnext
processinqueuecannotbemet
OSmayskipdownthequeuetoallocatememorytoa
smallerprocessthattsinavailablememory
Holeallocationpolicies:
First-t:allocatetherstholethatisbigenough
Best-t:allocatethesmallestholethatisbigenough
entirefreelisthastobesearchedunlesssorted
Worst-t:allocatethelargesthole
Whenprocessexits,memoryisreturnedtothesetofholesand
mergedwithadjacentholes,ifany
OperatingSystems:MemoryManagementp.9
Contiguousallocation
Example:
Processsizes:P1
600P2
1000P3
300P4
700P5
500
OS
400
0 1000 2000 2300 2560
OS
400
0 1000 2000 2300 2560
OS
400
0 1000 2000 2300 2560
OS
400
0 1000 2000 2300 2560
OS
400
0 1000 2000 2300 2560
P1
P1
P1
P2
P3
P3
P3
P3
P3
P4
P4
P4
P5
170017001700
900
OperatingSystems:MemoryManagementp.10
Fragmentation
Externalfragmentation:memoryspacetosatisfyarequestis
available,butisnotcontiguous
maybereducedslightlybyallocatingmemoryfrom
appropriateend(top/bottom)ofhole
InternalFragmentation:allocatedmemorymaybelargerthan
requestedmemory
⇒memorywithinpartitionmaybeleftunused
maybeusedtoavoidoverheadrequiredtokeeptrackof
smallholes
OperatingSystems:MemoryManagementp.11
Compaction
Memorycontentsshufedtoplaceallfreememorytogetherin
onelargeblock
Reducesexternalfragmentation
Dynamicrelocation(run-timebinding)needed
OperatingSystems:MemoryManagementp.12
Section8.5.1
Paging
Physicalmemoryispartitioned
intoxed-sizeframes
Framesize:
denedbyhardware
shouldbepowerof2
typically5128192bytes
Logicaladdressspaceis
partitionedintopages(samesize
asframes)
Whenaprocesswithnpageshas
tobeloaded,nfreeframeshave
tobefound
Kernelkeepstrackoffreeframes
Pagetabletranslateslogicalpage
#stophysicalframeaddresses
0 MAX
m
Logical
address
space
...
Physical
memory
Page
Table
OperatingSystems:MemoryManagementp.13
Paging
Let2m
=sizeoflogicaladdressspace
2n
=sizeofpage
Thenp=m−nhigherorderbitsoflogicaladdress
d=nlowerorderbitsoflogicaladdress
OperatingSystems:MemoryManagementp.14
Paging
Pagetable:
partofprocesscontext
duringcontextswitch,savedpagetableisusedto
reconstructhardwarepagetable
maybeusedbysomesystemcallstotranslatelogical
addressestophysicaladdressesinsoftware
Frametable:
maintainedbykernel
contains1entryperphysicalpageframe
whetherfreeorallocated
allocationinformation(PID,page#)
OperatingSystems:MemoryManagementp.15
Paging
Miscellaneousissues:
Memoryprotectionisautomatic
processcannotaddressmemoryoutsideitsownaddress
space
Fragmentation:
Noexternalfragmentation
Internalfragmentationcanhappen
halfapageperprocess,onaverage
Page/framesize:
Smallframes⇒lessfragmentation
Largeframes⇒pagetableoverhead↓;I/Oismoreefcient
OperatingSystems:MemoryManagementp.16
Section8.5.2
Paginghardware
I.Specialpurposeregisters:
Pagetableisstoredinasetofdedicated,high-speedregisters
Instructionstoload/modifyPTregistersareprivileged
Acceptablesolutionifpagetableissmall
Example:DECPDP-11
16-bitaddressspace
8Kpagesize
pagetablecontains8entries
OperatingSystems:MemoryManagementp.17
Paginghardware
II.Memory+PTBR:
Neededforlargepagetables
PTstoredinmainmemory
BaseaddressofPTisstoredinpagetablebaseregister
(PTBR)
LengthofPTisstoredinpagetablelengthregister(PTLR)
Contextswitchinvolveschanging1registeronly
Twophysicalmemoryaccessesareneededperusermemory
access
⇒memoryaccessisslowedbyfactorof2
OperatingSystems:MemoryManagementp.18
Paginghardware
III.Associativeregisters/Translationlook-asidebuffer(TLB):
TLB≡small,fast-lookup
hardwarecache,builtusing
high-speedmemory
(expensive)
eachregisterholdskey+
value
inputvalueiscompared
simultaneouslywithallkeys
onmatch,corresponding
valueisreturned
TLBholdssubsetofpagetableentries
TLBhit⇒additionaloverheadmaybe10%orless
TLBmiss⇒newhpage#,frame#iaddedtoTLB
TLBhastobeushedoncontext-switch
OperatingSystems:MemoryManagementp.19
Paginghardware
Hitratio:percentageoftimesthatapage#isfoundinTLB
dependsonsizeofTLB
Effectivememoryaccesstime:averagetimeforamemory
access(includingTLBlookup)
Example:
TLBlookup:20nsMemoryaccess:100nsHitratio:80%
Effectiveaccesstime=0.8×120+0.2×220=140ns
OperatingSystems:MemoryManagementp.20
Section8.5.3
Multi-levelpaging
Logicaladdressspacesareusuallyverylarge(232
or264
)
⇒pagetablesareverylarge(howlarge?)
⇒pagetablesshould/cannotbeallocatedcontiguously
Two-levelpaging:
Firstlevel(inner)pagetableisbrokenintopieces
Secondlevel(outer)PTentriespointtomemoryframes
holdingthepiecesoftherstlevelPT
Example:
←page#→
←offset→
p
1
p
2
d
10bits
10bits
12bits
3-,4-,...levelpagingmayberequiredforcertainarchitectures
Performance:TLBmiss⇒upto4extramemoryaccesses
OperatingSystems:MemoryManagementp.21
Section8.5.2
Memoryprotection
Protectionbit(s)associatedwitheachframe(viapagetable
entry)
protectionbitspeciesread-only/read-writeaccess
protectionbitcheckedinparallelwithaddresscomputation
protectionviolation(writingtoread-onlypage)causes
hardwaretraptoOS
Valid/invalidbitindicateswhetherpageisintheprocess'logical
addressspace
setbyOSforeachpage
maybeusedtoimplementprocesssizerestrictions
OperatingSystems:MemoryManagementp.22
Section8.5.5
Sharingpages
Primarilyusedforsharingreentrant(read-only)codeforheavily
usedprograms
e.g.commonutilities,texteditors,compilers,window/desktop
managers
NOTE:dataforseparateprocessesarestoredseparately
PTforeachprocessrunningasharedprogrammapscode
pagestothesamephysicalframes
Datapagesaremappedtodifferentphysicalframes
OperatingSystems:MemoryManagementp.23
Section8.6
Segmentation
Intuitively,addressspace6≡lineararrayofbytes
Addressspaceismadeupofvariable-sizedlogicalsegments
e.g.mainfunction,subroutines,somedatastructures(list,
array,stack,etc.),...
Segmentsarenotnecessarilyordered
Elementswithinasegmentareordered
Eachsegmentisallocatedcontiguousmemory
Logicaladdressesspecifyhsegmentidentier,offseti
NOTE:Segmentsareusuallyautomaticallygeneratedbythecompiler
OperatingSystems:MemoryManagementp.24
SegmentTable
Maps2-dimensionallogicaladdressesto1-dimensional
physicalmemoryaddresses
Segmenttableentry=hsegmentbase,segmentlimiti
Base=startingphysicaladdressofsegmentinmemory
Limit=sizeofsegment
OperatingSystems:MemoryManagementp.25
Segmentation
Segmenttables:
Canbestoredinfastregisters/memory
STBR:pointstosegmenttableinmemory
STLR:lengthofsegmenttable
ARsholdthemostrecentlyusedsegment-tableentries
Protection/sharing:
Eachsegmenthasassociatedprotection/permissionbits
Memorymappinghardwarechecksprotectionbitstopreventillegalmemoryaccesses
hardwarecheckscanbeusedtoenforceautomaticboundsonarrayindices
1ormoresegmentscanbesharedbetweenprocessesbysettingsegmenttable
entriestopointtothesamephysicallocation
sharedcodesegmentsshouldbeassignedthesamesegment#inallprocesses
Fragmentation:
Segmentsarevariable-sized⇒externalfragmentationmayhappen
ifaveragesegmentsizeissmall,fragmentationislow
OperatingSystems:MemoryManagementp.26
Section8.3
Swapping
Motivation:
Considerthefollowingsituation:
P1
,...,P
n
areresidentinmemoryandoccupyallavailable
memory Pi
forkstocreateachild
OperatingSystems:MemoryManagementp.27
Section8.3
Swapping
Motivation:
Considerthefollowingsituation:
P1
,...,P
n
areresidentinmemoryandoccupyallavailable
memory Pi
forkstocreateachild
Principle:
Spaceonfastdisk(alsocalledBackingStore)isusedas
additional/secondarymemory
Processcanbeswappedouttemporarilyfrommainmemoryto
backingstore;releasedmemoryisusedforsomeother
process;swappedprocessisswappedinlaterforcontinued
execution
OperatingSystems:MemoryManagementp.27
Swapping
Choosingprocesses:
Round-robin
whenP'squantumexpires,it
isswappedout,P

is
swappedintofreedmemory
schedulerallocatesnext
quantumtosomeother
processinmemory
...
OS
P1
P4
P3
P2
Backing
store
Priority-based(rollout,rollin)
whenhigherpriorityprocessarrives,lower-priorityprocess
isswappedout
whenhigherpriorityprocessnishes,lowerpriorityprocess
canbeswappedin
OperatingSystems:MemoryManagementp.28
Swapping
Performance:
Contextswitchtimeincreases(∵disktransferisinvolved)
Timequantumshouldbelargecomparedtoswaptimeforgood
utilization
Example:
Processsize:100KTransferrate:1Mbps
⇒swap-out+swap-intime=200ms(+ε)
OperatingSystems:MemoryManagementp.29
Swapping
Input/output:
IfPisswappedoutwhilewaitingforinputintobufferinuser
memory,addressesusedbyI/Odevicesmaybewrong
Solutions:
processwithpendingI/Oshouldneverbeswapped,OR
I/OoperationsarealwaysdoneusingOSbuffers
(datacanbetransferredfromOStouserbufferwhenPis
swappedin)
Compaction:
1.Processeswhichhavetobemovedareswappedout
2.Memoryiscompactedbymergingholes
3.Swapped-outprocessesareswappedintodifferentmemory
locationstominimizefragmentation
OperatingSystems:MemoryManagementp.30
Section9.1
Virtualmemory
Background:
Instructionsbeingexecuted/addressesbeingreferencedmust
beinmainmemory
Entirelogicaladdressspacedoesnothavetobeloadedinto
memory
somecodemaybeexecutedrarely
e.g.errorhandlingroutinesforunusualerrorconditions,
codeimplementingrarelyusedfeatures
arrays/tablesmaybeallocatedmorememorythanrequired
Virtualmemory≡mechanismtoallowexecutionofprocesses
withoutrequiringtheentireprocesstobeinmemory
OperatingSystems:MemoryManagementp.31
Virtualmemory
Advantages:
Programscanbelargerthanphysicalmemory
Moreprogramscanberunatthesametime
⇒throughput/degreeofmultiprogrammingincreaseswithout
increaseinresponsetime
LessI/Oisneededforloading/swapping
⇒programsmayrunfaster(comparedtoswapping)
OperatingSystems:MemoryManagementp.32
Section9.2
Demandpaging
Processesresideonsecondarymemory(high-speeddisk)
Whenprocessistobeexecuted,onlytheneededpagesare
broughtintomemory(lazyswapping)
Pagetableshouldspecifylocationofpages(memoryvs.
on-disk)
valid/invalidbitmaybeused
forpagethatisnotcurrentlyinmemory,pagetableentry
maycontainaddressofpageondisk
Whileprocessaccessespagesresidentinmemory,execution
proceedsnormally
Whenprocessaccessespagenotinmemory,paginghardware
trapstoOS(pagefault)
NOTE:Swappermanipulatesentireprocesses
Pagercopiesindividualpagesto/fromswapspace
OperatingSystems:MemoryManagementp.33
Pagefaults
1.Checkinternaltabletodeterminewhetherreferencewasto
valid/invalidpage.
2.Invalidaccess⇒terminateprocess.
3.Findafreeframefromthefree-framelist.
4.Readthedesiredpagefromswapdeviceintothefreeframe.
5.WhenI/Oiscomplete,updateinternaltableandpagetable.
6.Restarttheinstructionthatwasinterruptedbytheillegal
addresstrap.
(state/contextoftheprocessissavedsothatprocesscanbe
restartedinexactlythesamestate)
OperatingSystems:MemoryManagementp.34
Restartinginstructions
PageFault
Handling
Instructionfetch
Re-fetchinstruction
Operandfetch
1.Re-fetchinstruction.
2.Decodeinstruction.
3.Fetchoperand.
ADDAB
C
1.Fetch,decodeinstruction
2.FetchA,B.
3.AddA,B;storesuminC.
Problems:
MVC(IBMSystem360/370)
movesupto256bytesfromonelocationtoanother
Auto-increment/auto-decrementaddressingmodes
OperatingSystems:MemoryManagementp.35
Section9.4
Pagereplacement
Motivation:
Puredemandpaging:pagesarenotbroughtintomemoryuntil
required
(processstartsexecutingwithnopagesinmemory)
Overallocation⇒freeframelistmaybeemptywhenapage
faultoccurs
Method:
1.Findthelocationofthedesiredpageondisk.
2.Findafreeframe.Ifthereisnofreeframe:
(i)usepagereplacementalgorithmtoselectvictimframe;
(ii)writevictimpagetodisk;changepage/frametables
accordingly.
3.Readthedesiredpageintothe(newly)freeframe.
4.Updatethepageandframetables;restarttheprocess.
OperatingSystems:MemoryManagementp.36
Modify/dirtybit
Modify/dirtybitisassociatedwitheachpage(viaPT)
Setwheneverthepageiswritten
Ifdirtybitofvictimframeisclear,itisnotwrittentodisk
Reducestimetoservicepagefaults
Alsoapplicabletoread-onlypages
OperatingSystems:MemoryManagementp.37
Section9.5
Pagereplacementalgorithms
Pagereplacementalgorithmshouldyieldlowpage-faultrate
Referencestring:sequenceofmemoryreferences
usedtoevaluatePRalgorithms
maybegeneratedarticially,orbytracingaprocess
memoryreferencesareintermsofpage#sonly
sequenceofsuccessivereferencestothesamepagemay
bereplacedbyonlyonereference
#offramesallocatedtoaprocess↑⇒pagefaults↓
OperatingSystems:MemoryManagementp.38
FIFO
PagesarekeptinaFIFOqueue
whenapageisbroughtintomemory,itisaddedattailof
queue
whenapagehastobereplaced,pageatheadofqueueis
selected
Example:
Referencestring:123412512345
#offrames:3
#ofpagefaults:9
Belady'sanomaly:
#offramesallocatedtoaprocess↑6⇒pagefaults↓
Stackalgorithms:
Pagesinmemorywithnframes⊆Pagesinmemorywithn+1frames
NeverexhibitBelady'sanomaly
OperatingSystems:MemoryManagementp.39
Optimalalgorithm
Replacepagethatwillnotbeusedforthelongestperiodoftime
Minimizesthenumberofpagefaultsforaxednumberof
allocatedframes
Notimplementable
Usedtomeasureotherreplacementalgorithms
OperatingSystems:MemoryManagementp.40
LRUalgorithm
Replacepagethathasnotbeenusedforthelongesttime
Oftenusedinpractice
Disadvantage:usuallyrequiressubstantialhardware
assistance
Counterimplementation:
EachPTentrycontainsatime-of-use(counter)eld
Oneachmemoryreference,aclock/counterisincremented;
counteriscopiedintothePTentryforthereferredpage
Whenapagehastobereplaced,pagewiththesmallest
counterisselected
Disadvantages:
eachmemoryreferencerequiresawritetomemory
entirepagetablehastobesearchedtondLRUpage
counteroverowhastobehandled
OperatingSystems:MemoryManagementp.41
LRUalgorithm
Stackimplementation:
pagenumbersaremaintainedinadoubly-linkedstackwith
headandtailpointers
onapagereference,thecorrespondingPTentryismovedto
topofstack
sixpointershavetobechanged
tailpointstoLRUpage
OperatingSystems:MemoryManagementp.42
LRUapproximationalgorithms
Background:
Manyarchitecturesdonotprovidehardwaresupportfortrue
LRUpagereplacement
ApproximateversionsofLRUhavetobeimplementedwiththe
limitedhardwaresupport
Referencebit:
AssociatedwitheachPTentry
AllreferencebitsareinitiallyclearedbyOS
Setbyhardwareoneachpagereference
⇒distinguishesusedpagesfromunusedpages
OperatingSystems:MemoryManagementp.43
LRUapproximationalgorithms
I.Additional-reference-bitsalgorithm:
1referencebyteassociatedwitheachPTentry
Oneachtimerinterrupt:referencebyteisright-shifted;
referencebitiscopiedintohigh-orderbitofreferencebyteand
cleared
Referencebytescontainhistoryofpageusefor8mostrecent
intervals
ReferencebytesorderPTentriesinLRUorder
(tiesmaybebrokenusingFIFOordering)
OperatingSystems:MemoryManagementp.44
LRUapproximationalgorithms
II.Second-chance/clock
algorithm:
StorePTentriesinaFIFO
queue
Ifreferencebitofselected
pageisset:
clearreferencebit
setarrivaltimeto
currenttime
continuetonextpagein
FIFOorder
Ifallbitsareset,second-chancereplacementreducestoFIFO
replacement
OperatingSystems:MemoryManagementp.45
LRUapproximationalgorithms
III.Enhancedsecond-chancealgorithm:
hrefbit,dirtybiticonsideredasanorderedpair
h0,0ibestpagetoreplace
h0,1inotrecentlyused,butmodied(hastobewrittento
disk)
h1,0irecentlyused,butclean(likelytobeusedagainsoon)
h1,1irecentlyusedandmodied
Firstpageinlowestnon-emptyclassisselectedasvictim
OperatingSystems:MemoryManagementp.46
Countingalgorithms
EachPTentrystorescountofthenumberofreferencestothat
page
LFUAlgorithm:replacespagewithsmallestcount
countermayberightshiftedatintervalstoforman
exponentiallydecayingaverageusagecount
MFUAlgorithm:replacespagewithlargestcount
LFUpagemayhavebeenbroughtinveryrecentlyandisyet
tobeused
Performanceisnotverygood
OperatingSystems:MemoryManagementp.47
Globalvs.localreplacement
Globalreplacement
replacementframecanbeselectedfromallframes
(includingframesallocatedtootherprocesses)
generallyprovidesbetterthroughput
Localreplacement:replacementframecanbeselectedfrom
theframesallocatedtothecurrentprocess
OperatingSystems:MemoryManagementp.48
Section9.6
Allocationofframes
Singleusersystem:
KerneloccupiesMframes+someframesfordynamicdata
structures
Remainingframesareputonfreelistforusebyauserprocess
Multiprogramming:
Minimum#offramestobeallocatedtoaprocess:
maximumnumberofmemoryreferencespermittedina
singleinstruction
Example:PDP-11MOVinstruction
instructionmayoccupy>1word
2operandseachofwhichcanbeanindirectreference
iffewerframesareallocated,processshouldbeswapped
out,andallocatedframesfreed
OperatingSystems:MemoryManagementp.49
Allocationofframes
Letn=#ofprocesses
M=total#ofmemoryframes
s
i
=sizeofprocessp
i
a
i
=#offramesallocatedtop
i
Equalallocation:
a
i
=M/n
Proportionalallocation:
a
i
=M×s
i
/Σs
i
Priority-basedallocation:
a
i
=f(Pi
,M×s
i
/Σs
i
)
NOTE:Allocationdependsonlevelofmultiprogramming
OperatingSystems:MemoryManagementp.50
Section9.7
Thrashing
Denition:situationinwhichaprocessisspendingmoretime
pagingthanexecuting
ScenarioI:
Processisnotallocatedenoughframestoholdallpagesthat
areinactiveuse
Onapagefault,anactivepage(p)isreplaced
⇒processpagefaultssoontopageinp
OperatingSystems:MemoryManagementp.51
Thrashing
ScenarioII:
OSmonitorsCPUutilizationtodeterminedegreeof
multiprogramming
Globalpagereplacementalgorithmisused
Processentersaphasewhereitneedsasignicantlylarger#
offrames
Multipleprocessesstart
page-faulting
⇒pagingdevicequeue
becomeslonger,ready
queueempties
⇒CPUutilizationdecreases
⇒CPUschedulerincreases
degreeof
multiprogramming
OperatingSystems:MemoryManagementp.52
Thrashing:remedies
Local/prioritypagereplacement:
+Ifoneprocessstartsthrashing,itcannotcauseotherprocesses
tostartthrashing
Thrashingprocessesusepagingdeviceheavily
⇒averageservicetimeforpagefaultincreasesfor
non-thrashingprocessesalso
Pagefaultfrequencymonitoring:
Upperandlowerboundsondesiredpagefaultrateare
determined
IfPFR>upperlimit,processisallocatedanotherframe
IfPFR<lowerlimit,aframeisremovedfromtheprocess
IfPFRincreasesandnofreeframesareavailable:
aprocessisselectedandsuspended
freedframesaredistributedtoprocesseswithhighPFRs
OperatingSystems:MemoryManagementp.53
Thrashing:remedies
Localitymodel:
asetofpagesthatareactivelyusedtogether
e.g.subroutinecode,localvariables,andsomesubsetof
globalvariables
processmovesfromonelocalitytoanother(possibly
overlapping)localityduringexecution
Workingsetmodel:
Workingsetwindow=mostrecentΔpagereferences
Workingset=setofpagesintheworkingsetwindow
approximatestheprogram'scurrentlocality
Δtoolarge⇒workingsetoverlapsseverallocalities
Δtoosmall⇒workingsetdoesnotcoverentirelocality
TotaldemandforframesD=
￿
WSS
i
OperatingSystems:MemoryManagementp.54
Thrashing:remedies
Workingsetmodel:(CONTD.)
OSmonitorsworkingsetofeachprocessandallocatesenough
framestoaccomodateworkingset
Ifextraframesareavailable,moreprocessescanbeloaded
intomemory
IfDexceeds#ofavailableframes,process(es)mustbe
suspended
Implementation:
Timerinterruptisgeneratedatregularintervalse.g.every
5000memoryreferences
Foreachpage,referencebitiscopiedintohistoryregister
andcleared
Overhead=Frequencyofinterrupt,#ofhistorybits
OperatingSystems:MemoryManagementp.55
Section9.3
Performance
Effectiveaccesstime=ma+p×PFtime
wherema-memoryaccesstime
p-probabilityofapagefault
Pagefaultservicetime:
timetoservicepagefaultinterrupt
timeforI/O
timetorestartprocess
Example:PFTime:25msma:100ns
EAT≈100+25,000,000×p
(foracceptableperformance,<1memoryaccessin2,500,000shouldfault)
OperatingSystems:MemoryManagementp.56
Performance
Swapspace:
Swapspaceshouldbeallocatedinlargeblocks
⇒DiskI/OtoswapfasterthanI/Otolesystem
Fileimagecanbecopiedtoswapspaceatprocessstartup
Ifswapspaceislimited:(e.g.BSDUNIX)
pagesarebroughtinfromlesystemondemand
replacedpagesarewrittentoswapspace
OperatingSystems:MemoryManagementp.57
Pagebuffering
Systemsmaymaintainapooloffreeframes
Onapagefault:
requiredpageisreadintoafreeframefromthepool
inparallel,avictimisselectedandwrittentodisk
victimframeisaddedtofree-framepool
Processrestartsassoonaspossible
Pageinformationmayalsobemaintainedforeachfreeframe
ifdesiredpageisinfree-framepool,noI/Oisnecessary
usedonVAX/VMSsystemswithFIFOpagereplacement
Systemmaymaintainalistofmodiedpages
Whenpagingdeviceisidle,modiedpagesarewrittentodisk
OperatingSystems:MemoryManagementp.58