Sunteți pe pagina 1din 21

54

CHAPTER 6

MEMORY MANAGEMENT The concept of CPU scheduling allows a set of p ocesses to sha e the CPU the e !" inc easing the utili#ation of the CPU$ This set of p ocesses needs to eside in %e%o "$ The %e%o " is thus sha ed and the esou ce e&ui es to !e %anaged$ 'a ious %e%o " %anage%ent algo ith%s e(ist) each ha*ing its own ad*antages and disad*antages$ The ha dwa e design of the s"ste% pla"s an i%po tant ole in the selection of an algo ith% fo a pa ticula s"ste%$ That %eans to sa" ha dwa e suppo t is essential to i%ple%ent the %e%o " %anage%ent algo ith%$ 6$+ ,OG-CA, 's PHY.-CA, A//RE.. .PACE An add ess gene ated !" the CPU is efe ed to as a logical add ess$ An add ess seen !" the %e%o " unit that is the add ess loaded into the %e%o " add ess egiste 0MAR1 of the %e%o " fo a fetch o a sto e is efe ed to as a ph"sical add ess$ The logical add ess is also so%eti%es efe ed to as a *i tual add ess$ The set of logical add esses gene ated !" the CPU fo a p og a% is called the logical add ess space$ The set of all ph"sical add esses co esponding to a set of logical add ess is called the ph"sical add ess space$ At un ti%e 2 e(ecution ti%e) the *i tual add esses a e %apped to ph"sical add esses !" the %e%o " %anage%ent unit 0MMU1$ A si%ple %apping sche%e is illust ated !elow 03igu e 6$+1$ Relocation egiste ,ogical add ess 456 CPU
9

+5888

Ph"sical add ess +5456 MMU

Me%o "

3igu e 6$+7 /"na%ic elocation

55

The elocation egiste contains a *alue to !e added to e*e " add ess gene ated !" the CPU fo a use p ocess at the ti%e it is sent to the %e%o " fo a fetch o a sto e$ 3o e(a%ple) if the !ase is at +5888 then an add ess 8 is d"na%icall" elocated to location +5888) an access to location 456 is %apped to +5456 0+5888 9 4561$ Thus e*e " add ess is elocated elati*e to the *alue in the elocation egiste $ The ha dwa e of the MMU %aps logical add esses to ph"sical add esses$ ,ogical add esses ange f o% 8 to a %a(i%u% 0MA:1 and the co esponding ph"sical add esses ange f o% 0R 9 81 to 0R 9 MA:1 fo a !ase *alue of R$ Use p og a%s gene ate onl" logical add esses that a e %apped to ph"sical add esses !efo e use$ 6$4 .;APP-NG A p ocess to !e e(ecuted needs to !e in %e%o " du ing e(ecution$ A p ocess can !e swapped out of %e%o " in ce tain situations to a !ac<ing sto e and then ! ought into %e%o " late fo e(ecution to continue$ One such situation could !e the e(pi " of a ti%e slice if the ound= o!in CPU scheduling algo ith% is used$ On e(pi " of a ti%e slice) the cu ent p ocess is swapped out of %e%o " and anothe p ocess is swapped into the %e%o " space >ust f eed !ecause of swapping out of a p ocess 03igu e 6$41$ E*e " ti%e a ti%e slice e(pi es) a p ocess is swapped out and anothe is swapped in$ The %e%o " %anage that does the swapping is fast enough to alwa"s p o*ide a p ocess in %e%o " fo the CPU to e(ecute$ The du ation of a ti%e slice is ca efull" chosen so that it is sufficientl" la ge when co%pa ed to the ti%e fo swapping$
Ope ating s"ste%

.wap out P+ P4
Use a ea

.wap in ?ac<ing sto e 3igu e 6$47 .wapping of p ocesses

Me%o "

56

P ocesses a e swapped !etween the %ain %e%o " and the !ac<ing sto e when p io it" !ased CPU scheduling is used$ The a i*al of a high p io it" p ocess will can a lowe p io it" p ocess that is e(ecuting to !e swapped out to %a<e wa" fo a swap in$ The swapping in this case is so%eti%es efe ed to as oll out 2 oll in$ A p ocess that is swapped out of %e%o " can !e swapped in eithe into the sa%e %e%o " location o into a diffe ent %e%o " location$ -f !inding is done at load ti%e then swap in has to !e at the sa%e location as !efo e$ ?ut if !inding is done at e(ecution ti%e then swap in can !e into a diffe ent %e%o " space since the %apping to ph"sical add esses a e co%pleted du ing e(ecution ti%e$ A !ac<ing sto e is e&ui ed fo swapping$ -t is usuall" a fast dis<$ The p ocesses in the ead" &ueue ha*e thei i%ages eithe in the !ac<ing sto e o in the %ain %e%o "$ ;hen the CPU schedule pic<s a p ocess fo e(ecution) the dispatche chec<s to see if the pic<ed p ocess is in %e%o "$ -f "es then it is e(ecuted$ -3 not the p ocess has to !e loaded into %ain %e%o "$ -f the e is enough space in %e%o " the p ocess is loaded and e(ecution sta ts$ -f not) the dispatche swaps out a p ocess f o% %e%o " and swaps in the desi ed p ocess$ A p ocess to !e swapped out %ust !e idle$ P o!le%s a ise !ecause of pending -2O$ Conside the following scena io7 P ocess P + is waiting fo an -2O$ -2O is dela"ed !ecause the de*ice is !us"$ -f P+ is swapped out and its place P 4 is swapped in) then the esult of the -2O uses the %e%o " that now !elongs to P4$ The e can !e two solutions to the a!o*e p o!le%7 +$ 4$ Ne*e swap out a p ocess that is waiting fo an -2O -2O ope ations to ta<e place onl" into ope ating s"ste% !uffe s and not into use a ea !uffe s$ These !uffe s can then !e t ansfe ed into use a ea when the co esponding p ocess is swapped in$ 6$@ CONT-GUOU. A,,OCAT-ON The %ain %e%o " is usuall" di*ided into two pa titions) one of which has the esident ope ating s"ste% loaded into it$ The othe pa tition is used fo loading use p og a%s$ The ope ating s"ste% is usuall" p esent in the lowe %e%o " !ecause of the p esence of the inte upt *ecto in the lowe %e%o " 03igu e 6$@1$

57

Ope ating s"ste%

6+4A 6$@$+

Use a ea 3igu e 6$@7 Me%o " pa tition

.-NG,E PART-T-ON A,,OCAT-ON The ope ating s"ste% esides in the lowe %e%o "$ Use p ocesses e(ecute in the highe

%e%o "$ The e is alwa"s a possi!ilit" that use p ocesses %a" t " to access the lowe %e%o " eithe accidentall" o intentionall" the e !" causing loss of ope ating s"ste% code and data$ This p otection is usuall" p o*ided !" the use of a li%it egiste and elocation egiste $ The elocation egiste contains the s%allest ph"sical add ess that can !e accessed$ The li%it egiste contains the ange of logical add esses$ Each logical add ess %ust !e less than the content of the li%it egiste $ The MMU adds to the logical add ess the *alue in the elocation egiste to gene ate the co esponding add ess 03igu e 6$51$ .ince an add ess gene ated !" the CPU is chec<ed against these two egiste s) !oth the ope ating s"ste% and othe use p og a%s and data a e p otected and a e not accessi!le !" the unning p ocess$
,i%it egiste Relocation egiste

Yes CPU logical add ess Add essing e o 3igu e 6$57 Ha dwa e fo elocation and li%it egiste < No + Ph"sical add ess Me%o "

58

6$@$4

MU,T-P,E PART-T-ON A,,OCAT-ON Multip og a%%ing e&ui es that the e a e %an" p ocesses esiding in %e%o " so that the

CPU can switch !etween p ocesses$ -f this has to !e so then use a ea of %e%o " has to !e di*ided into pa titions$ The si%plest wa" is to di*ide the use a ea into fi(ed nu%!e of pa titions) each one to hold one use p ocess$ Thus the deg ee of %ultip og a%%ing is e&ual to the nu%!e of pa titions$ A p ocess f o% the ead" &ueue is loaded into one of the pa titions fo e(ecution$ On te %ination the pa tition is f ee fo anothe p ocess to !e loaded$ The disad*antage with this sche%e whe e pa titions a e of fi(ed si#es is the selection of pa tition si#es$ -f the si#e is too s%all then la ge p og a%s cannot !e un$ Also if the si#e of the pa tition is !ig then %ain %e%o " space in each pa tition goes a waste$ A *a iation of the a!o*e sche%e whe e the pa tition si#es a e not fi(ed !ut *a ia!le is gene all" used$ A ta!le <eeps t ac< of that pa t of the %e%o " that is used and the pa t that is f ee$ -nitiall" the enti e %e%o " of the use a ea is a*aila!le fo use p ocesses$ This can !e *isuali#ed as one !ig hole fo use$ ;hen a p ocess is loaded a hole !ig enough to hold this p ocess is sea ched$ -f one is found then %e%o " enough fo this p ocess is allocated and the est is a*aila!le f ee as illust ated !elow 03igu e 6$61$ 8 588A Bo! &ueue P ocess Me%o " Ti%e 4+68A Use a ea 4668A P+ P4 P@ P5 P6 688A +888A @88A C88A 688A +8 6 48 D +6 Ope ating s"ste%

3igu e 6$67 .cheduling e(a%ple Total %e%o " a*aila!le7 Resident ope ating s"ste%7 4668A 588A

59

Me%o " a*aila!le fo use 7 Bo! &ueue7 CPU scheduling7

4668 E 588 F 4+68A 3C3. RR 0+ ti%e unit1

Gi*en the %e%o " %ap in the illust ation a!o*e) P +) P4) P@ can !e allocated %e%o " i%%ediatel"$ A hole of si#e 04+68 E 0688 9 +888 9 @8811 F 468A is left o*e which cannot acco%%odate P5 03igu e 6$6a1$ Afte a while P 4 te %inates c eating the %ap of 3igu e 6$6!$ P 5 is scheduled in the hole >ust c eated esulting in 3igu e 6$6c$ Ne(t P + te %inates esulting in 3igu e 6$6d and P6 is scheduled as in 3igu e 6$6e$
8 O. 588A 8O. 588A 8O. 588A 8 O. 588A 8 588A G88A +888A +C88A 4888A 4@88A 4668A

O. P6 P5 P@

P+
+888A +888A

P+
+888A +C88A 4888A 4@88A 4668A

P+ P5 P@
+888A +C88A 4888A 4@88A 4668A

P5 P@

P4
4888A 4@88A 4668A

P@

4888A 4@88A 4668A

P@

0a1

0!1

0c1

0d1

0e1

3igu e 6$67 Me%o " allocation and >o! scheduling The ope ating s"ste% finds a hole >ust la ge enough to hold a p ocess and uses that pa ticula hole to load the p ocess into %e%o "$ ;hen the p ocess te %inates it eleases the used %e%o " to c eate a hole e&ual to its %e%o " e&ui e%ent$ P ocesses a e allocated %e%o " until the f ee %e%o " o hole a*aila!le is not !ig enough to load anothe ead" p ocess$ -n such a case the ope ating s"ste% waits fo so%e p ocess to te %inate and f ee %e%o "$ To !egin with the e is one la ge !ig hole e&ual to the si#e of the use a ea$ As p ocesses a e allocated into this %e%o ") e(ecute and te %inate this hole gets di*ided$ At an" gi*en instant the e afte the e a e a set of holes scatte ed all o*e the %e%o "$ New holes c eated that a e ad>acent to e(isting holes %e ge to fo % !ig holes$

60

The p o!le% now is to satisf" a %e%o " e&uest of si#e n f o% a list of f ee holes of *a ious si#es$ Man" solutions e(ist to dete %ine that hole which is the !est to allocate$ Most co%%on st ategies a e7 +$ 3i st=fit7 Allocate the fi st hole that is !ig enough to hold the p ocess$ .ea ch can eithe sta t at the !eginning of the set of holes o at the point whe e the last sea ch te %inated$ 4$ ?est=fit7 Allocate the s%allest hole that is !ig enough to hold the p ocess$ He e the enti e list has to !e sea ched o an o de ed list of holes !" si#e is to !e %aintained$ @$ ;o st=fit7 Allocate the la gest hole a*aila!le$ He e also the enti e list has to !e sea ched fo the !iggest hole o an o de ed list of holes !" si#e is to !e %aintained$ The si#e of a p ocess is *e " a el" an e(act si#e of a hole allocated$ The !est=fit allocation alwa"s p oduces an opti%al allocation whe e the hole left o*e afte allocation is the s%allest$ The fi st=fit is the fastest %ethod of allocation when co%pa ed to othe s$ The wo st=fit allocation is the wo st a%ongst the th ee and is seldo% used$ 6$@$@ 3RAGMENTAT-ON To !egin with the e is one la ge hole fo allocation to p ocesses$ As p ocesses a e loaded into %e%o " and te %inate on co%pletion) this la ge hole is di*ided into a set of s%alle holes that a e scatte ed in !etween the p ocesses$ The e %a" !e a situation whe e the total si#e of these scatte ed holes is la ge enough to hold anothe p ocess fo e(ecution !ut the p ocess cannot !e loaded) as the hole is not contiguous$ This is <nown as e(te nal f ag%entation$ 3o e(a%ple) in 3igu e 6$6c) a f ag%ented hole e&ual to 668A 0@88 9 4681 is a*aila!le$ P 6 cannot !e loaded !ecause 668A is not contiguous$ The e a e situations whe e onl" a few !"tes sa" + o 4 would !e f ee if a p ocess we e allocated a hole$ Then the cost of <eeping t ac< of this hole will !e high$ -n such cases this e(t a !it of hole is also allocated to the e&uesting p ocess$ -f so then a s%all po tion of %e%o " allocated to a p ocess is not useful$ This is inte nal f ag%entation$

61

One solution to e(te nal f ag%entation is co%paction$ Co%paction is to elocate p ocesses in %e%o " so those f ag%ented holes c eate one contiguous hole in %e%o " 03igu e 6$C1$
8 588A G88A +888A 8 588A G88A

O. P6

O. P6 P5

P5
+C88A 4888A 4@88A 4668A

+688A +G88A

P@ 668A

P@
4668A

3igu e 6$C7 Co%paction Co%paction %a" not alwa"s !e possi!le since it in*ol*es elocation$ -f elocation is static at load ti%e then elocation is not possi!le and so also co%paction$ Co%paction is possi!le onl" if elocation is done at unti%e$ E*en though co%paction is possi!le the cost in*ol*ed in elocation is to !e conside ed$ .o%eti%es c eating a hole at one end of the use %e%o " %a" !e !ette whe e as in so%e othe cases a contiguous hole %a" !e c eated in the %iddle of the %e%o " at lesse cost$ The position whe e the hole is to !e c eated du ing co%paction depends on the cost of elocating the p ocesses in*ol*ed$ An opti%al st ateg" if often difficult$ P ocesses %a" also !e olled out and olled in to affect co%paction !" %a<ing use of a !ac< up sto e$ ?ut this would !e at the cost of CPU ti%e$ 6$5 PAG-NG Contiguous allocation sche%e e&ui es that a p ocess can !e loaded into %e%o " fo e(ecution if and onl" if contiguous %e%o " la ge enough to hold the p ocess is a*aila!le$ ?ecause of this const aint) e(te nal f ag%entation is a co%%on p o!le%$ Co%paction was one solution to tide o*e e(te nal f ag%entation$ One othe solution to this p o!le% could !e to pe %it non= contiguous logical add ess space so that a p ocess can !e allocated ph"sical %e%o " whe e*e it is p esent$ This solution is i%ple%ented th ough the use of a paging sche%e$

62

6$5$+

CONCEPT O3 PAG-NG Ph"sical %e%o " is di*ided into fi(ed si#ed !loc<s called f a%es$ .o also logical %e%o " is

di*ided into !loc<s of the sa%e si#e called pages$ Allocation of %ain %e%o " to p ocesses fo e(ecution is then >ust %apping pages to f a%es$ The ha dwa e suppo t fo paging is illust ated !elow 03igu e 6$D1$ ,ogical add ess CPU p d p f d Ph"sical add ess Ph"sical %e %o "

f Page ta!le 3igu e 6$D7 Paging ha dwa e A logical add ess gene ated !" the CPU consists of two pa ts7 Page nu%!e 0p1 and a page offset 0d1$ The page nu%!e is used as an inde( into a page ta!le$ The page ta!le contains the !ase add ess of each f a%e in ph"sical %e%o "$ The !ase add ess is co%!ined with the page offset to gene ate the ph"sical add ess e&ui ed to access the %e%o " unit$ The si#e of a page is usuall" a powe of 4$ This %a<es t anslation of a logical add ess into page nu%!e and offset eas" as illust ated !elow7 ,ogical add ess space7 4% Page si#e7 ,ogical add ess7
p d

4n

0%=n1

;he e p F inde( into the page ta!le d F displace%ent within a page

63

-llust ation7 8 8 + 4 @
a !c d e f g h i >> < l % n o p

+ 8 + 4 @ 6 6 + 4 5 Page ta!le 6 @ 4

i > < l % n o p

,ogical %e%o " 6 C

a ! c d e f g h

Ph"sical %e%o " Page si#e7 Ph"sical %e%o "7 5 !"tes @4 !"tes F D pages

,ogical add ess 8 8 9 8 06 ( 51 9 8 ph"sical add ess 48 @ 8 9 @ 06 ( 51 9 @ ph"sical add ess 4@ 5 + 9 8 06 ( 51 9 8 ph"sical add ess 45 +@ @ 9 + 04 ( 51 9 + ph"sical add ess G Thus the page ta!le %aps e*e " logical add ess to so%e ph"sical add ess$ Paging does not suffe f o% e(te nal f ag%entation since an" page can !e loaded into an" f a%e$ ?ut inte nal f ag%entation %a" !e p e*alent$ This is !ecause the total %e%o " e&ui ed !" a p ocess is not alwa"s a %ultiple of the page si#e$ .o the last page of a p ocess %a" not !e full$ This leads to inte nal f ag%entation and a po tion of the f a%e allocated to this page will !e unused$ On an a*e age one half of a page pe p ocess is wasted due to inte nal f ag%entation$ .%alle the si#e of

64

a page) lesse will !e the loss due to inte nal f ag%entation$ ?ut the o*e head in*ol*ed is %o e in te %s of nu%!e of ent ies in the page ta!le$ Also <nown is a fact that dis< -2O is %o e efficient if page si#es a e !ig$ A t adeoff !etween the a!o*e facto s is used$ A p ocess e&ui es n pages of %e%o "$ Then at least n f a%es %ust !e f ee in ph"sical %e%o " to allocate n pages$ A list of f ee f a%es is %aintained$ ;hen allocation is %ade) pages a e allocated the f ee f a%es se&uentiall" 03igu e 6$G1$ Allocation details of ph"sical %e%o " a e %aintained in a f a%e ta!le$ The ta!le has one ent " fo each f a%e showing whethe it is f ee o allocated and if allocated to which page of which p ocess$ +5 +@ +D 48 +6 3 ee f a%e list +@ +5 +6 +6 3 ee f a%e list + 8 +6

8 + 4 @ New p ocess 48 ?efo e allocation +D

8 + 4 @

+5 +@ +D 48 @ Afte allocation 4

Page ta!le

3igu e 6$G7 3 a%e allocation 6$5$4 PAGE TA?,E -MP,EMENTAT-ON Ha dwa e i%ple%entation of a page ta!le is done in a nu%!e of wa"s$ -n the si%plest case the page ta!le is i%ple%ented as a set of dedicated high=speed egiste s$ ?ut this i%ple%entation is satisfacto " onl" if the page ta!le is s%all$ Mode n co%pute s allow the page ta!le si#e to !e *e " la ge$ -n such cases the page ta!le is <ept in %ain %e%o " and a pointe called the page=ta!le !ase egiste 0PT?R1 helps inde( the page ta!le$ The disad*antage with this

65

%ethod is that it e&ui es two %e%o " accesses fo one CPU add ess gene ated$ 3o e(a%ple) to access a CPU gene ated add ess) one %e%o " access is e&ui ed to inde( into the page ta!le$ This access using the *alue in PT?R fetches the f a%e nu%!e when co%!ined with the page= offset p oduces the actual add ess$ Using this actual add ess) the ne(t %e%o " access fetches the contents of the desi ed %e%o " location$ To o*e co%e this p o!le%) a ha dwa e cache called t anslation loo<=aside !uffe s 0T,?s1 a e used$ T,?s a e associati*e egiste s that allow fo a pa allel sea ch of a <e" ite%$ -nitiall" the T,?s contain onl" a few o no ent ies$ ;hen a logical add ess gene ated !" the CPU is to !e %apped to a ph"sical add ess) the page nu%!e is p esented as input to the T,?s$ -f the page nu%!e is found in the T,?s the co esponding f a%e nu%!e is a*aila!le so that a %e%o " access can !e %ade$ -f the page nu%!e is not found then a %e%o " efe ence to the page ta!le in %ain %e%o " is %ade to fetch the co esponding f a%e nu%!e $ This page nu%!e is then added to the T,?s so that a %apping fo the sa%e add ess ne(t ti%e will find an ent " in the ta!le$ Thus a hit will educe one %e%o " access and speed up add ess t anslation 03igu e 6$+81$

CPU ,ogical Add ess

d Ph"sical add ess Ph"sical %e%o "

Hit T,?

p Miss f Page ta!le 3igu e 6$+87 Paging ha dwa e with T,?

66

6$5$@

PROTECT-ON Each f a%e in ph"sical %e%o " is p otected$ P otection !its a e used fo this pu pose$ A

page can ha*e ead onl" 2 e(ecute onl" 2 ead=w ite access$ Ha dwa e p o*ides these p otection accesses to f a%es$ -llegal accesses a e t apped !" the ope ating s"ste%$ Also a p ocess needs to access f a%es co esponding to its pages onl"$ A *alid=in*alid !it is thus associated with each ent " in a page ta!le$ ;hen the !it is set) the page !elongs to the logical add ess space and thus has a co esponding f a%e$ -f the !it is not set) then the page is not in the p ocesses logical space and hence access to the f a%e is denied 03igu e 6$++1$ 3 a%e nu%!e 8 + 4 @ 5 6 8 + 4 @ 5 6 6 C 4 @ 5 C D G 8 6 * * * * * * i i 'alid=in*alid ?it 8 + 4 @ 5 6 6 C D G @ 5 6 8 + 4

Page ta!le 3igu e 6$++7 P otection !its 6$5$5 -N'ERTE/ PAGE TA?,E

.ince each p ocess e&ui es a %apping of its logical add ess space to a ph"sical add ess space) it has a page ta!le associated with it$ This page ta!le has one ent " fo each page the p ocess is using$ The co esponding ent " fo each page gi*es the %apping to ph"sical add ess space$ The ent ies in the page ta!le a e sto ed !" page nu%!e and hence a sea ch is eas"$ Main disad*antages with this sche%e a e that each page ta!le %a" ha*e *e " %an" ent ies and the page ta!les the%sel*es consu%e a lot of ph"sical %e%o ") all this e(e cise to <eep t ac< of ph"sical %e%o "$

67

A solution to this is the use of an in*e ted ta!le$ This ta!le has an ent " fo each f a%e of ph"sical %e%o "$ Each ent " has info %ation a!out the p ocess using the f a%e that is the p ocess=id along with the *i tual add ess$ Thus the enti e s"ste% has onl" one page ta!le 03igu e 6$+41$ ,ogical add ess CPU pid p d Ph"sical add ess i d

Ph"sical %e%o "

Page ta!le

3igu e 6$+47 -n*e ted page ta!le Each *i tual add ess is a t iple H p ocess=id) page nu%!e ) offset I$ Each ent " in the in*e ted page ta!le is a tuple consisting of H p ocess=id) page nu%!e I$ ;hen CPU gene ates a logical add ess a sea ch is %ade in the in*e ted page ta!le$ -f a %atch is found at the i th position) then a ph"sical add ess H -) offset I is gene ated$ -f no %atch occu s then it is an illegal %e%o " access$ Me%o " e&ui ed in this sche%e is less$ ?ut ti%e to sea ch the in*e ted page ta!le is %o e !ecause the in*e ted page ta!le is so ted !" ph"sical add ess and the sea ch is !eing %ade !" logical add ess$ Hash ta!les o associati*e egiste s a e used to o*e co%e this p o!le%$ 6$5$6 .HARE/ PAGE. P og a%s such as edito s and co%pile s can !e sha ed a%ong a nu%!e of p ocesses$ That is to sa" %an" p ocesses can use onl" one cop" of the a!o*e code$ This is !ecause these

68

codes a e e(a%ples of eent ant code o pu e code o non=self=%odif"ing code$ Code in such cases ne*e changes du ing e(ecution$ Thus %an" p ocesses can e(ecute the sa%e code at the sa%e ti%e$ Paging p o*ides the possi!ilit" of sha ing co%%on code$ Onl" const aint is that the sha ed code has to !e eent ant 03igu e 6$+@1$ P+ Ed + Ed 4 Ed @ /ata + Ed + Ed 4 Ed @ /ata 4 @ 5 6 + P4 @ 5 6 C 3igu e 6$+@7 .ha ed pages Each p ocess has its own cop" of egiste s and data sto age to hold data du ing e(ecution$ Onl" one cop" of the edito is <ept in ph"sical %e%o "$ The indi*idual page ta!les of the diffe ent p ocesses show the sa%e %apping fo pages co esponding to edito and diffe ent %apping fo the data pages$ The concept of sha ed pages p o*ides a significant sa*ing in total space e&ui ed$ ."ste% using in*e ted page ta!le cannot i%ple%ent this sha ed concept !ecause %o e than one *i tual add ess %aps on to the sa%e ph"sical add ess which is not possi!le to i%ple%ent in an in*e ted page ta!le$ 6$6 .EGMENTAT-ON Me%o " %anage%ent using paging p o*ides two enti el" diffe ent *iews of %e%o " E Use 2 logical 2 *i tual *iew and the actual 2 ph"sical *iew$ ?oth a e not the sa%e$ -n fact the use Js *iew is %apped on to the ph"sical *iew$ Ed + Ed 4 Ed @ /ata @ @ 5 6 4 P@ 8 /ata + /ata @ Ed + Ed 4 6 Ed @ /ata 4 D G +8

69

How do use s *isuali#e %e%o "K Use s p efe to *iew %e%o " as a collection of *a ia!le si#ed seg%ents 03igu e 6$+51$

.u! outine

.tac<

.& t

Main P og a%

,ogical add ess space

3igu e 6$+57 Use Js *iew of %e%o " The use usuall" w ites a %odula st uctu ed p og a% consisting of a %ain seg%ent togethe with a nu%!e of functions 2 p ocedu es$ Each one of the a!o*e is *isuali#ed as a seg%ent with its associated na%e$ Ent ies in a seg%ent a e at an offset f o% the sta t of the seg%ent$ 6$6$+ CONCEPT O3 .EGMENTAT-ON .eg%entation is a %e%o " %anage%ent sche%e that suppo ts use s *iew of %ain %e%o " desc i!ed a!o*e$ The logical add ess is then a collection of seg%ents) each ha*ing a na%e and a length$ .ince it is eas" to wo < with nu%!e s) seg%ents a e nu%!e ed$ Thus a logical add ess is H seg%ent nu%!e ) offset I$ Use p og a%s when co%piled eflect seg%ents p esent in the input$ ,oade while loading seg%ents into %e%o " assign the% seg%ent nu%!e s$

70

6$6$4

.EGMENTAT-ON HAR/;ARE E*en though seg%ents in use *iew a e sa%e as seg%ents in ph"sical *iew) the two=

di%ensional *isuali#ation in use *iew has to !e %apped on to a one=di%ensional se&uence of ph"sical %e%o " locations$ This %apping is p esent in a seg%ent ta!le$ An ent " in a seg%ent ta!le consists of a !ase and a li%it$ The !ase co esponds to the sta ting ph"sical add ess in %e%o " whe e as the li%it is the length of the seg%ent 03igu e 6$+61$ .eg%ent ta!le ,i%it ?ase

CPU

d Ph"sical %e%o "

< No Add essing e o

Yes

3igu e 6$+67 .eg%entation ha dwa e The logical add ess gene ated !" the CPU consists of a seg%ent nu%!e and an offset within the seg%ent$ The seg%ent nu%!e is used as an inde( into a seg%ent ta!le$ The offset in the logical add ess should lie !etween 8 and a li%it specified in the co esponding ent " in the seg%ent ta!le$ -f not the p og a% is t "ing to access a %e%o " location which does no !elong to the seg%ent and hence is t apped as an add essing e o $ -f the offset is co ect the seg%ent ta!le gi*es a !ase *alue to !e added to the offset to gene ate the ph"sical add ess$ An illust ation is gi*en !elow 0figu e 6$+61$

71

,ogical add ess space .tac< .u! outine 4 8 .& t + 5@88 5C88 6@88 +888 588 588 ++88 +588 6@88 5C88 @488 .eg%ent + 6C88 Ph"sical %e%o " 3igu e 6$+67 -llust ation of seg%entation A efe ence to logical location 6@ in seg%ent 4 ph"sical location 5@88 9 6@ F 5@6@ D64 in seg%ent @ ph"sical location @488 9 D64 F 5864 +444 in seg%ent 8 add essing e o !ecause +444 I +888 6$6$@ .EGMENTAT-ON TA?,E -MP,EMENTAT-ON A seg%ent ta!le <ept in egiste s can !e efe enced &uic<l"$ Pa allel e(ecution of addition to !ase and co%pa ison with li%it can sa*e conside a!le ti%e$ ?ut when seg%ent ta!les a e !ig containing ent ies fo %an" seg%ents then seg%ent ta!les will ha*e to !e %aintained in %e%o "$ The p ocedu e is si%ila as in paging and e&ui es two %e%o " accesses$ The solution to this is also the use of associati*e egiste s$ .eg%ent 4 Main P og a% @ +588 .eg%ent 8 4588 @488 .eg%ent @

,i%it .eg%ent ta!le

?ase

72

6$6$5

PROTECT-ON AN/ .HAR-NG P o*iding p otection to seg%ents is easie than in paging$ This is !ecause seg%ents

ep esent se%anticall" defined po tions of code and all po tions of code in a seg%ent a e li<el" to !e used in the sa%e wa"$ Hence so%e seg%ents contain inst uctions and so%e data$ Those that contain inst uctions can !e ead onl" o e(ecute onl" whe e as data seg%ents can ha*e w ite access$ .eg%ents can !e sha ed si%ila to sha ing of pages in a paging en*i on%ent$ .eg%ents can !e sha ed when ent ies in seg%ent ta!les of two diffe ent p ocesses point to the sa%e ph"sical locations 03igu e 6$+C1$ 5@864
Edito

8 8 +

,i%it 464D6 5546

?ase 5@864 6D@5D

Edito 6D@5D /ata + C4CC@

+ /ata + P+

,i%it
Edito

?ase 5@864 G888@ G888@ /ata 4

8 8 +

+ /ata 4

464D6 DD68

P4 3igu e 6$+C7 .ha ed seg%ents

GDD6@

.ha ing occu s at seg%ent le*el$ .e*e al seg%ents of a p og a% %a" !e sha ed$ ?ut each p ocess still needs sepa ate uni&ue seg%ents fo data$ .o%e p o!le%s e(ist while sha ing pa ts 2 seg%ents of p og a%s$ -f the sha ed seg%ent consists of a >u%p inst uction then a logical add ess is gene ated fo this t ansfe $ Now its co esponding %apping into the seg%ent ta!le c eates p o!le%s$ -n such cases di ect efe ence to cu ent seg%ent nu%!e s %ust !e a*oided$

73

6$6$6

3RAGMENTAT-ON .eg%ents of use p og a%s a e allocated %e%o " !" the !o! schedule $ This is si%ila to

paging whe e seg%ents could !e t eated as *a ia!le si#ed pages$ .o a fi st=fit o !est=fit allocation sche%e could !e used since this is a d"na%ic sto age allocation p o!le%$ ?ut as with *a ia!le si#ed pa tition sche%e) seg%entation too causes e(te nal f ag%entation$ ;hen an" f ee %e%o " seg%ent is too s%all to !e allocated to a seg%ent to !e loaded) then e(te nal f ag%entation is said to ha*e occu ed$ Me%o " co%paction is a solution to o*e co%e e(te nal f ag%entation$ The se*e it" of the p o!le% of e(te nal f ag%entation depends upon the a*e age si#e of a seg%ent$ Each p ocess !eing a seg%ent is nothing !ut the *a ia!le si#ed pa tition sche%e$ At the othe e(t e%e) e*e " !"te could !e a seg%ent in which case e(te nal f ag%entation is totall" a!sent !ut elocation th ough the seg%ent ta!le is a *e " !ig o*e head$ A co%p o%ise could !e fi(ed si#ed s%all seg%ents) which is the concept of paging$ Gene all" if seg%ents e*en though *a ia!le a e s%all) e(te nal f ag%entation is also less$ 6$6 .UMMARY -n this chapte we ha*e lea nt how a esou ce called %e%o " is %anaged !" the ope ating s"ste%$ The %e%o " in &uestion is the %ain %e%o " that holds p ocesses du ing e(ecution$ Me%o " could !e contiguousl" allocated !" using an" one of the !est=fit o fi st=fit st ategies$ ?ut one %a>o disad*antage with this %ethod was that of f ag%entation$ To o*e co%e this p o!le% we ha*e seen how %e%o " is di*ided into pages 2 f a%es and the p ocesses a e conside ed to !e a set of pages in logical %e%o "$ These pages a e %apped to f a%es in ph"sical %e%o " th ough a page ta!le$ ;e ha*e also seen use Js *iew of %e%o " in the fo % of seg%ents$ Bust li<e a page ta!le) a seg%ent ta!le %aps seg%ents to ph"sical %e%o "$ 6$C E:ERC-.E +$ 4$ /iffe entiate !etween inte nal and e(te nal f ag%entation$ E(plain how it is o*e co%e$ E(plain the paging concept with the help of a diag a%$

74

@$ 5$ 6$ 6$ C$ 6$D

E(plain fi st=fit) ?est=fit and wo st=fit allocation algo ith%s with an e(a%ple$ ;h" a e T,?s e&ui ed in pagingK E(plain$ ;ith a !loc< diag a% e(plain the ha dwa e e&ui ed fo seg%entation$ ;hat is an in*e ted page ta!leK ;hat a e its ad*antages o*e the con*entional page ta!leK /oes it ha*e an" disad*antagesK ; ite a note on sha ed pages$

ACT-'-TY .tud" the %e%o " %anage%ent sche%es i%ple%ented in the ope ating s"ste%s noted$

How is p otection p o*idedK /oes it allow sha ingK

S-ar putea să vă placă și