




已阅读5页,还剩65页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter9:VirtualMemory,ChapterObjectives,TodescribethebenefitsofavirtualmemorysystemToexplaintheconceptsofdemandpaging,page-replacementalgorithms,andallocationofpageframesTodiscusstheprincipleoftheworking-setmodel,ContentOverview,BackgroundDemandPagingCopy-on-WritePageReplacementAllocationofFramesThrashingMemory-MappedFilesAllocatingKernelMemoryOtherConsiderationsOperating-SystemExamples,9.1Background,Virtualmemoryseparationofuserlogicalmemoryfromphysicalmemory.OnlypartoftheprogramneedstobeinmemoryforexecutionLogicaladdressspacecanthereforebemuchlargerthanphysicaladdressspaceAllowsaddressspacestobesharedbyseveralprocessesAllowsformoreefficientprocesscreationVirtualmemorycanbeimplementedvia:DemandpagingDemandsegmentation,VirtualMemoryThatisLargerThanPhysicalMemory,Virtual-addressSpace,SharedLibraryUsingVirtualMemory,9.2DemandPaging,BringapageintomemoryonlywhenitisneededLessI/OneededLessmemoryneededFasterresponseMoreusersPageisneededreferencetoitinvalidreferenceabortnot-in-memorybringtomemoryLazyswapperneverswapsapageintomemoryunlesspagewillbeneededSwapperthatdealswithpagesisapager,TransferofaPagedMemorytoContiguousDiskSpace,Valid-InvalidBit,Witheachpagetableentryavalidinvalidbitisassociated(vin-memory,inot-in-memory)InitiallyvalidinvalidbitissettoionallentriesExampleofapagetablesnapshot:Duringaddresstranslation,ifvalidinvalidbitinpagetableentryisIpagefault,v,v,v,v,i,i,i,.,Frame#,valid-invalidbit,pagetable,PageTableWhenSomePagesAreNotinMainMemory,PageFault,Ifthereisareferencetoapage,firstreferencetothatpagewilltraptooperatingsystem:pagefaultOperatingsystemlooksatanothertabletodecide:InvalidreferenceabortJustnotinmemoryGetemptyframeSwappageintoframeResettablesSetvalidationbit=vRestarttheinstructionthatcausedthepagefault,PageFault(Cont.),Restartinstructionblockmoveautoincrement/decrementlocation,StepsinHandlingaPageFault,PerformanceofDemandPaging,PageFaultRate0p1.0ifp=0nopagefaultsifp=1,everyreferenceisafaultEffectiveAccessTime(EAT)EAT=(1p)xmemoryaccess+p(pagefaultoverhead+swappageout+swappagein+restartoverhead),DemandPagingExample,Memoryaccesstime=200nanosecondsAveragepage-faultservicetime=8millisecondsEAT=(1p)x200+p(8milliseconds)=(1px200+px8,000,000=200+px7,999,800Ifoneaccessoutof1,000causesapagefault,thenEAT=8.2microseconds.Thisisaslowdownbyafactorof40!,ProcessCreation,Virtualmemoryallowsotherbenefitsduringprocesscreation:-Copy-on-Write-Memory-MappedFiles(later),9.3Copy-on-Write,Copy-on-Write(COW)allowsbothparentandchildprocessestoinitiallysharethesamepagesinmemoryIfeitherprocessmodifiesasharedpage,onlythenisthepagecopiedCOWallowsmoreefficientprocesscreationasonlymodifiedpagesarecopiedFreepagesareallocatedfromapoolofzeroed-outpages,BeforeProcess1ModifiesPageC,AfterProcess1ModifiesPageC,Whathappensifthereisnofreeframe?,Pagereplacementfindsomepageinmemory,butnotreallyinuse,swapitoutalgorithmperformancewantanalgorithmwhichwillresultinminimumnumberofpagefaultsSamepagemaybebroughtintomemoryseveraltimes,9.4PageReplacement,Preventover-allocationofmemorybymodifyingpage-faultserviceroutinetoincludepagereplacementUsemodify(dirty)bittoreduceoverheadofpagetransfersonlymodifiedpagesarewrittentodiskPagereplacementcompletesseparationbetweenlogicalmemoryandphysicalmemorylargevirtualmemorycanbeprovidedonasmallerphysicalmemory,NeedForPageReplacement,BasicPageReplacement,FindthelocationofthedesiredpageondiskFindafreeframe:-Ifthereisafreeframe,useit-Ifthereisnofreeframe,useapagereplacementalgorithmtoselectavictimframeBringthedesiredpageintothe(newly)freeframe;updatethepageandframetablesRestarttheprocess,PageReplacement,PageReplacementAlgorithms,Wantlowestpage-faultrateEvaluatealgorithmbyrunningitonaparticularstringofmemoryreferences(referencestring)andcomputingthenumberofpagefaultsonthatstringInallourexamples,thereferencestringis1,2,3,4,1,2,5,1,2,3,4,5,GraphofPageFaultsVersusTheNumberofFrames,First-In-First-Out(FIFO)Algorithm,Referencestring:1,2,3,4,1,2,5,1,2,3,4,53frames(3pagescanbeinmemoryatatimeperprocess)4framesBeladysAnomaly:moreframesmorepagefaults,1,2,3,1,2,3,4,1,2,5,3,4,9pagefaults,1,2,3,1,2,3,5,1,2,4,5,10pagefaults,4,4,3,FIFOPageReplacement,FIFOIllustratingBeladysAnomaly,OptimalAlgorithm,Replacepagethatwillnotbeusedforlongestperiodoftime4framesexample1,2,3,4,1,2,5,1,2,3,4,5Howdoyouknowthis?Usedformeasuringhowwellyouralgorithmperforms,1,2,3,4,6pagefaults,4,5,OptimalPageReplacement,LeastRecentlyUsed(LRU)Algorithm,Referencestring:1,2,3,4,1,2,5,1,2,3,4,5CounterimplementationEverypageentryhasacounter;everytimepageisreferencedthroughthisentry,copytheclockintothecounterWhenapageneedstobechanged,lookatthecounterstodeterminewhicharetochange,5,2,4,3,1,2,3,4,1,2,5,4,1,2,5,3,1,2,4,3,LRUPageReplacement,LRUAlgorithm(Cont.),Stackimplementationkeepastackofpagenumbersinadoublelinkform:Pagereferenced:moveittothetoprequires6pointerstobechangedNosearchforreplacement,UseOfAStacktoRecordTheMostRecentPageReferences,LRUApproximationAlgorithms,ReferencebitWitheachpageassociateabit,initially=0Whenpageisreferencedbitsetto1Replacetheonewhichis0(ifoneexists)Wedonotknowtheorder,howeverAdditional-ReferencebitAtimernbitsReferencebitsshiftSecondchanceNeedreferencebitClockreplacementIfpagetobereplaced(inclockorder)hasreferencebit=1then:setreferencebit0leavepageinmemoryreplacenextpage(inclockorder),subjecttosamerules,Second-Chance(clock)Page-ReplacementAlgorithm,CountingAlgorithms,KeepacounterofthenumberofreferencesthathavebeenmadetoeachpageLFUAlgorithm:replacespagewithsmallestcountMFUAlgorithm:basedontheargumentthatthepagewiththesmallestcountwasprobablyjustbroughtinandhasyettobeused,9.5AllocationofFrames,EachprocessneedsminimumnumberofpagesExample:IBM3706pagestohandleSSMOVEinstruction:instructionis6bytes,mightspan2pages2pagestohandlefrom2pagestohandletoTwomajorallocationschemesfixedallocationpriorityallocation,FixedAllocation,EqualallocationForexample,ifthereare100framesand5processes,giveeachprocess20frames.ProportionalallocationAllocateaccordingtothesizeofprocess,PriorityAllocation,UseaproportionalallocationschemeusingprioritiesratherthansizeIfprocessPigeneratesapagefault,selectforreplacementoneofitsframesselectforreplacementaframefromaprocesswithlowerprioritynumber,Globalvs.LocalAllocation,Globalreplacementprocessselectsareplacementframefromthesetofallframes;oneprocesscantakeaframefromanotherLocalreplacementeachprocessselectsfromonlyitsownsetofallocatedframes,9.6Thrashing,Ifaprocessdoesnothave“enough”pages,thepage-faultrateisveryhigh.Thisleadsto:lowCPUutilizationoperatingsystemthinksthatitneedstoincreasethedegreeofmultiprogramminganotherprocessaddedtothesystemThrashingaprocessisbusyswappingpagesinandout,Thrashing(Cont.),DemandPagingandThrashing,Whydoesdemandpagingwork?LocalitymodelProcessmigratesfromonelocalitytoanotherLocalitiesmayoverlapWhydoesthrashingoccur?sizeoflocalitytotalmemorysize,LocalityInAMemory-ReferencePattern,Working-SetModel,working-setwindowafixednumberofpagereferencesExample:10,000instructionWSSi(workingsetofProcessPi)=totalnumberofpagesreferencedinthemostrecent(variesintime)iftoosmallwillnotencompassentirelocalityiftoolargewillencompassseverallocalitiesif=willencompassentireprogramD=WSSitotaldemandframesifDmThrashingPolicyifDm,thensuspendoneoftheprocesses,Working-setmodel,KeepingTrackoftheWorkingSet,Approximatewithintervaltimer+areferencebitExample:=10,000Timerinterruptsafterevery5000timeunitsKeepinmemory2bitsforeachpageWheneveratimerinterruptscopyandsetsthevaluesofallreferencebitsto0Ifoneofthebitsinmemory=1pageinworkingsetWhyisthisnotcompletelyaccurate?Improvement=10bitsandinterruptevery1000timeunits,Page-FaultFrequencyScheme,Establish“acceptable”page-faultrateIfactualratetoolow,processlosesframeIfactualratetoohigh,processgainsframe,9.7Memory-MappedFiles,Memory-mappedfileI/OallowsfileI/OtobetreatedasroutinememoryaccessbymappingadiskblocktoapageinmemoryAfileisinitiallyreadusingdemandpaging.Apage-sizedportionofthefileisreadfromthefilesystemintoaphysicalpage.Subsequentreads/writesto/fromthefilearetreatedasordinarymemoryaccesses.SimplifiesfileaccessbytreatingfileI/Othroughmemoryratherthanread()write()systemcallsAlsoallowsseveralprocessestomapthesamefileallowingthepagesinmemorytobeshared,MemoryMappedFiles,Memory-MappedSharedMemoryinWindows,9.8AllocatingKernelMemory,TreateddifferentlyfromusermemoryOftenallocatedfromafree-memorypoolKernelrequestsmemoryforstructuresofvaryingsizesSomekernelmemoryneedstobecontiguous,BuddySystem,Allocatesmemoryfromfixed-sizesegmentconsistingofphysically-contiguouspagesMemoryallocatedusingpower-of-2allocatorSatisfiesrequestsinunitssizedaspowerof2Requestroundeduptonexthighestpowerof2Whensmallerallocationneededthanisavailable,currentchunksplitintotwobuddiesofnext-lowerpowerof2Continueuntilappropriatesizedchunkavailable,BuddySystemAllocator,SlabAllocator,AlternatestrategySlabisoneormorephysicallycontiguouspagesCacheconsistsofoneormoreslabsSinglecacheforeachuniquekerneldatastructureEachcachefilledwithobjectsinstantiationsofthedatastructureWhencachecreated,filledwithobjectsmarkedasfreeWhenstructuresstored,objectsmarkedasusedIfslabisfullofusedobjects,nextobjectallocatedfromemptyslabIfnoemptyslabs,newslaballocatedBenefitsincludenofragmentation,fastmemoryrequestsatisfaction,SlabAllocation,9.9OtherIssues-Prepaging,PrepagingToreducethelargenumberofpagefaultsthatoccursatprocessstartupPrepageallorsomeofthepagesaprocesswillneed,beforetheyarereferencedButifprepagedpagesareunused,I/OandmemorywaswastedAssumespagesareprepagedandofthepagesisusedIscostofs*savepagesfaultsorthanthecostofprepagings*(1-)unnecessarypages?nearzeroprepagingloses,OtherIssuesPageSize,Pagesizeselectionmusttakeintoconsideration:fragmentationtablesizeI/Ooverheadlocality,OtherIssuesTLBReach,TLBReach-TheamountofmemoryaccessiblefromtheTLBTLBReach=(TLBSize)X(PageSize)Ideally,theworkingsetofeachprocessisstoredintheTLBOtherwisethereisahighdegreeofpagefaultsIncreasethePageSizeThismayleadtoanincreaseinfragmentationasnotallapplicationsrequirealargepagesizeProvideMultiplePageSizesThisallowsapplicationsthatrequirelargerpagesizestheopportunitytousethemwithoutanincreaseinfragmentation,OtherIssuesProgramStructure,ProgramstructureInt128,128data;EachrowisstoredinonepageProgram1for(j=0;j128;j+)for(i=0;i128;i+)datai,j=0;128x128=16,384pagefaultsProgram2for(i=0;i128;i+)for(j=0;j128;j+)datai,j=0;128pagefaults,OtherIssuesI/Ointerlock,I/OInterlockPagesmustsometimesbelockedintomemoryConsiderI
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五版购房合同:交房商品房不动产购买指南
- 2025版股权转让合同公证协议书
- 二零二五年度建筑工程劳务分包合同及配套设施建设协议
- 2025版新能源发电项目合伙合同范本
- 二零二五年出借咨询及风险管理合作协议正范本16
- 2025版标准型二手叉车买卖合同模板
- 2025版电子商务股份收购合同样本
- 2025版智慧家居系统技术服务合同样本
- 2025雕塑加工技术改造与升级合同范本
- 2025版历史文化名城保护工程设计合同示范文本GF
- GB/T 30758-2014耐火材料动态杨氏模量试验方法(脉冲激振法)
- DBJT13-370-2021 福建省柔性饰面砖应用技术标准
- GB/T 11538-2006精油毛细管柱气相色谱分析通用法
- 动力网站-艾默生netsure801电源系统用户手册
- 大唐集团公司工作票、操作票使用和管理标准(版)
- 医学皮肤部年度业务报告课件
- 21年一消防工程师继续教育题
- 太阳能热水系统问题与解决方案
- (完整版)物理化学上教案
- D型便梁工法(二)
- 疑难路段处理能力及室项目分析
评论
0/150
提交评论