




已阅读5页,还剩55页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter9MemoryManagement,BackgroundLogicalversusPhysicalAddressSpaceSwappingContiguousAllocationPagingSegmentationSegmentationwithPaging,Background,Programmustbebroughtintomemoryandplacedwithinaprocessforittobeexecuted.Inputqueuecollectionofprocessesonthediskthatarewaitingtobebroughtintomemoryforexecution.Userprogramsgothroughseveralstepsbeforebeingexecuted.(forexample),Multistepprocessingofauserprogram,BindingofInstructionsandDatatoMemory,Compiletime:Ifmemorylocationknownapriori,absolutecodecanbegenerated;mustrecompilecodeifstartinglocationchanges.Loadtime:Mustgeneraterelocatablecodeifmemorylocationisnotknownatcompiletime.Executiontime:Bindingdelayeduntilruntimeiftheprocesscanbemovedduringitsexecutionfromonememorysegmenttoanother.Needhardwaresupportforaddressmaps(e.g.,baseandlimitregisters).,Logicalvs.PhysicalAddressSpace,Theconceptofalogicaladdressspacethatisboundtoaseparatephysicaladdressspaceiscentraltopropermemorymanagement.LogicaladdressgeneratedbytheCPU;alsoreferredtoasvirtualaddress.Physicaladdressaddressseenbythememoryunit.(forexample)Logicalandphysicaladdressesarethesameincompile-timeandload-timeaddress-bindingschemes;logical(virtual)andphysicaladdressesdifferinexecution-timeaddress-bindingscheme.,Example,0LOADAX,6;AXValue62ADDAX,8;AXAX+Value84SROREAX,10;Value10AX6A8B10A+B,Relocation,ModifythecontentsrelatedtotheaddressesinuserprogramBindtheselogicaladdressestophysicaladdressesTwotypesofrelocations:Staticrelocation:Programsmustberelocatedbycompiler/linkerbeforeenteringmemory.Dynamicrelocation:Programsmaynotberelocateduntilexecutingthecommandsrelatedtoaddresses.,Examples,Dynamicrelocationusingarelocationregister,DynamicLoading,Routineisnotloadeduntilitiscalled.Bettermemory-spaceutilization;unusedroutineisneverloaded.Usefulwhenlargeamountsofcodeareneededtohandleinfrequentlyoccurringcases.Nospecialsupportfromtheoperatingsystemisrequiredimplementedthroughprogramdesign.,DynamicLinking,Linkingpostponeduntilexecutiontime.Smallpieceofcode,stub,usedtolocatetheappropriatememory-residentlibraryroutine.Stubreplacesitselfwiththeaddressoftheroutine,andexecutestheroutine.Operatingsystemneededtocheckifroutineisinprocessesmemoryaddress.,Overlays,Keepinmemoryonlythoseinstructionsanddatathatareneededatanygiventime.Neededwhenprocessislargerthanamountofmemoryallocatedtoit.Implementedbyuser,nospecialsupportneededfromoperatingsystem,programmingdesignofoverlaystructureiscomplex.,Overlaysforatwo-passassembler,Memory-ManagementUnit(MMU),Hardwaredevicethatmapsvirtualtophysicaladdress.InMMUscheme,thevalueintherelocationregisterisaddedtoeveryaddressgeneratedbyauserprocessatthetimeitissenttomemory.Theuserprogramdealswithlogicaladdresses;itneverseestherealphysicaladdresses.,Swapping,Aprocesscanbeswappedtemporarilyoutofmemorytoabackingstore,andthenbroughtbackintomemoryforcontinuedexecution.Backingstorefastdisklargeenoughtoaccommodatecopiesofallmemoryimagesforallusers;mustprovidedirectaccesstothesememoryimages.,Swapping,Rollout,rollinswappingvariantusedforpriority-basedschedulingalgorithms;lower-priorityprocessisswappedoutsohigher-priorityprocesscanbeloadedandexecuted.Majorpartofswaptimeistransfertime;totaltransfertimeisdirectlyproportionaltotheamountofmemoryswapped.Modifiedversionsofswappingarefoundonmanysystems,i.e.,UNIXandMicrosoftWindows.,SchematicViewofSwapping,ContiguousAllocation,Mainmemoryusuallydividedintotwopartitions:Residentoperatingsystem,usuallyheldinlowmemorywithinterruptvector.Userprocessesthenheldinhighmemory.Single-partitionallocationRelocation-registerschemeusedtoprotectuserprocessesfromeachother,andfromchangingoperating-systemcodeanddata.Relocationregistercontainsvalueofsmallestphysicaladdress;limitregistercontainsrangeoflogicaladdresseseachlogicaladdressmustbelessthanthelimitregister.,ContiguousAllocation(Cont.),Multiple-partitionallocationHoleblockofavailablememory;holesofvarioussizearescatteredthroughoutmemory.Whenaprocessarrives,itisallocatedmemoryfromaholelargeenoughtoaccommodateit.Operatingsystemmaintainsinformationabout:a)allocatedpartitionsb)freepartitions(hole),Datastructure:Freepartitionstable,Processlist:A(10),B(45),C(25),D(30).,OS,1/A,2/C,3/B,4/,30K,45K,75K,125K,225K,0K,#length(kb)begin(k)state41001250,freepartitionstable,allocatedpartitionstable,ExampleforContiguousAllocation,ExampleforContiguousAllocation(Cont.),Ifp6(80k)come,howtoallocate?,100k,300k,260k,DynamicStorage-AllocationProblem,First-fit(首次适应):Allocatethefirstholethatisbigenough.Best-fit(最佳适应):Allocatethesmallestholethatisbigenough;mustsearchentirelist,unlessorderedbysize.Producesthesmallestleftoverhole.Worst-fit(最差适应):Allocatethelargesthole;mustalsosearchentierlist.Producesthelargestleftoverhole.,First-fitandbest-fitbetterthanworst-fitintermsofspeedandstorageutilization.,DynamicpartitionallocationExample,Proglist:,A(10),B(50),C(25),B,D(48),#length(kb)begin(k)state1610300234.,OS,0,30,640,A(10),60040,B(50),40,90,55090,C(25),115,525115,5040525115,0,D(48),288525115,ALLOCATIONOVER,C,55288,OVER,Releasepartitions,Fragmentation,Externalfragmentation(外碎片)totalmemoryspaceexiststosatisfyarequest,butitisnotcontiguous.Internalfragmentation(内碎片)allocatedmemorymaybeslightlylargerthanrequestedmemory;thissizedifferenceismemoryinternaltoapartition,butnotbeingused.ReduceexternalfragmentationbycompactionShuffle整理memorycontentstoplaceallfreememorytogetherinonelargeblock.Compactionispossibleonlyifrelocationisdynamic,andisdoneatexecutiontime.Whendocompaction?,Compact,Paging,Whyneedpaging?NeedcontiguousmemoryFragmentCompactingcostSolutionChangecontiguousallocationintononcontiguousallocationProblemCanlogicaladdressspaceofaprocessbenoncontiguous?Processisallocatedphysicalmemorywheneverthelatterisavailable.,Paging(cont),Dividephysicalmemoryintofixed-sizedblockscalledframes(sizeis2n),number0,1,2Dividelogicalmemoryintoblocksofsamesizecalledpages.number0,1,2Logicaladdress:v=(P,d),(v=p*size+d)Keeptrackofallfreeframes.Torunaprogramofsizenpages,needtofindnfreeframesandloadprogram.,Paging(cont),Setupapagetabletotranslatelogicaltophysicaladdresses.Setupapagetableregisterinclude:Page-tablebaseregister页表基址寄存器(PTBR)Page-tablelengthregister页表限长寄存器(PRLR)indicte:beginaddrandlengthofcurrentprogresspagetable,PagingExample,Processlogicaladdrspace,PagingExample,.,frames,0,1,2,3,4,5,6,7,8,9,10,11,12,0123,02132638,page#frame#,ProcessA,A0,A1,A2,A3,012,ProB,0417212,page#frame#,B0,B1,B2,OVER,AddressTranslationScheme,AddressgeneratedbyCPUisdividedinto:Pagenumber(p)(页号)usedasanindexintoapagetablewhichcontainsbaseaddressofeachpageinphysicalmemory.Pageoffset(d)(偏移)combinedwithbaseaddresstodefinethephysicalmemoryaddressthatissenttothememoryunit.,AddressTranslationArchitecture,AddressTranslationexample,Frames,0,1,3,4,5,6,7,8,9,10,11,12,A0,A1,A2,A3,2,02132638,page#frame#,V=(2,d),PTR,BL,L,(6,d),Offsetd,Logicaladdressv,V=2130,pagesize=1k,physicaladdr=?,Problem,Pagetableiskeptinmainmemory.Inthisschemeeverydata/instructionaccess,howmanymemoryaccessesarerequired?,Two:Oneforthepagetableandoneforthedata/instruction.,Thetwomemoryaccessproblemcanbesolvedbytheuseofaspecialfast-lookuphardwarecachecalledassociativeregistersortranslationlook-asidebuffers变换后备存储器TLBs,AssociativeRegister,Associativeregisters联想寄存器parallelsearchAddresstranslation(A,A)IfAisinassociativeregister,getframe#out.Otherwisegetframe#frompagetableinmemory.,PaginghardwarewithTLB,EffectiveAccessTime,AssociativeLookup=timeunitAssumememorycycletimeis1microsecondHitrationpercentageoftimesthatapagenumberisfoundintheassociativeregisters;rationrelatedtonumberofassociativeregisters.Hitratio=EffectiveAccessTime(EAT)EAT=(1+)+(2+)(1)=2+,MemoryProtection,Memoryprotectionimplementedbyassociatingprotectionbitwitheachframe.Valid-invalidbit有效-无效位attachedtoeachentryinthepagetable:“valid”indicatesthattheassociatedpageisintheprocesslogicaladdressspace,andisthusalegalpage.“invalid”indicatesthatthepageisnotintheprocesslogicaladdressspace.,Valid(v)orinvalid(i)bitinaPagetable,Two-LevelPage-TableScheme,Two-LevelPagingExample,Alogicaladdress(on32-bitmachinewith4Kpagesize)isdividedinto:apagenumberconsistingof20bits.apageoffsetconsistingof12bits.Sincethepagetableispaged,thepagenumberisfurtherdividedinto:a10-bitpagenumber.a10-bitpageoffset.Thus,alogicaladdressisas:wherepiisanindexintotheouterpagetable,andp2isthedisplacementwithinthepageoftheouterpagetable.,Address-TranslationScheme,Address-translationschemeforatwo-level32-bitpagingarchitecture,MultilevelPagingandPerformance,Sinceeachlevelisstoredasaseparatetableinmemory,coveringalogicaladdresstoaphysicalonemaytake4memoryaccesses.Eventhoughtimeneededforonememoryaccessisquintupled,cachingpermitsperformancetoremainreasonable.Cachehitrate命中率of98percentyields:effectiveaccesstime=0.98x120+0.02x520=128nanoseconds.whichisonlya28percentslowdowninmemoryaccesstime.,InvertedPageTable,Oneentryforeachrealpageofmemory.Entryconsistsofthevirtualaddressofthepagestoredinthatrealmemorylocation,withinformationabouttheprocessthatownsthatpage.Decreasesmemoryneededtostoreeachpagetable,butincreasestimeneededtosearchthetablewhenapagereferenceoccurs.Usehashtable哈希表tolimitthesearchtooneoratmostafewpage-tableentries.,InvertedPageTableArchitecture,SharedPages,SharedcodeOnecopyofread-only(reentrant可重入)codesharedamongprocesses(i.e.,texteditors,compilers,windowsystems).Sharedcodemustappearinsamelocationinthelogicaladdressspaceofallprocesses.PrivatecodeanddataEachprocesskeepsaseparatecopyofthecodeanddata.Thepagesfortheprivatecodeanddatacanappearanywhereinthelogicaladdressspace.,SharedPagesExample,Segmentation,Memory-managementschemethatsupportsuserviewofmemory.Aprogramisacollectionofsegments.Asegmentisalogicalunitsuchas:mainprogram,procedure,function,localvariables,globalvariables,commonblock,stack,symboltable,arrays,LogicalViewofSegmentation,SegmentationArchitecture,Logicaladdressconsistsofatwotuple2元组:,Segmenttable段表mapstwo-dimensionalphysicaladdresses;eachtableentryhas:base基址containsthestartingphysicaladdresswherethesegmentsresideinmemory.limit限长specifiesthelengthofthesegment.Segment-tablebaseregister(STBR)pointstothesegmenttableslocationinmemory.Segment-tablelengthregister(STLR)indicatesnumberofsegmentsusedbyaprogram;segmentnumbersislegalifsSTLR.,Segmentationhardware,SegmentationArchitec
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 销售合同管理工具合同条款审查及执行追踪版
- (正式版)DB15∕T 3253.1-2023 《食品生产加工小作坊生产规范 第1部分:管理要求》
- 道条考试题及答案
- 南通中医院护理面试题库及答案
- 历年护理副主任考试题库及答案
- 内部审批与签字标准操作模板
- 市场调查分析与营销策略工具集
- 企业日常运营管理模板系统
- 文言文诵读技巧指导
- 医疗安全培训通讯课件
- DB34T 4961-2024农村饮用水安全卫生评价
- 数学与体育学科的跨学科教学尝试
- 新生职业生涯规划教育
- DB13-T 6056-2025 涉路工程技术评价规范
- 《继电器原理及其应用》课件
- 饮料质量安全管理制度
- 风险管控制度
- 一年级道法集体教研记录
- 两癌筛查工作总结
- 溶液及其应用教学设计-2024-2025学年九年级化学人教版(2024)下册
- 网上不良信息的侵害及预防
评论
0/150
提交评论