版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Module9:MemoryManagementBackground(背景)LogicalversusPhysicalAddressSpace(逻辑与物理地址空间)Swapping(交换)ContiguousAllocation(连续分配)Paging(分页) Segmentation(分段)SegmentationwithPaging(段页式).BackgroundProgrammustbebroughtintomemoryandplacedwithinaprocessforittobeexecuted.(程序必需放入一个进程,并且送入内存才能被执行)Inputqueue–collectionofprocessesonthediskthatarewaitingtobebroughtintomemoryforexecution.(输入队列—磁盘上等待进入内存并执行的进程的集合)Userprogramsgothroughseveralstepsbeforebeingexecuted.(用户程序在执行之前必需经历很多步骤).BindingofInstructionsandDatatoMemoryCompiletime(编译时期):Ifmemorylocationknownapriori,absolutecodecanbegenerated;mustrecompilecodeifstartinglocationchanges.(如果内存位置已知,可生成绝对代码;如果开始位置改变,需要重新编译代码)Loadtime(装入时期):Mustgeneraterelocatablecodeifmemorylocationisnotknownatcompiletime.(如果存储位置在编译时不知道,则必须生成可重定位代码)Executiontime(执行时期):Bindingdelayeduntilruntimeiftheprocesscanbemovedduringitsexecutionfromonememorysegmenttoanother.Needhardwaresupportforaddressmaps(e.g.,baseandlimitregisters).(如果进程在执行时可以在内存中移动,则地址绑定要延迟到运行时。需要硬件对地址映射的支持,例如基址和限长寄存器)Addressbindingofinstructionsanddatatomemoryaddressescan
happenatthreedifferentstages.(指令和数据结合到内存地址可以在三个不同的阶段发生。).DynamicLoadingRoutineisnotloadeduntilitiscalled.(例程在调用之前并不执行)Bettermemory-spaceutilization;unusedroutineisneverloaded.(更好的内存空间利用率;没有被使用的例程不被载入。)Usefulwhenlargeamountsofcodeareneededtohandleinfrequentlyoccurringcases.(当需要大量的代码来处理不经常发生的事情时是非常有用的。)Nospecialsupportfromtheoperatingsystemisrequiredimplementedthroughprogramdesign.(不需要操作系统的特别支持,通过程序设计实现).DynamicLinkingLinkingpostponeduntilexecutiontime.(链接被推迟到执行时期)Smallpieceofcode,stub,usedtolocatetheappropriatememory-residentlibraryroutine.(小的代码片-存根,用来定位合适的保留在内存中的库程序。)Stubreplacesitselfwiththeaddressoftheroutine,andexecutestheroutine.(存根用例程地址来替换自己,以及执行例程。)Operatingsystemneededtocheckifroutineisinprocesses’memoryaddress.(操作系统需要检查例程是否在进程的内存空间).OverlaysKeepinmemoryonlythoseinstructionsanddatathatareneededatanygiventime.(只是在内存中保留那些在特定时间所需要的指令和数据)Neededwhenprocessislargerthanamountofmemoryallocatedtoit.(当进程比所分配的内存大时,覆盖是必需的)Implementedbyuser,nospecialsupportneededfromoperatingsystem,programmingdesignofoverlaystructureiscomplex.(由用户执行,不需要操作系统的特别支持,覆盖结构的程序设计很复杂。).Logicalvs.PhysicalAddressSpaceTheconceptofalogicaladdressspacethatisboundtoaseparatephysical
addressspaceiscentraltopropermemorymanagement.(逻辑地址空间的概念同物理地址空间想关联,它是正确内存管理的中心。)Logicaladdress–generatedbytheCPU;alsoreferredtoasvirtualaddress.(逻辑地址—由CPU产生;也叫做虚拟空间。)Physicaladdress–addressseenbythememoryunit.(物理地址—内存设备所读入的地址)Logicalandphysicaladdressesarethesameincompile-timeandload-timeaddress-bindingschemes;logical(virtual)andphysicaladdressesdifferinexecution-timeaddress-bindingscheme.(逻辑和物理地址在编译时期和装入时期的地址绑定策略是相同的,而在执行时间的地址绑定策略是不同的。).Memory-ManagementUnit(MMU)Hardwaredevicethatmapsvirtualtophysicaladdress.(硬件把虚拟地址映射到物理地址)InMMUscheme,thevalueintherelocationregisterisaddedtoeveryaddressgeneratedbyauserprocessatthetimeitissenttomemory.(在MMU策略中,基址寄存器中的值在其送入内存的时候被加入到由一个用户进程所产生的每个地址中。)Theuserprogramdealswithlogicaladdresses;itneverseestherealphysicaladdresses.(用户程序所对应到的是逻辑地址,物理地址对它从来都不可见。).SwappingAprocesscanbeswappedtemporarilyoutofmemorytoabackingstore,andthenbroughtbackintomemoryforcontinuedexecution.(一个进程可以暂时被交换到内存外的一个备份区,随后可以被换回内存继续执行。)Backingstore–fastdisklargeenoughtoaccommodatecopiesofallmemoryimagesforallusers;mustprovidedirectaccesstothesememoryimages.(备份区—是一个固定的足够大的可以容纳所有用户内存映像的拷贝;对于可以让这些内存映像直接存取。).SwappingRollout,rollin–swappingvariantusedforpriority-basedschedulingalgorithms;lower-priorityprocessisswappedoutsohigher-priorityprocesscanbeloadedandexecuted.(滚入,滚出—交换由于基于优先级的算法而不同,低优先级的进程被换出,这样高优先级的进程可以被装入和执行。)Majorpartofswaptimeistransfertime;totaltransfertimeisdirectlyproportionaltotheamountofmemoryswapped.(交换时间的主要部分是转移时间,总的转移时间直接同交换的内存的数量成比例。)Modifiedversionsofswappingarefoundonmanysystems,i.e.,UNIXandMicrosoftWindows.(在许多系统如:UNIX,Windows中,可以找到一些被修正过的交换措施。).SchematicViewofSwapping.ContiguousAllocationMainmemoryusuallydividedintotwopartitions:(主存通常被分为两部分)Residentoperatingsystem,usuallyheldinlowmemorywithinterruptvector.(为操作系统保留的部分,通常用中断矢量保存在内存低端。)Userprocessesthenheldinhighmemory.(用户进程保存在内存高端。)Single-partitionallocation(单独分区分配)Relocation-registerschemeusedtoprotectuserprocessesfromeachother,andfromchangingoperating-systemcodeanddata.(基址寄存器策略由来保护用户进程(同其他进程和改变的操作系统代码和数据分开。)Relocationregistercontainsvalueofsmallestphysicaladdress;limitregistercontainsrangeoflogicaladdresses–eachlogicaladdressmustbelessthanthelimitregister.(基址寄存器包含最小物理地址的值;限长寄存器包含逻辑地址的范围,每个逻辑地址必需比限长寄存器的值小。).ContiguousAllocation(Cont.)Multiple-partitionallocation(多分区分配)Hole–blockofavailablememory;holesofvarioussizearescatteredthroughoutmemory.(分区—可用的内存块,不同大小的分区分布在整个内存中。)Whenaprocessarrives,itisallocatedmemoryfromaholelargeenoughtoaccommodateit.(当一个进程到来的时候,它将从一个足够容纳它分区中分配内存。)Operatingsystemmaintainsinformationabout(操作系统包含以下信息):a)allocatedpartitions(分配的分区)b)freepartitions(hole)(空的分区)OSprocess5process8process2OSprocess5process2OSprocess5process2OSprocess5process9process2process9process10.DynamicStorage-AllocationProblemFirst-fit(首先适应):Allocatethefirstholethatisbigenough.(分配最先找到的合适的分区。)Best-fit(最佳适应):Allocatethesmallestholethatisbigenough;mustsearchentirelist,unlessorderedbysize.Producesthesmallestleftoverhole.(搜索整个序列,找到适合条件的最小的分区进行分配。)Worst-fit(最差适应):Allocatethelargesthole;mustalsosearchentierlist.Producesthelargestleftoverhole.(搜索整个序列,寻找最大的分区进行分配。)Howtosatisfyarequestofsizenfromalistoffreeholes.(怎样从一个空的分区序列中满足一个申请需要。)First-fitandbest-fitbetterthanworst-fitintermsofspeedandstorageutilization.(在速度和存储的利用上,首先适应和最佳适应要比最差适应好。).FragmentationExternalfragmentation(外碎片)–totalmemoryspaceexiststosatisfyarequest,butitisnotcontiguous.(整个内存空间用来满足一个请求,但它不是连续的。)Internalfragmentation(内碎片)–allocatedmemorymaybeslightlylargerthanrequestedmemory;thissizedifferenceismemoryinternaltoapartition,butnotbeingused.(分配的内存可能比申请的内存大一点,这两者之间的差别是内部不被使用的簇)Reduceexternalfragmentationbycompaction(通过压缩来减少内碎片)Shufflememorycontentstoplaceallfreememorytogetherinonelargeblock.(把一些小的空闲内存结合成一个大的块。)Compactionispossibleonlyifrelocationisdynamic,andisdoneatexecutiontime.(只有重置是动态的时候,才有可能进行压缩,压缩在执行时期进行)I/Oproblem(I/O问题)LatchjobinmemorywhileitisinvolvedinI/O.(当I/O的时候,把工作锁定在内存中。)DoI/OonlyintoOSbuffers.(只对操作系统的缓冲区进行I/O。).PagingLogicaladdressspaceofaprocesscanbenoncontiguous;processisallocatedphysicalmemorywheneverthelatterisavailable.(进程的逻辑地址空间可能是不连续的,如果有可用的物理内存,它将分给进程。)Dividephysicalmemoryintofixed-sizedblockscalledframes(sizeispowerof2,between512bytesand8192bytes).(把物理内存分成大小固定的块。)Dividelogicalmemoryintoblocksofsamesizecalledpages.(把逻辑内存也分位固定大小的块,叫做页。)Keeptrackofallfreeframes.(保留一个页的记录。)Torunaprogramofsizenpages,needtofindnfreeframesandloadprogram.(运行一个有N页大小的程序,需要找到N个空的页框读入程序。)Setupapagetabletotranslatelogicaltophysicaladdresses.(建立一个页表,把逻辑地址转换为物理地址。)Internalfragmentation.(内碎片。).AddressTranslationSchemeAddressgeneratedbyCPUisdividedinto(CPU产生的地址被分为):Pagenumber
(p)(页号)–usedasanindexintoapage
tablewhichcontainsbaseaddressofeachpageinphysicalmemory.(它包含每个页在物理内存中的基址,用来作为页表的索引。)Pageoffset
(d)(偏移)–combinedwithbaseaddresstodefinethephysicalmemoryaddressthatissenttothememoryunit.(同基址相结合,用来确定送入内存设备的物理内存地址。).AddressTranslationArchitecture.PagingExample.ImplementationofPageTablePagetableiskeptinmainmemory.(主存中的页表)table
baseregister(PTBR)pointstothepagetable.(页表基址寄存器指向页表)tablelengthregister(PRLR)indicatessizeofthepagetable.(页表限长寄存器表明页表的长度)Inthisschemeeverydata/instructionaccessrequirestwomemoryaccesses.Oneforthepagetableandoneforthedata/instruction.(在这个机制中,每一次的数据/指令存取需要两次内存存取,一次是存取页表,一次是存取数据)Thetwomemoryaccessproblemcanbesolvedbytheuseofaspecialfast-lookuphardwarecachecalledassociativeregistersortranslationlook-asidebuffers
(TLBs).(通过一个联想寄存器,可以解决两次存取的问题).AssociativeRegisterAssociativeregisters–parallelsearch(联想寄存器—并行查找)
Addresstranslation(A´,A´´)(地址转换)IfA´isinassociativeregister,getframe#out.(如果A’在联想寄存器中,把页框#取出来。)Otherwisegetframe#frompagetableinmemory.(否则从内存中的页表中取出页框#。)Page#Frame#.EffectiveAccessTimeAssociativeLookup=timeunit(联想寄存器的查找需要时间)Assumememorycycletimeis1microsecond(假设内存一次存取要1微秒)Hitration–percentageoftimesthatapagenumberisfoundintheassociativeregisters;rationrelatedtonumberofassociativeregisters.(命中率—在联想寄存器中找到页号的比率,比率与联想寄存器的大小有关。)Hitratio=EffectiveAccessTime(EAT)(有效存取时间)
EAT=(1+)+(2+)(1–) =2+–
.MemoryProtectionMemoryprotectionimplementedbyassociatingprotectionbitwitheachframe.(内存的保护由与每个页框相连的保护位来执行。)Valid-invalidbitattachedtoeachentryinthepagetable(有效-无效位附在页表的每个表项中):“valid”indicatesthattheassociatedpageisintheprocess’logicaladdressspace,andisthusalegalpage.(“有效”表明相关的页在进程的逻辑地址空间,以及是一个合法的页。)“invalid”indicatesthatthepageisnotintheprocess’logicaladdressspace.(“无效”表明页不在进程的逻辑地址空间中。).Two-LevelTableScheme.Two-LevelPagingExampleAlogicaladdress(on32-bitmachinewith4Kpagesize)isdividedinto(一个逻辑地址被分为):apagenumberconsistingof20bits.(一个20位的页号。)apageoffsetconsistingof12bits.(一个12位的偏移。)Sincethepagetableispaged,thepagenumberisfurtherdividedinto(页表页被分为):a10-bitpagenumber.(一个10位的页号。)a10-bitpageoffset.(一个10位的偏移。)Thus,alogicaladdressisasfollows(因此,一个逻辑地址表示如下):
wherepiisanindexintotheouterpagetable,andp2isthedisplacementwithinthepageoftheouterpagetable.pagenumberpageoffsetpip2d101012.Address-TranslationSchemeAddress-translationschemeforatwo-level32-bitpagingarchitecture(一个两级32位分页结构的地址转换机制).MultilevelPagingandPerformanceSinceeachlevelisstoredasaseparatetableinmemory,coveringalogicaladdresstoaphysicalonemaytakefourmemoryaccesses.(由于每一级都分开的以表的形式存储在内存中,把一个逻辑地址转换为一个物理地址可能要进行4次内存存取。)Eventhoughtimeneededforonememoryaccessisquintupled,cachingpermitsperformancetoremainreasonable.(尽管每次内存存取的时间是很大的,高速缓存使执行的时间还是可以接受的。)Cachehitrateof98percentyields(缓存的命中率使98%)则:
effectiveaccesstime=0.98x120+0.02x520 =128nanoseconds.
whichisonlya28percentslowdowninmemoryaccesstime.(这只把内存存取时间降低了28%。).InvertedPageTableOneentryforeachrealpageofmemory.(一个内存中页的表项。)Entryconsistsofthevirtualaddressofthepagestoredinthatrealmemorylocation,withinformationabouttheprocessthatownsthatpage.(表项包含真正内存地址的页的虚拟地址,它包括拥有这个页的进程的信息。)Decreasesmemoryneededtostoreeachpagetable,butincreasestimeneededtosearchthetablewhenapagereferenceoccurs.(减少内存需要储存每个页表,但是当访问一个页时,寻找页表需要增加时间。)Usehashtabletolimitthesearchtoone—oratmostafew—tableentries.(使用哈希表来减少搜索。).InvertedPageTableArchitecture.SharedPagesSharedcode(共享代码)Onecopyofread-only(reentrant)codesharedamongprocesses(i.e.,texteditors,compilers,windowsystems).(一个只读(可再入)代码可由进程共享。)Sharedcodemustappearinsamelocationinthelogicaladdressspaceofallprocesses.(共享代码出现在所有进程的逻辑地址空间的相同位置。)Privatecodeanddata(私有代码和数据)Eachprocesskeepsaseparatecopyofthecodeanddata.(每个进程保留一个代码和数据的私有拷贝。)Thepagesfortheprivatecodeanddatacanappearanywhereinthelogicaladdressspace.(私有代码和数据的页可以出现在逻辑地址空间的任何地方。).SharedPagesExample.SegmentationMemory-managementschemethatsupportsuserviewofmemory.(内存管理机制支持用户观点的内存。)Aprogramisacollectionofsegments.Asegmentisalogicalunitsuchas(一个程序是一些段的集合,一个段是一个逻辑单位,如:):
mainprogram, procedure, function, localvariables,globalvariables, commonblock, stack, symboltable,arrays.LogicalViewofSegmentation13241423userspacephysicalmemoryspace.SegmentationArchitectureLogicaladdressconsistsofatwotuple(一个逻辑地址是两个向量的集合): <segment-number,offset>,Segmenttable–mapstwo-dimensionalphysicaladdresses;eachtableentryhas(段表-映射二维物理地址,每个表项包括):base–containsthestartingphysicaladdresswherethesegmentsresideinmemory.(基址-包括内存中段物理地址的起始地址。)limit–specifiesthelengthofthesegment.(限长-指定段的长度。)Segment-tablebaseregister(STBR)pointstothesegmenttable’slocationinmemory.(段表基址寄存器指向段表在内存中的地址。)Segment-tablelengthregister(STLR)indicatesnumberofsegmentsusedbyaprogram;(段表限长寄存器表明
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 四省名校2026届高考适应性测试试卷(化学试题文)试题含解析
- 环保科技进步持续承诺书8篇
- 2026年财务结算结果回复函6篇范本
- 出版发行领域承诺书范文3篇
- 客户需求调研问卷设计与数据分析
- 古建工程修缮加固与改造技术探讨
- 企业培训员工晋升年度考核手册
- 农业行业智能灌溉与农业机械化方案
- 员工遵规用工承诺函范文5篇
- 酒店业客户管理智能优化系统方案
- 普通肺炎病历报告
- DB51∕T 3118-2023 职业健康检查质量控制规范
- 基于课程思政的英语教学策略探析 论文
- 语料库语言学
- 《归园田居(其一)》优秀课件
- 【心灵读物】人生海海,劈浪前行-读麦家《人生海海》有感
- 中国肺动脉高压诊断与治疗指南(2021版)解读
- 拟定商品标题 (电商文案创作)
- 安全教育培训班组级试题
- GB/Z 40893.4-2021中医技术操作规范儿科第4部分:小儿推拿疗法
- GB/T 778.3-2018饮用冷水水表和热水水表第3部分:试验报告格式
评论
0/150
提交评论