Recall: Address Space Map Somet imes St ack Biggest Reserved f or (Space f or local var iables et c. Vir t ual OS 13: Memory Management For each nest ed pr ocedur e call) Address St ack Point er Last Modif ied: Heap (Space f or memor y dynamically 6/ 21/ 2004 9:51:29 AM allocat ed e.g. wit h malloc) St at ically declar ed var iables (Global var iables) PC Code (Text Segment ) Ox0000 Somet imes Reserved f or Error Cat ching -1 -2 P rocesses Address Space Let ’s be reasonable � Logically all of t his address space should � Does each process really need all of t his be resident in physical memory when t he space in memory at all t imes? pr ocess is r unning � Fir st has it even used it all? lot s of r oom in t he middle bet ween t he heap gr owing up and t he � How many machines do you use t hat have st ack gr owing down 2 32 = 4 GB of DRAM? Let alone 4 GB f or � Second even it has act ively used a chunk of t he *each* process!! addr ess space is it using it act ively r ight now • May be lot s of code t hat is rarely used (init ializat ion code used only at beginning, error handling code, et c.) • Allocat e space on heap t hen deallocat e • St ack grows big once but t hen normally small -3 -4 Freeing up Syst em Memory Send it t o disk � What do we do wit h por t ions of addr ess space � Why couldn’t we send it t o disk t o get it never used? out of our way? � Don’t allocat e t hem unt il t ouched! � I n t his case, t he disk is not r eally being used f or non-volat ile st or age but simply as � What do we do wit h r ar ely used por t ions of t he t empor ar y st aging ar ea addr ess space? � What would it t ake t o r est or e r unning � This isn’t so easy pr ocesses af t er a cr ash? (Maybe r est or e t o a � J ust because a variable rarely used doesn’t mean t hat we consist ent checkpoint in t he past ?) Would you don’t need t o st ore it s value in memory want t hat f unct ionalit y? � St ill it ’s a shame t o t ake up precious syst em memory wit h t hings we are rarely using! (The FS could sure use t hat � We’d have t o remember where we wrot e it space t o do caching remember?) so t hat if we need it again we can r ead it � What could we do wit h it ? back in -5 -6 1
Logist ics Virt ual Memory � How will we keep t r ack of which r egions ar e paged � Vir t ual Memor y = basic OS memor y management out and where we put t hem? abst r act ion/ t echnique � What will happen when a pr ocess t r ies t o access a � Pr ocesses use vir t ual addr esses r egion t hat has been paged t o disk? � Every t ime a process f et ches an inst ruct ion or loads a value int o a regist er it ref ers t o virt ual memory address � How will we shar e DRAM and disk wit h t he FS? � OS (wit h help f r om har dwar e) t r anslat es vir t ual � Will we have a minimum size region t hat can be addr esses t o physical addr esses sent t o disk? � Translat ion must be f ast ! � Like in FS, a f ixed size block or page is usef ul f or � OS manages sending some por t ions of vir t ual reducing f ragment at ion and f or ef f icient disk access addr ess space t o disk when needed � Somet ime t ranslat ion will involve st alling t o f et ch page f rom disk -7 -8 Virt ual Memory: I solat ion Virt ual Memory provides… Among P rocesses � Prot ect ion/ isolat ion among processes � Pr ot ect ion (Dat a I solat ion) � P rocesses use virt ual memory addresses � I llusion of more available syst em memory � These must be convert ed t o physical memory addresses in order t o access t he physical memory in t he syst em � Gives prot ect ion because processes unable even t o address (t alk about ) anot her processes address space � Per f or mance I solat ion � OS also t ries t o share limit ed memory resources f airly among processes � Can one process use so much of t he memory t hat ot her processes f orced t o page heavily? � Can one process use so much of t he backing st ore t hat ot her processes get out of memory errors? -9 -10 Virt ual Memory: I llusion of Full HW Support f or Virt ual Address Space Memory � We’ve seen t hat it makes sense f or pr ocesses not � Fast t ranslat ion => hardware support t o have t heir ent ir e addr ess space r esident in � Or OS would have t o be involved on ever y memor y but r at her t o move it in and out as needed inst r uct ion execut ion � P rogrammers used t o manage t his t hemselves � OS init ializes hardware properly on � One ser vice of vir t ual memor y is t o pr ovide an cont ext swit ch and t hen hardware supplies convenient abst r act ion f or pr ogr ammer s (“Your t ranslat ion and prot ect ion while whole wor king set is available and if necessar y I will br ing it t o and f r om disk f or you”) � Br eaks in t his illusion? � When you are “paging” heavily you know it ! � Out of memory errors - what do t hey mean? -11 -12 2
Translat ion/ P rot ect ion Wit h Technique 1: Fixed P art it ions Fixed Sized P art it ions � OS could divide physical memory int o f ixed � Hardware support sized regions t hat are available t o hold � Base r egist er port ions of t he address spaces of � Physical addr ess = Vir t ual Addr ess + base processes Regist er � I f Physical addr ess > par t it ion size t hen � Each process get s a part it ion and so t he har dwar e can gener at e a “f ault ” number of part it ions => max r unnable � During cont ext swit ch, OS will set base processes regist er t o t he beginning of t he new processes part it ion -13 -14 P aging t o Disk wit h Fixed Sized P roblems Wit h Fixed Sized P art it ions? P art it ions � Har dwar e could have anot her r egist er t hat says � Must access cont iguous por t ion of addr ess space t he base vir t ual addr ess in t he par t it ion � Using bot h code and st ack could mean a lot of paging!!! � Then t r anslat ion/ pr ot ect ion would go like t his: � What is t he best f ixed size? � I f virt ual address generat ed by t he process is bet ween � I f t ry t o keep everyt hing a process needs part it ion might t he base virt ual address and base virt ual address + need t o be very big (or we would need t o change how lengt h t hen access is ok and physical address is Virt ual compiler lays out code) Address – Base Virt ual Address Regist er + Base � P aging in such a big t hing could t ake a long t ime Regist er (especially if only using a small port ion) � Ot herwise OS must writ e out t he current cont ent s of � Also would “best ” size vary per process? t he part it ion and read in t he sect ion of t he address • Some pr ocesses might not need all of t he “f ixed” size while space being accessed now ot her s need mor e t han t he “f ixed” size � OS must record locat ion on disk where all non resident • I nt er nal f r agment at ion regions are writ t en (or record t hat no space has been • One f ixed sized part it ion = heavy paging f or all processes allocat ed on disk or in memory if a region has never been why? accessed) -15 -16 Technique 2: Variable Sized Variable P art it ions (con’t) P art it ions � Ver y similar t o f ixed sized par t it ions � May have ext er nal f r agment at ion � As processes are creat ed and complet e, f ree space in � Add a lengt h regist er (no longer f ixed size f or memory is likely t o be divided int o small pieces each process) t hat hardware uses in � Could relocat e processes t o coalesce t he f ree space? t ranslat ion/ prot ect ion calculat ions and t hat � How does OS know how big t o make each OS saves/ rest ores on cont ext swit ch pr ocesses par t it ion? Also how does OS decide what is a f air amount t o give each pr ocess? � No longer have problem wit h int ernal � St ill have pr oblem of only using only cont iguous f ragment at ion r egions -17 -18 3
Recommend
More recommend