wency@cuit.edu.cn20109.1OperatingSystemConceptsChapter9:MemoryManagementBackgroundSwappingContiguousAllocationPagingSegmentationSegmentationwithPaging*wency@cuit.edu.cn20109.2OperatingSystemConcepts9.1BackgroundProgrammustbebroughtintomemoryandplacedwithinaprocessforittoberun.Inputqueue–thecollectionofprocessesonthediskthatarewaitingtobebroughtintomemorytoruntheprogram.Thenormalprocedureistoselectoneoftheprocessesintheinputqueueandtoloadthatprocessintomemory.Mostsystemsallowauserprocesstoresideinanypartofthephysicalmemory.wency@cuit.edu.cn20109.3OperatingSystemConcepts9.1.1AddressBindingUsually,userprogramsgothroughseveralstepsbeforebeingrun.Addressesmayberepresentedindifferentwaysduringthesesteps.Addressesinsourceprogramaregenerallysymbolic(suchascount,i,jetc.)Compilertypicallybindsthesesymbolicaddressestorelocatableaddresses(suchas“14bytesfromthebeginningofthismodule”)Linkageeditororloaderwillbindtheserelocatableaddressestoabsoluteaddressesinturn.Eachbindingisamappingfromoneaddressspacetoanother.wency@cuit.edu.cn20109.4OperatingSystemConcepts9.1.1AddressBinding(1)Bindingofinstructionsanddatatomemoryaddressescanhappenatthreedifferentstages.Compiletime--Ifknownstartinglocationinmemory,absolutecodecanbegenerated;butmustrecompilecodeifstartinglocationchanges.(e.g..COMfilesinMS-DOS)Loadtime--Mustgeneraterelocatablecodeifmemorylocationisnotknownatcompiletime.Thefinalbindingisdelayeduntilloadtime.Executiontime–Bindingisdelayeduntilruntime,iftheprocesscanbemovedduringitsexecutionfromonememorysegmenttoanother.Needspecialhardwaresupportforaddressmaps(e.g.,baseandlimitregisters).Usedbymostgeneral-purposeOSwency@cuit.edu.cn20109.5OperatingSystemConceptsMultistepProcessingofaUserProgramReturnwency@cuit.edu.cn20109.6OperatingSystemConcepts9.1.2LogicalvsPhysicalAddressSpaceTheconceptofalogicaladdressspacethatisboundtoaseparatephysicaladdressspaceiscentraltopropermemorymanagement.Logicaladdress–generatedbyCPU;alsoreferredtoasvirtualaddress.Thesetofalllogicaladdressesgeneratedbyaprogramisalogical-addressspace.Physicaladdress–addressseenbythememoryunit.Thesetofallphysicaladdressescorrespondingtotheselogicaladdressesisaphysical-addressspace.Compile-timeandload-timeaddress-bindingschemesgenerateidenticallogicalandphysicaladdresses;buttheydifferinexecution-timeaddress-bindingscheme.wency@cuit.edu.cn20109.7OperatingSystemConcepts9.1.2LogicalvsPhysicalAddressSpace(1)Memory-ManagementUnit(MMU)--Hardwaredevicethatmapsvirtualaddresstophysicaladdressinrun-time.InMMUscheme,valueinrelocationregisterisaddedtoeveryaddressgeneratedbyauserprocesswhenitissenttomemory.RangesfordifferenttypesofaddressesLogicaladdresses—range0tomaxPhysicaladdresses-–rangeR+0toR+maxforabasevalueRTheuserprogramdealswithlogicaladdressesandneverseestherealphysicaladdresses.---Useronlythinksthattheprocessrunsinlocation0tomax.wency@cuit.edu.cn20109.8OperatingSystemConcepts9.1.2LogicalvsPhysicalAddressSpace(2)Dynamicrelocationusingarelocationregisterwency@cuit.edu.cn20109.9OperatingSystemConcepts9.1.3DynamicLoadingDynamicloading–Routineisnotloadeduntilitiscalled,whicharekeptondiskinarelocatableloadformat.Usedtoobtainbettermemory-spaceutilization.Unusedroutineisneverloaded.Itisusefulwhenlargeamountsofcodeareneededtohandlecasesoccurringinfrequently.Nospecialsupportisrequiredfromtheoperatingsystemwhenimplementedthroughprogramdesign.Operatingsystemcanprovidelibraryroutinestoimplementdynamicloadingforprogrammer.wency@cuit.edu.cn20109.10OperatingSystemConcepts9.1.4DynamicLinkingLinkingispostponeduntilexecutiontime.Smallpieceofcode,stub,usedtolocatetheappropriatememory-residentlibraryroutine.Stubreplacesitselfwiththeaddressoftheroutine,andexecutestheroutine.Operatingsystemneededtocheckiftheroutineisinprocesses’(itselforanother)memoryaddress.Dynamiclinkingisparticularlyusefulforsharedlibrariesupdating(suchasbugfixes),whichcalleddynamicallylinkedlibraries(DLL).wency@cuit.edu.cn20109.11OperatingSystemConcepts9.1.5OverlaysOverlays–tokeepinmemoryonlythoseinstructionsanddatathatareneededatanygiventime.Whenotherinstructionsareneeded,theyareloadedintospaceoccupiedpreviouslybyinstructionsthatarenolongerneeded.Neededwhenprocessislargerthantheamountofmemoryallocatedtoit.Implementedbyuser,nospecialsupportneededfromoperatingsystem,programmingdesignofoverlaystructureiscomplex.Overlaysiscurrentlylimitedtomicrocomputerandothersystemsthathavelimitedamountsofphysicalmemoryandthatlackhardwaresupportformoreadvancedtechniques.wency@cuit.edu.cn20109.12OperatingSystemConceptsOverlaysforaTwo-PassAssemblerwency@cuit.edu.cn20109.13OperatingSystemConcepts9.2SwappingAprocesscanbeswappedtemporarilyoutofmemorytoabackingstore,andthenbroughtbackintomemoryforcontinuedexecution.Backingstore–afastdiskthatmustbelargeenoughtoaccommodatecopiesofallmemoryimagesforallusers;mustprovidedirectaccesstothesememoryimages.Rollout,rollin–avariantofswappingpolicyisusedforpriority-basedschedulingalgorithms;lower-priorityprocessisswappedout,sohigher-priorityp