 
         
         
         
         
        
            已阅读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-2030碳中和目标下实木产业绿色转型路径探索报告
- 2025-2030硅基负极材料产能扩张节奏与性能改进路径分析报告
- 2025-2030矿山尾矿综合利用技术路线图
- 萍乡市中医院青年教师培养考核
- 2025-2030盐化工安全生产标准升级与企业风险管理体系建设专题报告
- 音乐顾问试题带答案
- 2025-2030现代物流体系智能化升级趋势与成本效益研究
- 2025-2030环境毒素对儿童神经突触形成的影响评估报告
- 2025-2030环保政策趋严背景下免漆门技术标准升级追踪报告
- 2025-2030环保即服务行业政策支持与市场需求匹配度报告
- 第二单元写作《学会记事》课件-统编版语文七年级上册
- 2025至2030输配电设备发展趋势分析与未来投资战略咨询研究报告
- 2025四川成都未来医学城招聘8人考试参考题库及答案解析
- 2025届四川省南充市高三第一次诊断考-化学试题+答案
- 脊髓损伤教学课件
- 山东省名校考试联盟2026届高三上学期10月阶段性检测化学试卷(含答案)
- (南开中学)重庆市高2026届高三第二次质量检测 历史试卷(含答案详解)
- 2025云南省曲靖市公开选拔市属国有企业领导人员及市场化选聘职业经理人(10人)笔试参考题库附带答案详解
- 急性高原反应指南解读
- 学生奖状印刷模板
- 光伏发电论文
 
            
评论
0/150
提交评论