paging - swarthmore college solution is paging. paging vocabulary • for each process, the virtual...
TRANSCRIPT
![Page 1: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/1.jpg)
Paging11/10/16
![Page 2: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/2.jpg)
RecallfromTuesday
Oursolutiontofragmentationistosplitupaprocess’saddressspaceintosmallerchunks.
Process1
OS
Process2
Process1
Process3
Process2
PhysicalMemory
OS:Place
Process3
Process3
Process3
Process3
![Page 3: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/3.jpg)
RecallfromTuesday
Wesupportvirtualaddressingbytranslatingaddressesatruntime.
Wecan’tachievethisusingbaseandboundregistersunlesseachprocess’smemoryisallinoneblock. P2
0
N2-1
P2
P1
P3
0
N-1
Base +
<
Bound
y/n?
![Page 4: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/4.jpg)
Howcanwedoboth?
• Wewanttosupporttranslationofvirtualaddressestophysicaladdresseson-the-fly.
• Wewanttosplitupeachprocess’saddressspacetousephysicalmemorymoreefficiently.
Thesolutionispaging.
![Page 5: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/5.jpg)
PagingVocabulary
• Foreachprocess,thevirtual addressspaceisdividedintofixed-sizepages.
• Forthesystem,thephysical memoryisdividedintofixed-sizeframes.
• Thesizeofapageisequaltothatofaframe.• Often4KBinpractice.
![Page 6: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/6.jpg)
MainIdea
• ANYvirtualpagecanbestoredinanyavailableframe.• Makesfindinganappropriately-sizedmemorygapveryeasy– they’reallthesamesize.
• Foreachprocess,OSkeepsatablemappingeachvirtualpagetophysicalframe.
![Page 7: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/7.jpg)
MainIdea
• ANYvirtualpagecanbestoredinanyavailableframe.• Makesfindinganappropriately-sizedmemorygapveryeasy– they’reallthesamesize.
PhysicalMemory
VirtualMemory
(OSMapping)Implicationsforfragmentation?
External:goesaway.Nomoreawkwardly-sized,unusablegaps.
Internal:Aboutthesame.Processcanalwaysrequestmemoryandnotuseit.
![Page 8: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/8.jpg)
Addressing
• Likewedidwithcaching,we’regoingtochopupmemoryaddressesintopartitions.
• Virtualaddresses:• High-orderbits:page#• Low-orderbits:offsetwithinthepage
• Physicaladdresses:• High-orderbits:frame#• Low-orderbits:offsetwithintheframe
![Page 9: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/9.jpg)
Example:32-bitvirtualaddresses
• Supposewehave8-KB(8192-byte)pages.• Weneedenoughbitstoindividuallyaddresseachbyteinthepage.• Howmanybitsdoweneedtoaddress8192items?
![Page 10: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/10.jpg)
Example:32-bitvirtualaddresses
• Supposewehave8-KB(8192-byte)pages.• Weneedenoughbitstoindividuallyaddresseachbyteinthepage.• Howmanybitsdoweneedtoaddress8192items?• 213 =8192,soweneed13bits.• Lowest13bits:offsetwithinpage.
![Page 11: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/11.jpg)
Example:32-bitvirtualaddresses
• Supposewehave8-KB(8192-byte)pages.• Weneedenoughbitstoindividuallyaddresseachbyteinthepage.• Howmanybitsdoweneedtoaddress8192items?• 213 =8192,soweneed13bits.• Lowest13bits:offsetwithinpage.
• Remaining19bits:pagenumber.
We’llcallthesebitsp. We’llcallthesebitsi.
![Page 12: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/12.jpg)
We’llcallthesebitsp. We’llcallthesebitsi.
OSPageTableForProcess
Virtualaddress:
Physicaladdress:
We’ll(still)callthesebitsi.We’llcallthesebitsf.
Whereisthispageinphysicalmemory?(Inwhichframe?)
Oncewe’vefoundtheframe,whichbyte(s)dowewanttoaccess?
AddressPartitioning
![Page 13: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/13.jpg)
PhysicalAddress
LogicalAddressPagep Offseti
FrameV Perm …R D
PhysicalMemory
PageTable
AddressTranslation
![Page 14: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/14.jpg)
PageTable• Onetableperprocess• Tableentryelements• V:validbit• R:referencedbit• D:dirtybit• Frame:locationinphy mem• Perm:accesspermissions
• Tableparametersinmemory• Pagetablebaseregister• Pagetablesizeregister
FrameV Perm …PTBRPTSR
R D
![Page 15: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/15.jpg)
• Virtualaddress=p+i• Physicaladdress=f+i• First,doaseriesofchecks
LogicalAddressPagep Offseti
PhysicalAddress
FrameV Perm …R D
AddressTranslation
![Page 16: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/16.jpg)
CheckifPagep isWithinRangeLogicalAddress
Pagep
PTBRPTSR
p <PTSR
Offseti
PhysicalAddress
FrameV Perm …R D
![Page 17: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/17.jpg)
CheckifPageTableEntryp isValidLogicalAddress
Pagep
PTBRPTSR
V==1
Offseti
PhysicalAddress
FrameV Perm …R D
![Page 18: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/18.jpg)
CheckifOperationisPermittedLogicalAddress
Pagep
PTBRPTSR
Perm(op)
Offseti
PhysicalAddress
FrameV Perm …R D
![Page 19: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/19.jpg)
TranslateAddressLogicalAddress
Pagep
PTBRPTSR
Offseti
PhysicalAddress
FrameV Perm …R D
concat
![Page 20: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/20.jpg)
PhysicalAddressbyConcatenation
LogicalAddressPagep
PTBRPTSR
Offseti
FrameV Perm …R D
PhysicalAddressFramef Offseti
![Page 21: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/21.jpg)
SizingthePageTableLogicalAddress
Pagep Offseti
Numberofbitsnspecifiesmaxsizeoftable,wherenumberofentries=2n
Numberofbitsneededtoaddressphysicalmemoryinunitsofframes
Numberofbitsspecifiespagesize
FrameV Perm …R D
![Page 22: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/22.jpg)
ExampleofSizingthePageTable
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
Pagep:20bits Offseti:12bits
…
FrameV Perm …R D
![Page 23: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/23.jpg)
Howmanyentries(rows)willtherebeinthispagetable?A. 212,becausethat’showmanytheoffsetfieldcan
addressB. 220,becausethat’showmanythepagefieldcan
addressC. 230,becausethat’showmanyweneedtoaddress1
GBD. 232,becausethat’sthesizeoftheentireaddress
space
![Page 24: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/24.jpg)
ExampleofSizingthePageTable
Howbigisaframe?
Pagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
…
FrameV Perm …R D
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
![Page 25: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/25.jpg)
Whatwillbetheframesize,inbytes?A. 212,becausethat’showmanybytestheoffset
fieldcanaddressB. 220,becausethat’showmanybytesthepagefield
canaddressC. 230,becausethat’showmanybytesweneedto
address1GBD. 232,becausethat’sthesizeoftheentireaddress
space
![Page 26: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/26.jpg)
ExampleofSizingthePageTablePagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
Pagesize=framesize=212 =4096bytes
…
FrameV Perm …R D
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
![Page 27: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/27.jpg)
Howmanybitsdoweneedtostoretheframenumber?
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
A:12 B:18C:20D:30E:32
Pagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
?
Pagesize=framesize=212 =4096bytes
…
FrameV Perm …R D
![Page 28: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/28.jpg)
ExampleofSizingthePageTable
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
Pagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
18bitstoaddress230/212 frames
Pagesize=framesize=212 =4096bytes
…
Sizeofanentry?
FrameV Perm …R D
![Page 29: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/29.jpg)
Howbigisanentry,inbytes?(Roundtoapoweroftwobytes.)
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
A:1B:2 C:4 D:8E:16
Pagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
18bitstoaddress230/212 frames
Pagesize=framesize=212 =4096bytes
…
Sizeofanentry?
FrameV Perm …R D
![Page 30: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/30.jpg)
ExampleofSizingthePageTable
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
Pagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
18bitstoaddress230/212 frames
Pagesize=framesize=212 =4096bytes
…
4bytesneededtocontain24(1+1+1+18+3+…)bits
FrameV Perm …R D
Totaltablesize?
![Page 31: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/31.jpg)
ExampleofSizingthePageTable
• 32bitvirtualaddresses,1GBphysicalmemory• Addresspartition:20bitpagenumber,12bitoffset
Pagep:20bits Offseti:12bits
20bitstoaddress220=1Mentries
18bitstoaddress230/212 frames
Pagesize=framesize=212 =4096bytes
…
4bytesneededtocontain24(1+1+1+18+3+…)bits Tablesize=
1Mx4=4MB
FrameV Perm …R D
![Page 32: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/32.jpg)
Concerns
• 4MBofbookkeepingforeveryprocess?• 200processes->800MBjusttostorepagetables…
• We’regoingtoneedatonofmemoryjustforpagetables…
• Weneedtodoalookupinourpagetable,whichisinmemory,everytimeaprocessaccessesmemory.• Isn’tthatslowingdownmemorybyafactorof2?
![Page 33: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/33.jpg)
Multi-LevelPageTables(You’renotresponsibleforthis.TakeanOSclassforthedetails.)
LogicalAddress1st-levelPaged Offseti
FrameV …R D
2nd-levelPagep
FrameV …R DPointsto(base)framecontaining2nd-levelpagetable
concat
PhysicalAddressReducesmemoryusageSIGNIFICANTLY:onlyallocatepagetablespacewhenweneedit.Morememoryaccessesthough…
![Page 34: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/34.jpg)
Cachingthepagetable
• Eachlookupcostsanothermemoryreference• Foreachreference,additionalreferencesrequired• Slowsmachinedownbyfactorof2ormore
• Takeadvantageoflocality• Mostreferencesaretoasmallnumberofpages• Keeptranslationsoftheseinhigh-speedmemory(acacheforpagetranslation)
![Page 35: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/35.jpg)
VMImplications
• Notallpiecesneedtobeinmemory• Needonlypiecebeingreferenced• Otherpiecescanbeondisk• Bringpiecesinonlywhenneeded
• Illusion:thereismuchmorememory• What’sneededtosupportthisidea?• Awaytoidentifywhetherapieceisinmemory• Awaytobringinpieces(fromwhere,towhere?)• Relocation(whichwehave)
![Page 36: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/36.jpg)
SampleContentsofPageTableEntry
• Valid:isentryvalid(pageinphysicalmemory)?• Ref:hasthispagebeenreferencedyet?• Dirty:hasthispagebeenmodified?• Frame:whatframeisthispagein?• Protection:whataretheallowableoperations?• read/write/execute
FramenumberValid Ref Dirty Prot:rwx
![Page 37: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/37.jpg)
Pagefaults
Apagefaultoccurswhenwetrytoaccessavirtualaddressthathasnocorrespondingphysicaladdress.
mechanismforhandlingapagefault:1. readinthevirtualpagefromdisk
• Locationkeptinkerneldatastructure.2. storeitinaphysicalmemoryframe
• Mayneedtokicksomethingelseout.3. UpdatePTEwithframenum &validbit=14. Restartinstructionthatcausedthepagefault
![Page 38: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/38.jpg)
PageFaultsareExpensive
• Disk:5-6ordersmagnitudeslowerthanRAM• Veryexpensive;butifveryrare,tolerable
• Example• RAMaccesstime:100nsec• Diskaccesstime:10msec• p =pagefaultprobability• Effectiveaccesstime:100+p × 10,000,000nsec• Ifp =0.1%,effectiveaccesstime=10,100nsec !
![Page 39: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/39.jpg)
Handingfaultsfromdiskseemsveryexpensive.Howcanwegetawaywiththisinpractice?
A. Wehavelotsofmemory,anditisn’tusuallyfull.
B. Weusespecialhardwaretospeedthingsup.
C. Wetendtousethesamepagesoverandover.
D. Thisistoocommon&expensivetodoinpractice!
![Page 40: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/40.jpg)
PrincipleofLocality
• Notallpiecesreferenceduniformlyovertime• Makesuremostreferencedpiecesinmemory• Ifnot,thrashing:constantfetchingofpieces
• Referencesclusterintime/space• Willbetosameorneighboringareas• Allowspredictionbasedonpast
![Page 41: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/41.jpg)
PageReplacement
• Goal:removepage(s)notexhibitinglocality
• Pagereplacementisabout• whichpage(s)toremove• whentoremovethem
• Howtodoitinthecheapestwaypossible• Leastamountofadditionalhardware• Leastamountofsoftwareoverhead
![Page 42: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/42.jpg)
BasicPageReplacementAlgorithms
• FIFO:selectpagethatisoldest• Simple:useframeordering• Doesn’tperformverywell(oldestmaybepopular)
• OPT:selectpagetobeusedfurthestinfuture• Optimal,butrequiresfutureknowledge• Establishesbestcase,goodforcomparisons
• LRU:selectpagethatwasleastrecentlyused• Predictfuturebasedonpast;worksgivenlocality• Costly:time-stamppageseachaccess,findleast
• Goal:minimizereplacements(maximizelocality)
![Page 43: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/43.jpg)
Summary• Wegiveeachprocessavirtualaddressspacetosimplifyprocessexecution.
• OSmaintainsmappingofvirtualaddresstophysicalmemorylocationsinapagetable.• Onepagetableforeveryprocess
• Providestheabstractionofverylargememory:notallpagesneedberesidentinmemory• Bringpagesinfromdiskondemand
![Page 44: Paging - Swarthmore College solution is paging. Paging Vocabulary • For each process, the virtual address space is divided into fixed-size pages. • For the system, the physicalmemory](https://reader031.vdocuments.us/reader031/viewer/2022022508/5acef9bb7f8b9a6c6c8c8547/html5/thumbnails/44.jpg)
WorksheetexampleStepthroughthestreamofVirtualAddressesfromtheCPU:
• ShowhowthebitsofeachaddressareusedforeachVirtualAddress&itsPhysicalAddressmapping• TranslateeachVAtoitsPAusingtheappropriatePTE• UpdatePTEsappropriatelyasyougo• ShowthehistoryofthecontentsofRAMastheseaddressesareaccessed• Whichvirtualpageofwhichprocessdoesitstore
• ImplementaFIFOpagereplacementpolicyforRAM
44