Unit 5.1 Memory Management_Device Driver_IPC.ppt

AnilkumarBrahmane2 8 views 48 slides May 17, 2024
Slide 1
Slide 1 of 48
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48

About This Presentation

This is for learning purpose.


Slide Content

Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Prof. A. V. Brahmane
Assistant Professor
E-mail : [email protected]
Contact No: 91301 91301 Ext :145, 9922827812
Subject-Operating System and Administration (CO2013)
Unit V-Memory Management Policies, I/O Subsystem
and IPC

Content
•Swapping,
•DemandPaging,
•Driverinterface,
•diskdrivers,
•ProcessTracing,
•Networkcommunication,
•Sockets
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Memory Management Policies
•Historically,UNIXsystemstransferredentireprocessesbetweenprimarymemoryand
theswapdevice.
•Suchamemorymanagementpolicyiscalledswapping.
•ItmadesensetoimplementsuchapolicyonthePDP11,wherethemaximumprocess
sizewas64K.
•TheBSDsystem(release4.0)wasthefirstmajorimplementationofademand
pagingpolicy,transferringmemorypagesinsteadofprocessestoandfromasecondary
device;laterreleasesofUNIXsystemValsosupportdemandpaging.
•Theentireprocessdoesnothavetoresideinmainmemorytoexecute,andthekernel
loadspagesforaprocessondemandwhentheprocessreferencesthepages.
•Thispermitsgreaterflexibilityinmappingthevirtualaddressspaceofaprocessintothe
physicalmemoryofamachine,usuallyallowingthesizeofaprocesstobegreaterthan
theamountofavailablephysicalmemoryandallowingmoreprocessestofit
simultaneouslyinmainmemory.Swappingpolicyiseasiertoimplementandhasless
overhead.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Swapping
•Swappinghas3partstoit:
•managingspaceontheswapdevice
•swappingprocessesoutofmainmemory
•swappingprocessesintomainmemory
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Allocation of Swap Space
•Theswapdeviceisablockdeviceinaconfigurablesectionofadisk.
•Thespaceonswapdeviceisallocatedintheformofcontiguousblocks(asopposedto
singleblockallocationforfiles).
•Theallocationofspaceontheswapdeviceistransitory(asopposedtolonglastingfile
allocation).
•Aprocessthatresidesontheswapdevicewilleventuallymigratebacktomainmemory.
•SincespeediscriticalandthesystemcandoI/Ofasterinonemulti-blockoperationthan
inseveralsingleblockoperations,thekernelallocatescontiguousspaceontheswap
devicewithoutregardforfragmentation(asopposedtotheflexibleallocationforfiles
whichresultsintominimumfragmentation).
•Theallocationschemeforswapspaceallocationdiffersfromtheschemeusedforfile
systems.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Therefore,thedatastructuresalsodiffer.
•Thekernelmaintainsthefreespacefortheswapdeviceinanin-coretable,
calledmap.
•Amapisanarraywhereeachentryconsistsofanaddressofanallocatable
resourceandthenumberofresourceunitsavailablethere;thekernelinterprets
theaddressandunitsaccordingtothetypeofmap.
•Initially,amapcontainsoneentrythatindicatestheaddressandthetotal
numberofresources
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Initial Swap Map
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithm to allocate map space,malloc
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Allocation of Swap Space
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Allocation of Swap Space
•The following figures show the state of the map after allocating 100 units, 50
units, then 100 units again:
•Whenfreeingresources,thekernelfindstheirproperpositioninthemapby
address.Threecasesarepossiblehere:
•Thefreedresourcescompletelyfillaholeinthemap.Inthiscase,thekernel
combinesthenewlyfreedresourcesandtheexisting(two)entriesintooneentry
inthemap.
•Thefreedresourcespartiallyfillahole.Inthiscase,thekerneladjuststheaddress
andunitsfieldsofanappropriateentrytoaccountfortheresourcesjustfreed.
•Thefreedresourcespartiallyfillaholebutarenotcontiguoustoanyresourcesin
themap.Thenanewentryiscreatedandinsertedintheproperposition.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Consideringthepreviousexample,ifthekernelfrees50unitsofswapspace
startingataddress101,theswapmapwillcontainanewentry(case3).Ifthe
kernelthenfrees100unitsstartingataddress1,itadjuststhefirstentryofthe
swapmap(case2).Supposethekernelnowrequests200unitsofswapspace,
sincethefirstentrycannotsatisfytherequirement,thesecondentryismodified
andspaceisgivenfromaddress251to450,bothinclusive.
•Theseactionsareshownbelowonnextslide:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Allocating Swap Space from Secondary Entry in Map
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Swapping Processes Out of Main Memory
•Aprocessisswappedoutifthekernelneedsspaceinmemory.Itneedsspacein
memoryunderfollowingsituations:
•Theforksystemcallmustallocatespaceforachildprocess.
•Thebrksystemcallincreasesthesizeofaprocess.
•Aprocessbecomeslargerbythenaturalgrowthofitsstack.
•Thekernelwantstofreespaceinmemoryforprocessesithadpreviously
swappedoutandshouldnowswapin.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Whenthekerneldecidesthataprocessiseligibleforswappingfrommainmemory,it
decrementsthereferencecountofeachregionintheprocessandswapstheregionout
ifitsreferencecountdropsto0.
•Thekernelallocatesspaceonaswapdeviceandlockstheprocessinmemory(forcases
1-3),preventingswapperfromswappingitoutwhilethecurrentswapoperationisin
progress.
•Thekernelsavestheswapaddressoftheregionintheregiontableentry.
•Thebuffercacheisbypassedwhenthekernelswapsdatabetweentheswapdeviceand
useraddressspace.
•Ifmemoryisorganizedinpages,thedatatobeswappedoutislikelytobediscontiguous
inphysicalmemory.
•Thekernelmustgatherthepageaddressesofdatatobeswappedout,andthedisk
drivermayusethecollectionofpageaddressestosetuptheI/O.Theswapperwaitsfor
eachI/Ooperationtocompletebeforeswappingoutotherdata.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Itisnotnecessarythatthekernelwritetheentirevirtualaddressspaceofaprocess
toaswapdevice.
•Instead,itcopiesthephysicalmemoryassignedtoaprocesstotheallocatedspace
ontheswapdevice,ignoringunassignedvirtualaddresses.
•Whenthekernelswapstheprocessbackintomemory,itknowsthevirtualaddress
mapoftheprocess,soitcanreassigntheprocesstothecorrectvirtualaddresses.
•Thekerneleliminatesanextracopyfromadatabuffertophysicalmemoryby
readingthedataintothephysicalmemorylocationsthatwerepreviouslysetupto
conformtothevirtualaddresslocations.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Mapping process Space onto the Swap Device
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Swapping Processes Into the Main Memory
•Theswapperprocess(process0),istheonlyprocessthatswapsprocessesinto
memoryfromswapdevices.
•Aftersysteminitialization,theswappergoesintoaninfiniteloop,whereitsonly
taskistodoprocessswapping.
•Theswappersleepsifthereisnoworkforit.Swapperexecutesonlyinkernel
mode.
•Whenswapperwakesuptoswapprocessesin,itselectstheprocesseswhichhas
spentthelongesttimeinthestate"readytorunbutswappedout".
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithmswapper
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Theswappertriestoswapoutsleepingprocessesratherthanready-to-run
processes,becauseready-to-runprocessesmightgetscheduledearlierthansleeping
processes.
•Aready-to-runprocessmustbecoreresidentforatleast2secondsbeforebeing
swappedout,andaprocesstobeswappedinmusthavebeenswappedoutforat
least2seconds.
•Iftheswappercannotfindaprocessestoswapoutorifneithertheprocesstobe
swappedinnortheprocesstobeswappedouthaveaccumulatedmorethan2
secondsresidencetimeintheirenvironment,thenswappersleepsontheeventthat
itwantstoswapaprocessintomemorybutcannotfindroomforit.
•Theclockwillawakentheswapperonceasecondinthatstate.Thekernelalso
awakensswapperifanotherprocessgoestosleep,sinceitmaybemoreeligiblefor
swappingoutthantheprocessespreviouslyconsideredbytheswapper.Inanycase,
theswapperwakesupandbeginsexecutionfromthebeginning,attemptingtoswap
ineligibleprocesses
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•HereisanexampleofprocessschedulinginasystemwhereA,B,C,Daresame
sizedprocessesandonly2processescanstayinmainmemory.
•Thisistheschedulingtimeline:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Sequence of Swapping operations
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Theswapperchoosesprocessestoswapinbasedontheamountoftimethe
processeshadbeenswappedout.
•Anothercriterioncouldhavebeentoswapinthehighest-priorityprocessthatis
readytorun,sincesuchprocessesdeserveabetterchancetoexecute.
•Ithasbeendemonstratedthatsuchapolicyresultsin"slightly"betterthroughput
underheavysystemload.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thealgorithmforchoosingaprocesstoswapouthassomeseriousflaws:
•Theswapperswapsoutaprocessbasedonitspriority,memory-residencetime,
andnicevalue.
•Althoughitswapsoutaprocessonlytomakeroomforaprocessbeingswapped
in,itmayswapoutaprocessthatdoesnotprovideenoughmemoryforthe
incomingprocess.
•Forinstance,iftheswapperattemptstoswapinaprocessthatoccupies1
megabyteofmemoryandthesystemcontainsnofreememory,itisfutiletoswap
outaprocessthatoccupiesonly2Kbytesofmemory.
•Analternativestrategywouldbetoswapoutgroupsofprocessesonlyifthey
provideenoughmemoryfortheincomingprocess.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Iftheswappersleepsbecauseitcouldnotfindenoughmemorytoswapina
process,itsearchesagainforaprocesstoswapinalthoughithadpreviously
chosenone.
•Thereasonisthatotherswappedprocessesmayhaveawakenedinthemeantime
andtheymaybemoreeligibleforswappinginthanthepreviouslychosen
process.
•Butthatissmallsolacetotheoriginalprocessstilltryingtobeswappedin.
•Insomeimplementations,theswappertriestoswapoutmanysmallerprocesses
tomakeroomforthebigprocesstobeswappedinbeforesearchingforanother
processtoswapin;thisistherevisionintheswapperalgorithmshownbythe
commentsinthealgorithmgivenabove.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Iftheswapperchoosesa"ready-to-run"processtoswapout,itispossiblethat
theprocesshadnotexecutedsinceitwaspreviouslyswappedin.Thefollowing
figureshowssuchacase,wherethekernelswapsinprocessDatthe2-second
mark,schedulesprocessC,andthenswapsoutprocessDatthe3-secondmarkin
favorofprocessE(becauseoftheinteractionofthenicevalue)eventhough
processDhadneverrun.Suchthrashingisclearlyundesirable:
•Iftheswapperattemptstoswapoutaprocessbutcannotfindspaceontheswap
device,asystemdeadlockcouldariseifthefollowingfourconditionsaremet:
•Alltheprocessesinmainmemoryareasleep
•Alltheready-to-runprocessesareswappedout
•Thereisnoroomontheswapdevicefornewprocesses
•Thereisnoroominmainmemoryforincomingprocesses
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Demand Paging
•MachineswhosememoryarchitecturesisbasedonpagesandwhoseCPUhas
restartableinstructionscansupportakernelthatimplementsademandpaging
algorithm,swappingpagesofmemorybetweenmainmemoryandaswapdevice.
•Demandpagingsystemsfreeprocessesfromsizelimitationsotherwiseimposed
bytheamountofphysicalmemoryavailableonamachine.
•Thekernelstillhasalimitonthevirtualsizeofaprocess,dependentonthe
amountofvirtualmemorythemachinecanaddress.
•Demandpagingistransparenttotheuserexceptforthevirtualsizepermissible
toaprocess.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Theportionofthetextsectionwhichcontainsthefrequentlycalledsubroutines
andprogramloopsisasmallsubsetofthetotalspaceoftheprocess.Thisis
knownastheprincipleof"locality".
•Theworkingsetofaprocessisthesetofpagesthattheprocesshasreferencedin
itslastnmemoryreferences;thenumberniscalledthewindowoftheworking
set.
•Iftheworkingsetstaysinthememory,swappingcouldbereduced.
•Whenaprocessaddressesapagethatisnotinitsworkingset,itincursapage
fault;inhandlingthefault,thekernelupdatestheworkingset,readinginpages
fromasecondarydeviceifnecessary.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Working set a process
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Asshowninthediagram,workingsetswithlargerwindowsizesaremore
efficient,implyingthattheprocesswillnotfaultoftenasoften.
•Itisexpensivetoremembertheorderofpagereferences.Instead,systems
approximateaworkingsetmodelbysettingareferencebitwheneveraprocess
accessesapageandbysamplingmemoryreferencesperiodically:Ifapagewas
recentlyreferenced,itispartofaworkingset;otherwise,it"ages"inmemory
untilitiseligibleforswapping.
•Whenaprocessaccessesapagethatisnotpartofitsworkingset,itincurs
avaliditypagefault.Thekernelsuspendsexecutionoftheprocessuntilitreads
thepageintomemoryandmakesitaccessibletotheprocess.Whenthepageis
loadedinmemory,theprocessrestartstheinstructionitwasexecutingwhenit
incurredthefault.Thus,theimplementationofapagingsubsystemhastwo
parts:swappingrarelyusedpagestoaswappingdeviceandhandlingpagefaults.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Data Structures for Demand Paging
•Thekernelcontains4majordatastructurestosupportlow-levelmemory
managementfunctionsanddemandpaging:
•pagetableentries
•diskblockdescriptors
•pageframedatatable(calledpfdataforshort)
•swap-usetable
•pfdatatableisallocatedonceforthelifetimeofthesystem,butallocationsfor
otherstructurearedynamic.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Asseenpreviously,theregioncontainspagetablestoaccessphysicalmemory.
Eachentryofapagetablecontainsthephysicaladdressofthepage,protection
bitsindicatingwhetherprocessescanread,writeorexecutefromthepage,and
thefollowingbitfieldstosupportdemandpaging:
•Valid
•Reference
•Modify
•Copyonwrite
•Age
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thekernelsetsthevalidbittoindicatethatthecontentsofapagearelegal,but
thepagereferenceisnotnecessarilyillegalifthevalidbitisnotset.
•Thereferencebitindicateswhetheraprocessrecentlyreferencedapage,and
themodifybitindicateswhetheraprocessrecentlymodifiedthecontentsofa
page.
•Thecopyonwritebit,usedintheforksystemcall,indicatesthatthekernelmust
createanewcopyofthepagewhenaprocessmodifiesitscontents.
•Thekernelmanipulatestheagebitstoindicatehowlongapagehasbeena
memberoftheworkingsetofaprocess.
•Assumethekernelmanipulatesthevalid,copyonwrite,andagebits,andthe
hardwaresetsthereferenceandmodifybitsofthepagetableentry(later,a
hardwarethatdoesnothavethesecapabilitiesisconsidered).
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The structure of region

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Eachpagetableentryisassociatedwithadiskblockdescriptor,whichdescribes
thediskcopyofthevirtualpage.
•Processesthatsharearegionthereforeaccesscommonpagetableentriesand
diskblockdescriptors.
•Thecontentsofavirtualpagesareeitherinaparticularblockonaswapdevice,
inanexecutable,ornotonaswapdevice.Ifthepageisonaswapdevice,the
diskblockdescriptorcontainsthelogicaldevicenumberandblocknumber
containingthepagecontents.
•Ifthepageiscontainedinanexecutablefile,thediskblockdescriptorcontains
thelogicalblocknumberinthefilethatcontainsthepage;thekernelcanquickly
mapthisnumberintoitsdiskaddress.
•Thediskblockdescriptoralsoindicatestwospecialconditionssetduringexec:
thatapageis"demandfill"or"demandzero",studiedlater.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Pfdata table
•Thepfdatatabledescribeseachpageofphysicalmemoryandisindexedbypage
number.Itcontainsthesefields:
•Stateofthepage,indicatingthatthepageisonaswapdeviceorexecutablefile,
thatDMAiscurrentlyunderwayforthepage(readingdatafromaswapdevice),
orthatthepagecanbereassigned.
•Thenumberofprocessesthatreferencethepage.Thereferencecountequalsthe
numberofvalidpagetableentriesthatreferencethepage.Itmaydifferfromthe
numberofprocessesthatshareregionscontainingthepage,aswillbedescribed
belowwhenreconsideringthealgorithmfork.
•Thelogicaldevice(swaporfilesystem)andblocknumberthatcontainsacopyof
thepage.
•Pointerstootherpfdatatableentriesonalistoffreepagesandonahashqueue
ofpages.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Relationship between page table entries, disk block descriptors, pfdata table
entries, and the swap-use count table.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Fork in Paging System
•Inswappingsystems,thekernelcopiestheaddressspaceoftheparent.Butin
pagingsystem,forsharedregions,kerneljustincrementsthereferencecountin
theregiontableentrytosharetheregion.Andforprivateregionssuchasdata
andstack,thekernelallocatesanewregiontableentryandpagetable.Thenit
examinesthepagesontheparentprocessandiftheyarevalid,incrementsthe
referencecountinpfdatatableentry,sharingthepage(asopposedtosharingthe
region).
•Thekernelsetsthe"copy-on-write"bitinfork,forthesharedpagesintheprivate
regions.Ifanyprocesswritesonsuchsharedpage,itincursthe"protectionfault".
Inthefaulthandler,thekernelmakesacopyofpageandthentheprocesscan
writeonitsprivatecopy.Sothecopyingisdiffereduntilanactuallywrite
operationisdone.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The diagram below shows the kernel data structures after
theforksystem call:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Exec in a Paging System
•Onademandpagedsystem,theexecutablefilemaybetoolargetofitinthe
availablemainmemory.Therefore,thekerneldoesnotpreassignmemoryto
executablefilebut"faults"itin,assigningmemoryasneeded.Itfirstassignsthe
pagetablesanddiskblockdescriptorsfortheexecutablefile,markingthepage
tableentries"demandfill"(fornon-bssdata)or"demandzero"(forbssdata).
Followingavariantofreadalgorithmforreadingthefileintomemory,the
processincursavalidityfaultasitreadseachpage.Thefaulthandlernotes
whetherthepageis"demandfill",meaningitscontentswillimmediatelybe
overwrittenwiththecontentsoftheexecutablefilesoitneednotbecleared,or
thatitis"demandzero",meaningthatitscontentsshouldbecleared.Ifthe
processcannotfitintomemory,thepage-stealerprocessperiodicallyswaps
pagesfrommemory,makingroomfortheincomingfile.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Therearesomeinefficienciesinthisscheme:
•Aprocessincursapagefaultwhenreadingeachpageoftheexecutablefile,eventhoughitmay
neveraccessthepage.
•Thepagestealermayswappagesfrommemorybeforetheexecisdone,resultingintwoextra
swapoperationsperpageiftheprocessneedsthepageearly.
•Tomakeexecmoreefficient,thekernelcandemandpagedirectlyfromtheexecutablefileifthe
dataisproperlyaligned,asindicatedbyaspecialmagicnumber.However,useofstandard
algorithms(suchasbmap)toaccessafilewouldmakeitexpensivetodemandpagefromindirect
blocksbecauseofthemultiplebuffercacheaccessesnecessarytoreadablock.
•Consistencyproblemscouldarisebecausebmapisnotreentrant.ThekernelsetsvariousI/O
parametersintheu-areaduringthereadsystemcall.Ifaprocessincursapagefaultduring
areadsystemcallwhenattemptingtocopydatatouserspace,itwouldoverwritethesefieldsin
theu-areatoreadthepagefromthefilesystem.Therefore,thekernelcannotusetheregular
algorithmstofaultinpagesfromthefilesystem.Thealgorithmsare,ofcourse,reentrantin
regularcases,becauseeachprocesshasseparateu-areaandaprocesscannotsimultaneously
executemultiplesystemcalls.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The Page-Stealer Process
•Thepagestealerisakernelprocessthatswapsoutmemorypagesthatareno
longerpartoftheworkingsetofaprocess.
•Itiscreatedonsysteminitializationandisinvokedthroughoutthesystemlifetime
whensystemislowonfreepages.Itexamineseveryactive,unlockedregionand
incrementstheagefieldofallvalidpages.
•Thekernellocksaregionwhenaprocessfaultsonapageintheregion,sothat
thepagestealercannotstealthepagebeingfaultedin.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Therearetwopagingstatesforapageinmemory:thepageisagingandisnotyet
eligibleforswapping,orthepageiseligiblefroswappingandisavailablefor
reassignmenttoothervirtualpages.
•Thefirststateindicatesthataprocessrecentlyaccessedthepage.Some
machinessetareferencebitwhentheyreferenceapage,butsoftwaremethods
canbesubstitutedifthehardwaredoesnothavethisfeature.
•Thepagestealerturnsoffthereferencebitforsuchpagesbutremembershow
manyexaminationshavepassedsincethepagewaslastreferenced.
•Thefirststatethusconsistsofseveralsubstates,correspondingtothenumberof
passesthepagestealermakesbeforethepageiseligibleforswapping.
•Whenthenumberexceedsathresholdvalue,thekernelputsthepageintothe
secondstate,readytobeswapped.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

State diagram for Page Aging
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Page Faults
•Therearetwotypesofpagefaults:validityfaultsandprotectionfaults.
•Thefaulthandlersmayhavetoreadapagefromdisktomemoryandsleep
duringtheI/Ooperation,therefore,theyareanexceptiontothegeneralrulethat
interrupthandlerscannotsleep.
•Validity Fault Handler
•If a process attempts to access a page whosevalidbit is not set, it incurs a validity
fault and then the kernel invokes the validity fault handler.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Protection Fault Handler
•Ifaprocessaccessesavalidpagebutitspermissionbitsdonotpermitaccessto
it,theprocessincursaprotectionfault.Aprocessalsoincursaprotectionfault
whenitattemptstowriteapagewhosecopyonwritebitwassetduring
theforksystemcall.Thekernelmustdeterminewhetherpermissionwasdenied
becausethepagerequiresacopyonwriteorwhethersomethingtrulyillegal
happened.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

A Hybrid System with Swapping and Demand Paging
•Demandpagingsystemstreatmemorymoreflexiblythanswappingsystems.But
therecouldbesituationswherethepagestealerandvalidityfaulthandlerthrash
(spendmoretimeonswappingpagesratherthanprocessexecution)becauseof
shortageofmemory.Ifthesumoftheworkingsetsofallprocessesisgreater
thanthephysicalmemoryonamachine,thefaulthandlerwillusuallysleep,
becauseitcannotallocatepagesforaprocess.Thepagestealerwillnotbeable
tostealpagesfastenough,becauseallpagesareinaworkingset.System
throughputwillbeaffectedbadly.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•ThesystemVkernelrunsswappinganddemandpagingbothtoavoid
thrashing.Whenthekernelisnotabletoallocatepagesforaprocess,
itwakesuptheswapperandputsthecallingprocessinastate
equivalentto"readytorunbutswapped".Theswapperswapsout
entireprocessesuntilavailablememoryexceedsthehigh-watermark.
Foreachprocessswappedout,itmakesone"ready-to-runbut
swapped"processreadytorun.Itdoesnotswapthoseprocessesin
viathenormalswappingalgorithmbutletsthemfaultinpagesas
needed.Thismethodslowsdownthesystemfaultrateandreduces
thrashing.

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thank you….
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Tags