版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
Chapter9VirtualMemoryOperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsBackgroundVirtualmemory–separationofuserlogicalmemoryfromphysicalmemory.Onlypartoftheprogramneedstobeinmemoryforexecution.Logicaladdressspacecanthereforebemuchlargerthanphysicaladdressspace.MoreprogramscanberunatthesametimeLessI/ObeneededtoloadorswapVirtualmemorycanbeimplementedvia:DemandpagingDemandsegmentationOperatingSystemConceptsVirtualMemoryThatisLargerThanPhysicalMemoryOperatingSystemConceptsVirtual-addressSpaceUsuallydesignlogicaladdressspaceforstacktostartatMaxlogicaladdressandgrow“down”whileheapgrows“up”MaximizesaddressspaceuseUnusedaddressspacebetweenthetwoisholeNophysicalmemoryneededuntilheaporstackgrowstoagivennewpageOperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsDemandPagingBringapageintomemoryonlywhenitisneeded.LessI/OneededLessmemoryneededFasterresponseMoreusersPageisneededreferencetoitinvalidreferenceabortnot-in-memorybringtomemoryOperatingSystemConceptsValid-InvalidBitWitheachpagetableentryavalid–invalidbitisassociated
(1in-memory,0
not-in-memory)Initiallyvalid–invalidbitissetto0onallentries.Duringaddresstranslation,ifvalid–invalidbitinpagetableentryis0pagefault.OperatingSystemConceptsPageTableWhenSomePagesAreNotinMainMemoryOperatingSystemConceptsPageFaultIfthereiseverareferencetoapage,firstreferencewilltraptoOSpagefaultOSlooksatanothertabletodecide:Invalidreferenceabort.Justnotinmemory.Getemptyframe.Swappageintoframe.Resettables,validationbit=1.Restartinstructionblockmoveautoincrement/decrementlocationOperatingSystemConceptsStepsinHandlingaPageFaultOperatingSystemConceptsPerformanceofDemandPagingExtremecase–startprocesswithnopagesinmemoryOSsetsinstructionpointertofirstinstructionofprocess,non-memory-resident->pagefaultAndforeveryotherprocesspagesonfirstaccessPuredemandpagingOperatingSystemConceptsPerformanceofDemandPagingPageFaultRate0p1.0ifp=0nopagefaultsifp=1,everyreferenceisafault
EffectiveAccessTime(EAT) EAT=(1–p)xmemoryaccess +p(pagefaultoverhead +[swappageout] +swappagein +restartoverhead)PerformanceofDemandPagingMemoryaccesstime=200nanosecondsAveragefaultservicetime=8millisecondsEAT=(1–p)x200+p(8milliseconds)=200+px7,999,800Ifoneaccessoutof1,000causesapagefault,thenEAT=8.2microseconds.Thisisaslowdownbyafactorof40!!OperatingSystemConceptsPerformanceofDemandPagingIfwantperformancedegradation<10percent220>200+7,999,800xp
20>7,999,800xpp<.0000025<onepagefaultinevery400,000memoryaccessesOperatingSystemConceptsOperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsProcessCreationVirtualmemoryallowsotherbenefitsduringprocesscreation:
-Copy-on-Write
-Memory-MappedFiles(Later)OperatingSystemConceptsCopy-on-WriteCopy-on-Write(COW)allowsbothparentandchildprocessestoinitiallysharethesamepagesinmemory.(Nodemandpaging)Ifeitherprocessmodifiesasharedpage,onlythenisthepagecopied.COWallowsmoreefficientprocesscreationasonlymodifiedpagesarecopied.BeforeProcess1ModifiesPageCOperatingSystemConceptsAfterProcess1ModifiesPageCOperatingSystemConceptsOperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsWhathappensifthereisnofreeframe?Pagereplacement–findsomepageinmemory,butnotreallyinuse,swapitoutalgorithmperformance–wantanalgorithmwhichwillresultinminimumnumberofpagefaultsSamepagemaybebroughtintomemoryseveraltimesOperatingSystemConceptsPageReplacementPreventover-allocationofmemorybymodifyingfaultserviceroutinetoincludepagereplacement.Usemodify(dirty)bittoreduceoverheadofpagetransfers–onlymodifiedpagesarewrittentodisk.Pagereplacementcompletesseparationbetweenlogicalmemoryandphysicalmemory–largevirtualmemorycanbeprovidedonasmallerphysicalmemory.OperatingSystemConceptsNeedForPageReplacementOperatingSystemConceptsBasicPageReplacementFindthelocationofthedesiredpageondisk.Findafreeframe:
-Ifthereisafreeframe,useit.
-Ifthereisnofreeframe,useapagereplacement algorithmtoselectavictimframe.Readthedesiredpageintothe(newly)freeframe.Updatethepageandframetables.Restarttheinstruction.OperatingSystemConceptsPageReplacementOperatingSystemConceptsPageReplacementAlgorithmsWantlowestfaultrate.Evaluatealgorithmbyrunningitonaparticularstringofmemoryreferences(referencestring)andcomputingthenumberofpagefaultsonthatstring.Inallourexamples,thereferencestringis 1,2,3,4,1,2,5,1,2,3,4,5.OperatingSystemConceptsGraphofPageFaultsVersusTheNumberofFramesOperatingSystemConceptsFirst-In-First-Out(FIFO)AlgorithmReferencestring:1,2,3,4,1,2,5,1,2,3,4,53frames(3pagescanbeinmemoryatatimeperprocess)1231234125349pagefaultsOperatingSystemConceptsFirst-In-First-Out(FIFO)Algorithm4frames
FIFOReplacement–Belady’sAnomalymoreframesmorepagefaults1231235124510pagefaults443OperatingSystemConceptsFIFOIllustratingBelady’sAnamolyOperatingSystemConceptsFIFOPageReplacementOperatingSystemConceptsOptimalAlgorithmReplacepagethatwillnotbeusedforlongestperiodoftime.4framesexample 1,2,3,4,1,2,5,1,2,3,4,5
Howdoyouknowthis?Usedformeasuringhowwellyouralgorithmperforms.12346pagefaults45OperatingSystemConceptsOptimalPageReplacementOperatingSystemConceptsLeastRecentlyUsed(LRU)AlgorithmReferencestring:1,2,3,4,1,2,5,1,2,3,4,5
Counterimplementation(how?)Everypageentryhasacounter;everytimepageisreferencedthroughthisentry,copytheclockintothecounter.Whenapageneedstobechanged,lookatthecounterstodeterminewhicharetochange.12354435OperatingSystemConceptsLRUPageReplacementOperatingSystemConceptsLRUAlgorithm(Cont.)Stackimplementation–keepastackofpagenumbersinadoublelinkform:(How?Exercise1)Pagereferenced:moveittothetoprequires6pointerstobechangedNosearchforreplacementOperatingSystemConceptsUseOfAStacktoRecordTheMostRecentPageReferencesOperatingSystemConceptsLRUApproximationAlgorithmsReferencebitWitheachpageassociateabit,initially=0Whenpageisreferencedbitsetto1.Replacetheonewhichis0(ifoneexists).Wedonotknowtheorder,however.Additional-Reference-BitsAlgorithmKeepan8-bitbytesforeachpageAtregularintervalsshiftsthebitsright1bit,shiftthereferencebitintothehigh-orderbitInterpretthese8-bitbytesasunsignedintergers,thepagewithlowestnumberistheLRUpageOperatingSystemConceptsLRUApproximationAlgorithms(Cont.)Secondchance(linklistapproach?)Needreferencebit.Clockreplacement.Ifpagetobereplaced(inclockorder)hasreferencebit=1.then:setreferencebit0.leavepageinmemory.replacenextpage(inclockorder),subjecttosamerules.OperatingSystemConceptsSecond-Chance(clock)ReplacementAlgorithmOperatingSystemConceptsCountingAlgorithmsKeepacounterofthenumberofreferencesthathavebeenmadetoeachpage.
LFUAlgorithm:replacespagewithsmallestcount.
MFUAlgorithm:basedontheargumentthatthepagewiththesmallestcountwasprobablyjustbroughtinandhasyettobeused.OperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFrames
ThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsAllocationofFramesEachprocessneedsminimumnumberofpages.(why?Restartinstruction)Example:IBM370–6pagestohandleSSMOVEinstruction:instructionis6bytes,mightspan2pages.2pagestohandlefrom.2pagestohandleto.Twomajorallocationschemes.fixedallocationpriorityallocationOperatingSystemConceptsFixedAllocationEqualallocation–e.g.,if100framesand5processes,giveeach20pages.Proportionalallocation–Allocateaccordingtothesizeofprocess.OperatingSystemConceptsPriorityAllocationUseaproportionalallocationschemeusingprioritiesratherthansize.
IfprocessPigeneratesapagefault,selectforreplacementoneofitsframes.selectforreplacementaframefromaprocesswithlowerprioritynumber.OperatingSystemConceptsGlobalvs.LocalAllocationGlobalreplacement–processselectsareplacementframefromthesetofallframes;oneprocesscantakeaframefromanother.(benefit?Weakness?)Localreplacement–eachprocessselectsfromonlyitsownsetofallocatedframes.OperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsThrashingIfaprocessdoesnothave“enough”pages,thefaultrateisveryhigh.Thisleadsto:(howithappens?)lowCPUutilization.operatingsystemthinksthatitneedstoincreasethedegreeofmultiprogramming.anotherprocessaddedtothesystem.
Thrashing
aprocessisbusyswappingpagesinandout.OperatingSystemConceptsThrashingWhydoespagingwork?(howtoknowtheframenumbertoallocatetoaprocess?)
LocalitymodelProcessmigratesfromonelocalitytoanother.Localitiesmayoverlap.Whydoesthrashingoccur?
sizeoflocality>totalmemorysizeOperatingSystemConceptsLocalityInAMemory-ReferencePatternOperatingSystemConceptsWorking-SetModelworking-setwindowafixednumberofpagereferences
Example:10,000instructionWSSi(workingsetofProcessPi)=
totalnumberofpagesreferencedinthemostrecent(variesintime)iftoosmallwillnotencompassentirelocality.iftoolargewillencompassseverallocalities.if=willencompassentireprogram.OperatingSystemConceptsWorking-SetModel(Cont.)D=WSSitotaldemandframesifD>mThrashingPolicyifD>m,thensuspendoneoftheprocesses.OperatingSystemConceptsWorking-setmodelOperatingSystemConceptsKeepingTrackoftheWorkingSetApproximatewithintervaltimer+areferencebitExample:=10,000Timerinterruptsafterevery5000timeunits.Keepinmemory2bitsforeachpage.Wheneveratimerinterruptscopyandsetsthevaluesofallreferencebitsto0.Ifoneofthebitsinmemory=1pageinworkingset.Whyisthisnotcompletelyaccurate?Improvement=10bitsandinterruptevery1000timeunits.Whathappenswhenpagefaultoccurs?OperatingSystemConceptsFaultFrequencySchemeEstablish“acceptable”faultrate.Ifactualratetoolow,processlosesframe.Ifactualratetoohigh,processgainsframe.OperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsMemory-MappedFilesMemory-mappedfileI/OallowsfileI/Otobetreatedasroutinememoryaccessbymappingadiskblocktoapageinmemory.Afileisinitiallyreadusingdemandpaging.Asizedportionofthefileisreadfromthefilesystemintoaphysicalpage.Subsequentreads/writesto/fromthefilearetreatedasordinarymemoryaccesses.SimplifiesfileaccessbytreatingfileI/Othroughmemoryratherthanread()
write()systemcalls.Alsoallowsseveralprocessestomapthesamefileallowingthepagesinmemorytobeshared.OperatingSystemConceptsMemoryMappedFilesOperatingSystemConceptsMemory-MappedSharedMemoryinWindowsExample:linuxmmapFollowinglink:/developerworks/cn/linux/l-ipc/part5/index1.htmlOperatingSystemConceptsOperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsAllocatingKernelMemoryTreateddifferentlyfromusermemoryOftenallocatedfromafree-memorypoolKernelrequestsmemoryforstructuresofvaryingsizes,fragmentationneedtobetakencareofSomekernelmemoryneedstobecontiguousOperatingSystemConceptsBuddySystemAllocatesmemoryfromfixed-sizesegmentconsistingofphysically-contiguouspagesMemoryallocatedusingpower-of-2allocatorSatisfiesrequestsinunitssizedaspowerof2Requestroundeduptonexthighestpowerof2Whensmallerallocationneededthanisavailable,currentchunksplitintotwobuddiesofnext-lowerpowerof2ContinueuntilappropriatesizedchunkavailableOperatingSystemConceptsBuddySystemAllocator21KBkernelmemoryallocationrequestFragmentationproblemOperatingSystemConceptsSlabAllocatorAlternatestrategySlabisoneormorephysicallycontiguouspagesCacheconsistsofoneormoreslabsSinglecacheforeachuniquekerneldatastructureEachcachefilledwithobjects–instantiationsofthedatastructureOperatingSystemConceptsSlabAllocator(Cont)Whencachecreated,filledwithobjectsmarkedasfreeWhenstructuresstored,objectsmarkedasusedIfslabisfullofusedobjects,nextobjectallocatedfromemptyslabIfnoemptyslabs,newslaballocatedBenefitsincludenofragmentation,fastmemoryrequestsatisfactionOperatingSystemConceptsSlabAllocationSlabAllocationForexampleprocessdescriptorisoftypestructtask_structApprox1.7KBofmemoryNewtask->allocatenewstructfromcacheWilluseexistingfreestructtask_structSlabcanbeinthreepossiblestatesFull–allusedEmpty–allfreePartial–mixoffreeandusedUponrequest,slaballocatorUsesfreestructinpartialslabIfnone,takesonefromemptyslabIfnoemptyslab,createnewemptyOperatingSystemConceptsOperatingSystemConceptsChapter9:VirtualMemoryBackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamplesOperatingSystemConceptsOtherIssues--PrepagingPrepagingToreducethelargenumberofpagefaultsthatoccursatprocessstartupPrepageallorsomeofthepagesaprocesswillneed,beforetheyarereferenced(worksetmodel)Butifprepagedpagesareunused,I/OandmemorywaswastedAssumespagesareprepagedandα
ofthepagesisusedIscostofs*α
savepagesfaults>or<thanthecostofprepaging
s*(1-α)unnecessarypages?α
nearzeroprepagingloses
OperatingSystemConceptsOtherIssues–PageSizePagesizeselectionmusttakeintoconsideration:Fragmentation(?)tablesize(?)I/Ooverhead(?)Locality(?)OperatingSystemConceptsOtherIssues–TLBReachTLBReach-TheamountofmemoryaccessiblefromtheTLBTLBReach=(TLBSize)X(PageSize)Ideally,theworkingsetofeachprocessisstoredintheTLBOtherwisethereisahighdegreeofpagefaultsIncreasethePageSizeProvideMultiplePageSizesThisallowsapplicationsthatrequirelargerpagesizestheopportunitytousethemwithoutanincreaseinfragmentationOperatingSystemConceptsOtherIssues–ProgramStructureProgramstructureintA[][]=newint[1024]
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024版泥水作業(yè)班組承包協(xié)議書
- 二零二五年度股權(quán)收益權(quán)轉(zhuǎn)讓合同范本與收益分配3篇
- 二零二五年航空航天零部件制造合同協(xié)議模板2025版3篇
- 二零二五年金融產(chǎn)品居間服務(wù)協(xié)議范本3篇
- 二零二五年度智能化設(shè)備技術(shù)入股合作協(xié)議范本3篇
- GRC材質(zhì)2024裝飾構(gòu)件定制合作協(xié)議版B版
- 二零二五版汽車租賃轉(zhuǎn)讓與保險責任合同2篇
- 2024混凝土施工勞務(wù)分包合同
- 2024年跨區(qū)域生態(tài)環(huán)境保護合作協(xié)議
- 西安工商學院《MAPLE編程及工程應用》2023-2024學年第一學期期末試卷
- 2020小升初復習-小升初英語總復習題型專題訓練-完形填空15篇
- 2023年浙江省公務(wù)員考試面試真題解析
- GB/T 5796.3-2022梯形螺紋第3部分:基本尺寸
- GB/T 16407-2006聲學醫(yī)用體外壓力脈沖碎石機的聲場特性和測量
- 簡潔藍色科技商業(yè)PPT模板
- 錢素云先進事跡學習心得體會
- 道路客運車輛安全檢查表
- 宋曉峰辣目洋子小品《來啦老妹兒》劇本臺詞手稿
- 附錄C(資料性)消防安全評估記錄表示例
- 噪音檢測記錄表
- 推薦系統(tǒng)之協(xié)同過濾算法
評論
0/150
提交評論