1. Overview of Operating Systems a. Wat is an OS ! "t is a #ontro$ program tat provi%es an interfa#e &etween te #omputer ar%ware an% te user. Part of tis interfa#e in#$u%es too$s an% servi#es for te user. 'rom Si$&ers#at( (page 3)) *+n operating system is a program tat a#ts as an interme%iary &etween a user of #omputer an% #omputer ar%ware. ,e purpose of te OS is provi%e an environment in wi# te user #an e-e#ute programs. ,e primary goa$ of an OS is tus to ma.e te #omputer #onvenient to use. + se#on%ary goa$ is to use te #omputer ar%ware in an effi#ient manner./ Computer Hardware ! CP01 memory1 "2O %evi#es provi%e &asi# #omputing resour#es. System and Application Programs ! Compi$ers1 %ata&ase systems1 games1 &usiness programs1 et#. %efine te ways te #omputing resour#es are use% to so$ve te users pro&$ems. Operating System ! Contro$s an% #oor%inates te #omputing resour#es among te system an% app$i#ation programs for te users. 1 End User ! 3iews te #omputer system as a set of app$i#ations. ,e 4n% 0ser is genera$$y not #on#erne% wit various %etai$s of te ar%ware. Programmer ! 0ses $anguages1 uti$ities (fre5uent$y use% fun#tions) an% OS servi#es ($in.ers1 assem&$ers1 et#.) to %eve$op app$i#ations instea%. ,is meto% is use% to re%u#e #omp$e-ity &y a&stra#ting te %etai$ of ma#ine %epen%ant #a$$s into +P"s an% various uti$ities an% OS servi#es. OS Mas.s te ar%ware %etai$s from te programmer an% provi%es an interfa#e to te system. Manages te #omputers resour#es. ,e OS %esigner as to &e fami$iar wit user re5uirements an% ar%ware %etai$s. &. OS attri&utes i. Convenien#e ! ma.e te #omputer easy to use ii. 4ffi#ien#y ! manage #omputer resour#es in an effi#ient manner iii. +&i$ity to 4vo$ve ! +n OS sou$% &e a&$e to integrate new system fun#tions an% a%%itions2mo%ifi#ations witout interfering wit servi#e or over &ur%ening users. #. OS #an &e tougt of as) i. Contro$ Program an% 6esour#e +$$o#ator ! ,e OS is a program1 $i.e oter programs in te system. 7i.e oter programs1 it ma%e of instru#tions1 &ut its instru#tions serve te purpose to a$$o#ate resour#es (CP01 memory1 %is. storage1 i2o) so tat oter programs #an operate. ,o %o tis it must stop itse$f from running an% $et oter programs run. Wen te oter program8s turn to run is over1 te OS runs $ong enoug to prepare te resour#es for te ne-t pro#ess to run1 an% so on. 9 ii. 0ser to Computer "nterfa#e ! Provi%es an frien%$y environment from wi# user #an a##omp$is teir goa$s. %. OS from te viewpoint tat it is 0ser2Computer "nterfa#e ! ,e OS a#ts as an interme%iary &etween te 0sers2Programmers an% te ar%ware1 ma.ing it easier for users1 programmers1 an% app$i#ations to a##ess te OS8s fa#i$ities1 servi#es (fa#i$ities #an &e tougt of as te system8s resour#es1 servi#es are te meto%s tat te OS provi%es to use te fa#i$ities). Servi#es are typi#a$$y provi%e% in te fo$$owing areas) i. Program :eve$opment ! e%itors1 %e&uggers1 #ompi$ers1 et#. ii. Program 4-e#ution ! $oa%ers1 $in.ers1 system prote#tion. iii. +##ess to "2O %evi#es ! Provi%es a uniform interfa#e1 usua$$y simp$e rea%s an% writes1 tat i%es te %etai$s of i2o %evi#e operation. iv. 'i$e a##ess an% prote#tion ! Must &e a&$e to manage storage %evi#es1 a##ess %ata in fi$e1 an% provi%es a##ess #ontro$ to fi$es. v. 4rror %ete#tion ! Must &e a&$e to gra#efu$$y an%$e various errors1 su# as memory a##ess vio$ations1 %ivi%e &y (ero1 %evi#e errors1 et#. vi. System 7ogging ! $og important system events for system tuning1 error #orre#tion an%2or &i$$ing information. e. ;rief istory (Wi.ipe%ia) i. ,e first #omputers %i% not ave an OS &ut programs for managing te system an% using te ar%ware 5ui#.$y appeare%. ii. ;y te ear$y 1<=0s1 #ommer#ia$ #omputer ven%ors1 su# as 0N"3+C an% Contro$ :ata Corporation1 were supp$ying 5uite e-tensive too$s for stream$ining te %eve$opment1 s#e%u$ing1 an% e-e#ution of >o&s on &at# pro#essing systems. iii. "n te 1<=0s ";M System23=0 OS 3=0 was %eve$ope% to run on a wo$e $ine of #omputers. "t was a first1 an OS for severa$ %ifferent ma#ines in ";M8s pro%u#t $ine. 'eatures in#$u%e%) 1. ?ar% %is. storage %eve$opment. 9. ,ime saring environment. ,ime saring provi%e% users te i$$usion of aving te wo$e ma#ine to temse$ves. iv. Mu$ti#s was anoter we$$ .nown OS tat use% te time saring #on#epts. "t inspire% severa$ OS8s in#$u%ing 0ni- an% 3MS. v. ,e first mi#ro#omputers (pre%e#essors to PCs) %i% not re5uire2use most of te a%van#e% features use% for mainframes an% mini #omputers. vi. CP2M (Contro$ Program2Monitor) was #reate% &y :igita$8s @ary Ai$%a$$ for "nte$ B0B02B0BC an% Di$og DB0 pro#essors in a&out 1<E4. "t is te pre%e#essor for ";M8s PC :OS an% MS :OS. :OS8s ma>or #ontri&ution was its '+, fi$e system. vii. "n te 1<B08s :OS %ominate% te "nte$ &ase% PC8s wi$e te Ma#intos operating system1 patterne% after F46OF #orporations ear$y win%ow &ase% %o#ument e%iting operating systems1 provi%e% #ompetition on te +pp$e p$atform. f. Computer System Stru#tures ! + mo%ern #omputer #onsists of) 3 i. CP0 ! Centra$ Pro#essing 0nit. "s responsi&$e for e-e#ution of aritmeti#1 $ogi#a$1 %ata transfer1 an% #ontro$ operations. ii. :evi#e Contro$$ers 1. %is. %rive #ontro$$er 9. au%io %evi#e #ontro$$er 3. vi%eo #ontro$$er 4. et#. iii. System ;us ! Serves as a #ommuni#ation #anne$ &etween te various system #omponents. iv. Memory ! Storage of instru#tions an% %ata for system an% user pro#esses. ,e CP0 an% %evi#e #ontro$$ers #an run #on#urrent$y. + memory #ontro$$er syn#roni(es te CP08s an% %evi#e #ontro$$er8s a##ess to memory.
0pon power up) o ;ootstrap program initia$i(es a$$ system aspe#ts. CP0 6egisters :evi#e Contro$$ers Memory Contents o 7oa%s OS an% starts its e-e#ution. 7o#ates OS in storage (%is.). 4 7oa%s OS .erne$ (&asi# OS fun#tions) ;egins OS fun#tion (init1 or monitor) Storage :evi#es) o Main Memory ! re$ative$y sma$$ in si(e (39. to 4gig)1 re$ative$y fast a##ess spee%1 ran%om a##ess1 vo$ati$e. ,e on$y $arge storage area tat te CP0 #an %ire#t$y a##ess. ,e oter memory areas tat te CP0 #an a##ess are) 6egisters (typi#a$$y 9C= &ytes) rea$$y fast Ca#e (=4. ! 9C=.) fast o :is. ! 7arge in si(e1 me%ium a##ess spee%1 ran%om a##ess1 nonG vo$ati$e 4$e#troni# %is. Magneti# %is. Opti#a$ %rive o Magneti# ,ape ! 6ea$$y 7arge1 $ow spee%1 se5uentia$ a##ess1 nonG vo$ati$e g. Operating System Components (Capter 31 Si$&ers#at() ! Main #omponents are pro#ess1 memory1 fi$e1 "2O system1 an% se#on%ary storage management. i. Pro#ess Management responsi&i$ities. 1. Creation an% :e$etion of user an% system pro#esses. 9. Suspension an% resumption of pro#esses. 3. Provision of me#anisms for pro#ess syn#roni(ation. 4. Provision of me#anisms for pro#ess #ommuni#ation. C. Provision of me#anisms for %ea%$o#. an%$ing. ii. Main Memory Management responsi&i$ities 1. Aeep tra#. of wi# parts of memory are &eing use% an% &y wat pro#esses. 9. :e#i%e wi# pro#esses are to &e $oa%e% into memory wen memory spa#e &e#omes avai$a&$e. 3. +$$o#ate an% %eGa$$o#ate memory as nee%e%. iii. 'i$e Management responsi&i$ities 1. Creation an% %e$etion of fi$es. 9. Creation an% %e$etion of %ire#tories. 3. ,e support of primitives for manipu$ating fi$es an% %ire#tories. 4. Mapping of fi$es onto se#on%ary storage. C. ;a#.up of fi$es onto sta&$e storage me%ia. iv. "2O System Management ! i%es te pe#u$iarities of spe#ifi# ar%ware %evi#es from te user. ,e su&Gsystem (in 0N"F) #onsists of) 1. Memory management #omponent in#$u%ing &uffering1 #a#ing an% spoo$ing (spooling refers to putting >o&s in a &uffer1 a spe#ia$ area in memory1 or on a %is. were a %evi#e #an a##ess tem wen it is rea%y. Spool is an a#ronym for simultaneous peripheral operations on-line. 4ar$y mainframe #omputers a% re$ative$y sma$$ an% e-pensive (&y #urrent stan%ar%s) ar% C %is.s. ,ese #osts ma%e it ne#essary to reserve te %is.s for fi$es tat required ran%om a##ess1 wi$e writing $arge se5uentia$ fi$es to ree$s of tape. ,ypi#a$ programs wou$% run for ours an% pro%u#e un%re%s or tousan%s of pages of printe% output. Perio%i#a$$y te program wou$% stop printing for a wi$e to %o a $engty sear# or sort. ;ut it was %esira&$e to .eep te printer(s) running #ontinuous$y. ,us wen a program was running1 it wou$% write te printa&$e fi$e to a spool of tape1 wi# wou$% $ater &e rea% &a#. in &y te program #ontro$$ing te printer. Wi.ipe%ia.org) 9. + genera$ %evi#e %river interfa#e. 3. :rivers for spe#ifi# ar%ware %evi#es. On$y te %evi#e %river .nows te operation spe#ifi#s of te %evi#e to wi# it is assigne%. v. Se#on%ary Storage Management 1. 'reeGspa#e management. 9. Storage a$$o#ation 3. :is. s#e%u$ing . 'irst Operating Systems i. Simp$e ;at# (One Ho& at a time) 1. ;at# refers to an ear$y type of pro#essing in wi# te user wou$% su&mit a >o& (program1 %ata1 an% #ontro$ information a&out te nature of te >o& (usua$$y on #ar%s)) to an operator. a. ,e operator wou$% group te >o&s into $i.e *&at#es/ (for e-amp$e1 a$$ 'O6,6+N programs may &e groupe% = togeter1 saving $oa% time for te #ompi$er) an% put tem into te #ar% rea%er. &. + program #a$$e% a *monitor/ signa$s te #ar% rea%er to rea% a >o&. On#e te >o& is $oa%e%1 te monitor an%s e-e#ution over to te >o&. Wen >o& #omp$etes1 te monitor ta.es over an% pro#ess repeats. i. + monitor tat a$ways is in main memory is #a$$e% a *resi%ent monitor/. #. ,e output wou$% &e spoo$e% to a printer. "f te program fai$e%1 error messages from te #ompi$er or a memory %ump wou$% &e#ome te output. 9. + %efinitive feature of ;at# Pro#essing is te $a#. of intera#tion &etween te user an% program wi$e te program is e-e#uting. 3. Ho&s are usua$$y run one at a time1 first #ome first serve. 4. ,e $anguage tat instru#ts te monitor on te parti#u$ars ($anguage1 tape mounting1 et#) is #a$$e% Ho& Contro$ 7anguage (HC7). C. ,e %e$ay &etween >o& su&mission an% #omp$etion is #a$$e% turnaround time. =. ;e#ause te CP0 is or%ers of magnitu%e faster tan te #ar% rea%ers an% printers1 tere is $ots of CP0 i%$e time. E. ,wo e-e#ution mo%es are often use% to ai% in system prote#tion) a. 0ser mo%e) ,e app$i#ation program run in tis mo%e. "t as a##ess to a su&set of te systems #omman%s an% memory spa#e. Certain areas of memory (te area in wi# te monitor resi%es) are off $imits. &. Aerne$ mo%e) Sometimes #a$$e% privi$ege% mo%e. ,e monitor as a##ess to a$$ instru#tions an% memory areas of te system. ii. Mu$tiGprogramme% &at# ! Simi$ar to simp$e &at# e-#ept tat te #omputer e-e#utes >o&s from a poo$ of >o&s tat ave &een $oa%e% into te memory. ,e a%vantage is tat CP0 i%$e time is re%u#e%1 an% "2O %evi#es %o not sit i%$e. 1. Ho&s are $oa%e% #ontinua$$y from #ar%s into te >o& poo$ (in memory). 9. ,e OS se$e#ts a >o& to &e run. 3. Wen te >o& as to wait for some tas. (su# as a tape to &e mounte% or an "2O operation (#ar% rea%1 or print resu$t) te CP0 swit#es e-e#ution to anoter >o& from te >o& poo$. 4. Wen tat >o& as to wait1 te CP0 is swit#e% to anoter >o& an% so on. Wen ea# >o& finises its waiting time1 it eventua$$y gets te CP0 &a#.. "n tis way CP0 i%$e time is re%u#e%. C. ,is s#eme intro%u#es two new #on#epts) E a. Memory management &. CP0 s#e%u$ing iii. ,imesaring (Mu$tiGtas.ing) ! Mainframe #omputers use% time saring to give users1 $o#ate% at remote termina$s1 (sometimes #a$$e% *%um& termina$s/) te i$$usion tat ea# user a% te #omputer to temse$ves. 1. "ntro%u#es user2#omputer intera#tion. 9. "ntera#tion e$ps in) a. 'in%ing #ompi$er time errors. &. 'i$e e%iting. #. :e&ugging #o%e wi$e it is running. %. 4-e#ution of mu$tiGstep >o&s in wi# $ater >o&s %epen% on resu$ts of ear$ier >o&s. 3. Mu$tip$e >o&s are e-e#ute% &y te CP0 swit#ing &etween tem (a swit# from one >o& to anoter is referre% to as *#onte-t swit#/)1 &ut te swit#es o##ur so fre5uent$y tat te users may intera#t wit te programs as tey run. CP0 is *time mu$tip$e-e% &etween te users/. 4. 6e5uires) a. 0ser a##essi&$e onG$ine fi$e system. &. :ire#tory system #. CP0 s#e%u$ing %. Mu$tiprogramming. C. Common$y uses) a. 3irtua$ memory (a te#ni5ue tat a$$ows e-e#ution of a >o& tat may not &e #omp$ete$y in memory). 9. ;a#.groun% an% ;asi#s a. Computer System review i. +r#ite#ture (Sta$$ings1 page <) 1. Pro#essor ! Carries out te operation of te #omputer. ,e pro#essor #onsists of at $east one +ritmeti# 7ogi# 0nit (+70) an% severa$ registers. ,e registers are use% for a%%ressing1 #omparisons1 aritmeti# operations et#. 9. Main Memory ! Stores %ata an% programs. Main memory is usua$$y vo$ati$e (wen power is sut %own1 #ontents are $ost). 3. "2O Mo%u$es ! Moves %ata &etween system an% e-terna$ environment (se#on%ary memory %evi#es G %is.s1 termina$s1 et#) 4. System &us ! Provi%es #ommuni#ation among system #omponents. B :efinitions (e-presse% using C notation) PC ! Program Counter1 #ontains te a%%ress of te ne-t instru#tion to &e fet#e% from memory. "6 ! "nstru#tion 6egister1 #ontains te instru#tion most re#ent$y fet#e%. M+6 ImemoryJ&uffer 2K +%%ress of &uffer $o#ation for ne-t rea% or write. K2 M;6 (ImemoryJ&uffer) /* Contains %ata to &e written or re#eive% from memory. */ "2O +6 ! :enotes "2O %evi#e "2O ;6 ! +%%ress in "2O &uffer of %ata to &e move% ii. "nstru#tion #y#$e 1. + program is a $ist of instru#tions. 9. ,o e-e#ute a program te instru#tions are e-e#ute% se5uentia$$y (usua$$y) from start to en%. 3. ,e instru#tion e-e#ution pro#ess as two steps. a. 'et# stage ! ,e instru#tion at te $o#ation pointe% to &y te PC is $oa%e% in te "6. &. 4-e#ute stage ! ,e instru#tion in te "6 is e-e#ute% &y te CP0. "n genera$1 tere are four #ategories of instru#tions) i. Pro#essor to Memory transfer ii. Pro#essor to "2O transfer iii. :ata Pro#essing ! +n aritmeti# or $ogi#a$ operation is performe% on %ata < iv. Contro$ ! ,e se5uen#e of e-e#ution is a$tere%. 'or e-amp$e a *>ump #omman%/. iii. Pro#ess Contro$ ;$o#. ! 4very program tat is e-e#uting as a Pro#ess Contro$ ;$o#. (PC;) asso#iate% wit it. ,e PC; is a &$o#. of %ata tat OS uses to .eep tra#. of te status of te running program. "t #ontains pro#ess state information1 e-e#ution s#e%u$ing %ata1 memory management information1 et#. 3. Pro#esses a. :efinition ! + #omputer program is a passive entity tat is store% in fi$e. Wen te program is &eing e-e#ute%1 it is #a$$e% a *pro#ess/. + pro#ess is more tan te #o%e &eing e-e#ute%L it a$so in#$u%es information su# as) i. ,e #urrent part of te program &eing e-e#ute%. ii. CP0 register %ata1 program sta#. %ata (temporary %ata use% &y te program in#$u%ing su&routine parameter1 return a%%resses an% temporary varia&$es) iii. + g$o&a$ %ata se#tion. &. Pro#ess States i. C state mo%e$ ew ! ,e pro#ess is &eing #reate%. PC; is &eing #reate% an% initia$i(e%. !unning ! "nstru#tions are &eing e-e#ute%. "aiting #$loc%ed& ! ,e pro#ess is waiting for some event to o##ur (su# as "2O #omp$etion or re#eiving a signa$). !eady ! ,e pro#ess is waiting for te CP0. 'erminated ! ,e pro#ess as finise% e-e#ution. 10 #. Pro#ess stru#ture ! ,e OS .eeps tra#. of ea# pro#ess &y maintaining a %ata stru#ture #a$$e% a Pro#ess Contro$ ;$o#. (PC;). i. PC; an% #omponents (typi#a$) (Sta$$ings1 page 111) 1. Pro#ess ": (P":) ! uni5ue i%entifier 9. Pro#ess State ! New1 running1 waiting1 rea%y1 or terminate%. 3. Priority ! Priority $eve$ in re$ation to oter pro#esses. 4. Program Counter (PC) ! +%%ress of te ne-t instru#tion to &e e-e#ute% in te pro#ess. C. Conte-t %ata ! Current register va$ues =. "2O status information ! Outstan%ing "2O re5uests1 "2O %evi#es1 open fi$es use% &y te pro#ess1 et#. E. +##ounting "nformation ! CP0 time1 e$apse% time1 run time $imit1 et#. B. Oter information #ommon$y in#$u%e%) a. Memory "nformation ! ;ase an% 7imit registers1 page ta&$e %ata. &. S#e%u$ing information ! Pointers to s#e%u$ing 5ueues. %. Operations on Pro#esses i. Creation 1. +ssign uni5ue P": 9. +$$o#ate memory for te pro#ess. Can use %efau$ts for te type of pro#ess1 or use spe#ifi# num&ers as re5ueste% &y te pro#ess. a. Co%e spa#e &. Sta#. spa#e 3. "nitia$i(e te PC; ! "nitia$i(e te PC; va$ues. 4. Put pro#ess in appropriate 5ueue ! Most new pro#esses are put into te new pro#ess 5ueue (or 6ea%y2Suspen%e% 5ueue). C. "nitia$i(e Pro#ess +##ounting Parameters ! 0p%ate system $og fi$es. ii. Pro#ess Spawning ! Creation of a pro#ess &y anoter pro#ess. 1. Parent ! Creating pro#ess. 9. Ci$% ! New$y #reate% pro#ess. "t wi$$ nee% resour#es (CP0 time1 memory1 fi$es1 "2O %evi#es). ,ey #ome from eiter te parent pro#ess or te OS. 3. 4-e#ution of parent an% #i$% #an ta.e severa$ forms) a. Con#urrent e-e#ution of parent an% #i$%. &. Parent waits unti$ some or a$$ of its #i$% pro#esses #omp$ete. 4. Nature of parent2#i$%) a. Ci$% pro#ess is #opy of parent. i. 0N"F for. #a$$ #an &e use%. Ci$% is i%enti#a$ e-#ept tat te return #o%e for te parent is 0 an% te return #o%e for te #i$% is non(ero. ii. 4-amp$e of 0ni- for.) 11 Pi% M for.()L "f (Pi% N 0) O Printf(*Ci$% pro#ess #reation fai$e%. Pn/)L Q e$se if (Pi% MM 0) O 2K :o parent operations. K2 Q e$se O 2K :o #i$% operations. K2 Q iii. :e$etion (,ermination) 1. Norma$ ,ermination G Pro#ess terminates wen $ast instru#tion is as #omp$ete%. + #a$$ to e-it() re5uests tat te OS %e$etes te pro#ess. 9. Parent #an terminate #i$% using a&ort #a$$ for te fo$$owing reasons) a. Ci$% e-#ee%e% use of its resour#es. &. Ci$%8s tas. is no $onger nee%e%. #. Parent is e-iting1 many OS8s %o not a$$ow #i$% pro#ess to #ontinue after parent terminates. e. ,rea%s ! Sometimes #a$$e% a *$igtweigt pro#ess/ or 7WP. "t as its own) i. Program Counter (PC) ii. 6egister set iii. Sta#. spa#e f. 7igtweigt pro#esses sares wit peer trea%s. i. Co%e se#tion ii. :ata se#tion iii. OS resour#e su# as open fi$es an% signa$s g. ,rea%s are use% wen trea%s wor. on re$ate% >o&s. "t #an &e more effi#ient to use mu$tip$e trea%s1 for e-amp$e provi%ing %ata to mu$tip$e remote ma#ines on a networ.. ?aving one pro#ess wit mu$tip$e trea%s1 ea# e-e#uting te same #o%e1 &ut aving %ifferent %ata an% fi$e se#tions is more effi#ient tan mu$tip$e eavy weigt pro#esses. 4. CP0 S#e%u$ing a. CP0 G "2O &urst #y#$e ! Pro#ess e-e#ution a$ternates &etween perio%s of CP0 use an% "2O waiting. ,ese pases are #a$$e% CP0 &urst an% "2O &urst. + pro#ess starts wit a CP0 &urst an% ten a$ternates &etween "2O &urst an% CP0 &urst unti$ #omp$etion wit a CP0 &urst1 a system re5uest for termination of te pro#ess. ,e amount of CP0 &urst an% "2O &urst vary great$y from pro#ess to pro#ess. Some e-amp$es are &e$ow. i. :ata&ase program ! "2O intense (%is.) ii. Simu$ation ! CP0 intense (#a$#u$ation of matemati#a$ mo%e$s) iii. Pi#ture 6en%ering ! CP0 intense iv. 4-#e$ ! "2O intense (most$y waits on user to enter %ata) v. @ames ! &ot CP0 intense (ren%ering of s#enes)1 an% "2O intense (%isp$ay of s#enes1 an% user inputs) 19 &. Conte-t Swit#ing G Canging of pro#ess states. ,e more #onte-t swit#ing1 te iger te overea%1 meaning $ess app$i#ation wor. is &eing a##omp$ise%. Conte-t swit#ing invo$ves) i. Saving te state of te running pro#ess in its PC;. ii. 7oa%ing a save% pro#ess. #. S#e%u$ing i. Sort ,erm ! Wen te CP0 &e#omes i%$e1 a >o& from te 6ea%y Rueue is se$e#te% to run. ,is is te >o& of te sort term s#e%u$er. 1. Operates very fre5uent$y. 9. Cou$% &e invo.e% at a rate of 10 times a se#on%. 3. ;e#ause it operates often it must &e fast. 4. :ispat#er. "t is te %ispat#er8s >o& to give #ontro$ of te CP0 to te mo%u$e se$e#te% &y te Sort ,erm S#e%u$er. :ispat#ing invo$ves) a. Swit#ing Conte-t. &. Swit#ing to user mo%e. #. Humping te proper $o#ation in te program (i%entifie% in te PC;) an% restarting te program. ii. 7ong ,erm ! "t is te >o& of te $ong term s#e%u$er to se$e#t >o&s from te >o& poo$ an% $oa% tem into memory for e-e#ution. "n genera$ te 7ong ,erm s#e%u$er wi$$ attempt to &a$an#e te system &etween CP0 an% "2O &oun% pro#esses to ma.e greatest use of avai$a&$e resour#es. 1. Operates $ess fre5uent$y. 9. Cou$% minutes &etween #a$$s. 3. ;e#ause it is #a$$e% infre5uent$y1 it #an ta.e time to %e#i%e wi# pro#esses sou$% &e se$e#te% for e-e#ution. 4. Some systems %on8t use 7ong ,erm s#e%u$ers1 or tey are very minima$. ,ime saring systems are a goo% e-amp$e. ,ey >ust put every new pro#ess into te 6ea%y Rueue. iii. Preemptive ! S#e%u$er %oes not wait for an "2O re5uest or an interrupt to move a >o& from te running 5ueue to te rea%y 5ueue. 1. ,ime Saring System ! 4a# pro#ess in te running 5ueue gets an a$$otment of CP0 #y#$es. "f te pro#ess %oes not terminate or ma.e an "2O re5uest &efore its a$$otment #omp$etes te s#e%u$er moves to anoter running pro#ess. %. S#e%u$ing Criteria ! :ifferent s#e%u$ing a$goritms try to optimi(e te fo$$owing #riteria to %ifferent %egrees) i. CP0 0ti$i(ation ! Aeep te CP0 as &usy as possi&$e. "n a rea$ system a $igt $oa% is a&out 40S1 eavy <0S. ii. ,rougput ! ,e num&er of pro#ess #omp$ete% per time unit. Can range anywere &etween more tan 10 pro#ess per se#on% to $ess tan 1 per our. iii. ,urnaroun% time ! ,is is a measure of ow $ong a pro#ess spen%s in te system. "t is te time from wen te pro#ess is su&mitte% to #omp$etion. 13 iv. Waiting time ! ,e s#e%u$ing a$goritm %oes not effe#t te amount of time spent e-e#uting or %oing "2OL it on$y affe#ts te time spent in te rea%y 5ueue. Waiting time is te sum of time perio%s waiting in te rea%y 5ueue. v. 6esponse time ! ,e amount of time tat from su&mission of te >o& to its first response to te user. @oo% response time is important in time saring systems. e. +$goritms i. 'irst Come 'irst Serve ! Pro#esses are serve% in te or%er tey are re#eive%. Can &e imp$emente% wit a '"'O 5ueue. 1. Waiting time is ig$y %epen%ent on or%er of >o&s an% #an &e $ong. 9. NonGPreemptive 3. CP0 intense >o&s #an #ause a$$ "2O &oun% >o&s to wait for tem to #omp$ete. +s "2O &oun% >o&s wait for "2O tey a$$ move from te waiting 5ueue to te rea%y 5ueue an% te CP0 intense >o& %ominates te CP0. ii. Sortest Ho& 'irst ! ,e >o& in te rea%y 5ueue wit te sortest ne-t CP0 &urst is se$e#te%. "f two >o&s ave e5ua$ ne-t CP0 &urst1 'C'S &rea.s te tie. 1. +$goritm is prova&$y optima$. "t gives te minimum waiting time for a set of pro#esses. 14 9. ,e ma>or %raw&a#. is .nowing wat te $engt of te ne-t CP0 &urst for ea# pro#ess wi$$ &e. a. No pra#ti#a$ way to .now its va$ue. &. 3a$ue #an &e pre%i#te%L #ou$% &e simi$ar in $engt to previous &ursts. 3. SH' #an &e preemptive or nonGpreemptive. 1C iii. Priority S#e%u$ing ! "nstea% of $oo.ing at te or%er in wi# >o&s arrive an%2or teir estimate% CP0 &ursts1 >o&s run in or%er of importan#e (priority). 1. Ho&s of e5ua$ priority are s#e%u$e% 'C'S 9. SH' is a spe#ia$ #ase of priority s#e%u$ing1 in wi# te priority is te inverse of te estimate% CP0 &urst. 3. Priority s#e%u$ing #an &e preemptive or nonGpreemptive. 4. Suffers from in%efinite &$o#.ing or starvation. + $ow priority >o& #an &e #ause% to wait in%efinite$y &y iger priority >o&s. a. 'rom Si$&ers#at( page 134 *6umor as it tat 1 wen tey sut %own te ";M E0<4 at M", in 1<E31 tey foun% a $owGpriority pro#ess tat a% &een su&mitte% in 1<=E an% not yet &een run./ &. *+ging/ is a pro#ess in wi# te priority of pro#esses tat ave &een waiting for a $ong time is in#rease%. iv. 6oun% 6o&in ! 'C'S a$goritm in wi# ea# pro#ess in te rea%y 5ueue is preempte% after a sort time (time 5uantum). 1. ,e rea%y 5ueue is treate% as a #ir#u$ar 5ueue. 9. ,e s#e%u$er goes aroun% te rea%y 5ueue a$$o#ating te CP0 ea# pro#ess for a ma-imum of 1 time 5uantum. 3. +verage waiting time #an &e $ong. 4. 0se% in time saring systems were response time is important (nee%s to &e sort). f. +ssignment 1 ! Program a s#e%u$er1 imp$ement 'C'S1 SH'1 an% 6oun% 6o&in (:ue in 3 wee.s). C. Rui( 1 6eview ! 6eview of se#tions 1 troug 4 (Wee. 4) =. Rui( 1 E. Pro#ess Syn#roni(ation G Wat meto%s are avai$a&$e for #oor%inating #ooperating pro#esses tat sare resour#es1 su# as memory1 so tat tey e-e#ute #orre#t$y every timeT 1= a. "nstru#tions from te pro#esses are inter$eave% in an unpre%i#ta&$e way. &. Criti#a$ Se#tion Pro&$em ! + region of #o%e in wi# a pro#ess may &e #anging #ommon varia&$es1 &uffers1 et#. Wi$e te pro#ess is in its #riti#a$ se#tion no oter pro#ess #an &e in teir #orrespon%ing #riti#a$ se#tion. (Mutua$ e-#$usion). 1E "n te #o%e i$$ustration a&ove a #onte-t swit# from te pro%u#er to te #onsumer is e-e#ute% wi$e te pro%u#er is e-e#uting te #ount in#rement instru#tion. +s a resu$t an item is $ost (te pro%u#er wi$$ write over it) &e#ause te #ount varia&$e is %e#remente% an% in#remente% witout any a#tion %ata transfer a#tions o##urring. #. So$utions #enter aroun% te fo$$owing strategies) i. "n#rement2:e#rement operations are atomi# (#annot &e &ro.en %own into a series of instru#tions) ii. Prote#t te in#rement an% %e#rement #a$$s in #riti#a$ se#tions. 1. Software so$ution (@enera$ #riti#a$ se#tion so$ution) 9. ?ar%ware so$ution (,est an% set1 semapores1 et#.) %. ,o so$ve te #riti#a$ se#tion pro&$em1 te fo$$owing re5uirements must &e satisfie%) i. Mutua$ 4-#$usion ! "f pro#ess p(i) is e-e#uting its #riti#a$ se#tion1 ten no oter pro#esses #an &e e-e#uting teir #riti#a$ se#tions. ii. Progress ! "f te #riti#a$ se#tions are va#ant an% a pro#ess wises to enter1 ten on$y pro#esses tat wis to enter a #riti#a$ se#tion #an parti#ipate in te %e#ision a&out wi# pro#ess enters ne-t1 an% tis pro#ess #annot ta.e an in%efinite amount of time. iii. ;oun%e% Waiting ! ,ere is a $imit on te num&er of times tat a pro#ess #an &e as.e% to %efer entry into its #riti#a$ se#tion in favor of oters. e. ,wo Pro#ess So$utions 1B i. Stru#ture of so$ution) 6epeat Entry into critical section Criti#a$ se#tion . . . E(it )rom critical section 0nti$ %one ii. +$goritm 1 Pro#ess P(i) Entry* wi$e(turn UM i) O :o notingL Q . . . E(it* turn M (1Gi) turn M O01 1Q1 initia$$y 0 P0 P1 turn 4nters Waits 0 4-it Wait 0 to 1 wait 4nter 1 Wait e-it 1 to 0 "f P0 uses its turn ten (upon e-it1 turn is set to 1) an% ten P1 %oes not enter its #riti#a$ se#tion (it never sets turn &a#. to 0) ten if P0 wants to enter its #riti#a$ se#tion1 it wi$$ wait forever (or at $east unti$ P1 resets turn &a#. to 0). So tis a$goritm vio$ates &oun%e% waiting. iii. +$goritm 9 Pro#ess P(i) Entry* f$agViW M ,604L Wi$e(f$agV1 ! iW) O :o notingL Q . . . E(it* f$agViW M '+7S4L 1< "n tis a$goritm te pro#ess sets its f$ag in%i#ating tat it is entering its #riti#a$ se#tion an% ten waits for te oter pro#ess to $eave its #riti#a$ se#tion. "f &ot pro#esses it te f$agViW M ,604 statement at te same time %ea%$o#. o##urs. ;ot pro#esses wi$$ wait on ea# oter forever in te wi$e $oop. iv. +$goritm 3 Pro#ess P(i) Entry* f$agViW M ,604L ,urn M 1GiL Wi$e(f$agViG1W II (turn M 1 ! i)) O :o notingL Q . . . E(it* f$agViW M '+7S4L "n tis a$goritm te pro#ess in%i#ates tat it %esires to enter te #riti#a$ region1 &ut %efers to te oter pro#ess. "f &ot pro#ess it te entry point at te same time1 te $ast pro#ess to %efer to te oter pro#ess waits. +s soon tat pro#ess #$ears its #riti#a$ se#tion it resets its f$ag a$$owing te oter pro#ess to enter its #riti#a$ se#tion. P0 P1 1 '$agV0W M ,604 9 '$agV1W M ,604 3 ,urn M 1 4 ,urn M 0 C Wi$e M '+7S4 C Wi$e M ,604 v. ;a.ery +$goritm ! ,e mu$tip$e pro#ess version of a$goritm 3 is #a$$e% te ;a.ery +$goritm. f. Syn#roni(ation ?ar%ware ! ?ar%ware provision #an ma.e #riti#a$ se#tion so$utions easier. One option is to %isa$$ow interrupts wi$e a pro#ess in a #riti#a$ se#tion. "nterrupt %isa&$ing is not a goo% so$ution for mu$tiGpro#essor ma#ines &e#ause it ta.es time to %isa&$e1 an% to pass te message to oter pro#essors to %isa&$e. +noter %isa%vantage is tat some system #$o#.s are .ept up%ate% &y interrupts. i. ,est an% Set G ,e test an% set operation is a ma#ine instru#tion in te CP08s instru#tion set1 meaning tat it operates atomi#a$$y (as one unG interrupti&$e unit) . "t8s fun#tion is to pro&e retrieve te #ontents of a varia&$e1 return it va$ue1 an% at te same time set its va$ue to ,604L 90 ,est+n%Set(-) O temp M -L - M ,604L return tempL Q Entry* wi$e(,est+n%Set(-)) O :o notingL Q . . . E(it* - M '+7S4L "f - is '+7S4 it is set to ,604 an% we fa$$ out of te $oop1 e-e#ute te #riti#a$ se#tion1 an% up e-it1 reset it to '+7S4. "f - is ,6041 we it set it to ,604 an% wait in te $oop unti$ anoter pro#ess sets - to '+7S4L ii. Swap. iii. ?omewor. pro&$em ! %efine te swap() fun#tion. 4-p$ain ow it wor.s. Compare an% #ontrast it to te ,est+n%Set() fun#tion. g. Semapores i. ,e previous so$utions are not easy to genera$i(e to mu$tip$e pro#ess so$utions. Semapores are a too$ to e$p wit tis. ii. + semapore1 s1 is an integer varia&$e. "n or%er to use semapores1 two atomi# operations are %efine%) 1. Wait(s) M P(s) M test 9. Signa$(s) M 3(s) M in#rement 3. ,ey are sometimes referre% to as P(s) an% 3(s) for te :ut# wor%s proberen (wait)1 an% verhogen (signa$). wait(S) O wi$e(SNM 0) O %o notingL Q S M SG1L Q 91 signa$(S) O S M SX1L Q 4. ;ot operations must &e atomi#1 tat is on$y one pro#ess #an mo%ify te semapore va$ue at any given time. C. Stru#ture of te so$ution is as &efore) 2K mute- is initia$i(e% to 1 K2 repeat O wait(mute-)L #riti#a$ se#tion signa$(mute-) unti$ fa$seL =. Consi%er two pro#esses using semapores to syn#roni(e teir operations. ,o %o so tey wi$$ sare a #ommon varia&$e1 synch. a. ,is time1 initia$i(e syn# to 0. P1() O . . . S1L signa$(syn#)L . . Q P9() O . . . wait(syn#)L S9L . . Q 99 &. Statements $o#ate% after te wait() statement in P9 wi$$ on$y &e e-e#ute% after te signa$() in P11 meaning a$$ statements &efore te signa$() statement in P1 wi$$ e-e#ute &efore a$$ statements after te wait() statement in P9. #. "mp$ementation :etai$s) i. ,e ear$ier so$utions a$ong wit te semapore so$ution re$y on busy waiting. ;usy waiting is wen te pro#ess $oops #ontinuous$y in te #riti#a$ se#tion entry #o%e. 1. 6eferre% to sometimes as a spinG$o#.. 9. "n a sing$e CP0 system tat is mu$tiG programme%1 spinG$o#.s #an eat va$ua&$e CP0 s$i#es. 3. ;e#ause tey re5uire no #onte-t swit# spinG$o#.s #an &e goo%1 as $ong as te time in tem is sort. 4. ,e #ure) a. 6e%efine te wait statement to use &$o#.ing instea% of &usy waiting. i. ;$o#.ing means tat te pro#ess puts itse$f into te wait 5ueue wen te wait() is en#ountere%. ii. Wen a signa$() #a$$ is ma%e1 &$o#.e% pro#esses are restarte% &y a wa.eup() operation tat puts tem into te rea%y 5ueue. On#e tey are in te run 5ueue tey #e#. teir semapore. "f it is Y 0 ten tey pass te wait() #a$$ is e-ite%1 oterwise tey return temse$ves to te wait 5ueue. iii. So &usy waiting (te wasting of CP0 #y#$es) is $arge$y e$iminate%1 &ut not #omp$ete$y. "t %oes so at te e-pense of rea#tion time to te signa$. 93 . :ea%$o#.s an% Starvation i. Wen two or more pro#esses are waiting in%efinite$y for a signa$ tat #an on$y &e sent &y one of te waiting pro#esses te pro#esses are sai% to &e *%ea%$o#.e%/. See te e-amp$e &e$ow) 2K "nitia$i(e te semapores to 1. K2 S M 1L R M 1L P0 P1 Wait(S)L wait(R)L Wait(R)L Wait(S)L . . . . . . signa$(S)L signa$(R)L signa$(R)L signa$(S)L ,e first series of waits %e#rements te semapores1 S an% R1 to 0 an% fa$$s out of te wait #a$$s. ,e ne-t set puts &ot pro#esses P0 an% P1 into te wait 5ueue1 resu$ting in a %ea%$o#. &e#ause te on$y way to get out is to in#rement te S an% R semapores an% te in#rement #a$$ is in te pro#esses tat are &eing &$o#.e%. ii. Note) :ea%$o#.s #an &e #ause% &y many oter #on%itions1 su# as pro#esses #ompeting for resour#es1 et#. More %is#ussion on tat $ater. i. C$assi# Syn#roni(ation Pro&$ems i. ;oun%e% &uffer ! ,ere is a #ommon &uffer tat is &eing use% to store pro%u#e% items tat are to &e #onsume%. ,e semapores fun#tion to .eep it from overf$owing1 or from &eing a##esse% wen it is empty1 an% to ma.e sure tat on$y one pro#ess a##ess te &uffer at a time. 2K :e#$arations. K2 &uffer is a pie#e of memory of si(e n. mute-1 empty1 an% fu$$ are semapores. 2K "nitia$i(e varia&$es. K2 mute- M 1L 2K Provi%es mutua$ e-#$usion wen a##essing &uffer. K2 empty M nL 2K Counts te num&er of empty s$ots in te &uffer. K2 fu$$ M 0L 2K Counts te num&er of fu$$ s$ots in te &uffer. K2 94 Pro%u#erPro#ess() O repeat Z pro%u#e an itemL Z wait(empty)L wait(mute-)L Z a%% item to &ufferL Z signa$(mute-)L signa$(fu$$)L unti$(fa$se)L Q ConsumerPro#ess() O repeat wait(fu$$)L wait(mute-)L Z remove item from &ufferL Z signa$(mute-)L signa$(empty)L Z #onsume item from &ufferL Z unti$(fa$se)L Q ii. 6ea%ers2Writers Wen %ata is to &e sare% &y severa$ pro#esses1 it is o.ay for many to rea% it at on#e1 &ut on$y one pro#ess may #ange te o&>e#t at on#e. Wen te writing pro#ess is up%ating te pro#ess1 on$y it #an a##ess it1 no oter rea%ers or writers are permitte% a##ess. 2K :e#$arations. K2 mute-1 wrt are semaporesL rea%#ount is integerL 2K "nitia$i(ations. K2 mute- M 1L 2K 4nsures mutua$ e-#$usion wen rea%#ount is up%ate%. K2 wrt M 1L 2K 4nsures mutua$ e-#$usion for te writing pro#esses. K2 rea%#ount M 0L 2K ,ra#.s te num&er of pro#esses rea%ing te %ata. K2 9C WriterPro#ess() O wait(wrt)L Z 2K Writing is performe%. K2 Z signa$(wrt)L Q 6ea%erPro#ess() O wait(mute-)L rea%#ount M rea%#ount X 1L if (rea%#ount MM 1) ten wait(wrt)L 2K Prote#ts o&>e#t from &eing #ange% wi$e it is &eing rea%. K2 signa$(mute-)L Z 2K 6ea%ing is performe%. K2 Z wait(mute-)L rea%#ount M rea%#ount !1L if (rea%#ount MM 0) ten signa$(wrt)L 2K Signa$s writers tat a$$ rea%ing is #omp$ete%. K2 signa$(mute-)L Q 9= iii. :ining Pi$osopers ! ,is is a #$assi# pro&$em in wi# mu$tip$e pro#esses must #oor%inate te use of mu$tip$e resour#es. 1. :es#ription ! C pi$osopers are seate% at a roun% ta&$e. ,eir wo$e $ife revo$ves aroun% tin.ing an% eating. "n te mi%%$e of te ta&$e is a &ig &ow$ of ri#e1 te ta&$e is $ai% out wit C #opsti#.s. Wen a pi$osoper gets ungry1 tey get te two #opsti#.s #$osest to tem. 9. Simp$e so$ution is represent ea# #opsti#. wit a semapore. 2K :e#$arations. K2 semapore #opsti#.VCWL repeat wait(#opsti#.ViW)L wait(#opsti#.V(iX1)SCW)L Z eat Z signa$(#ops #opsti#.ViW)L signa$(#opsti#.V(iX1)SCW)L Z tin. Z unti$ (fa$se)L 3. ,is so$ution wi$$ en#ounter a %ea%$o#. if a$$ te pi$osopers get ungry at te same time. Some so$utions are) a. +$$ow on$y 4 pi$osopers at te ta&$e at on#e. 9E &. +$$ow a pi$osoper to pi#. #opsti#.s on$y if &ot are avai$a&$e. #. 0se an asymmetri# so$ution. O%% pi$osopers pi#. up $eft #opsti#. ten rigt1 even pi$osopers >ust te opposite. 4. So$ution must &e %ea%$o#. free1 &ut not a$$ow a pi$osoper to starve. :ea%$o#. free %oes not guarantee starvation free. >. "ntro%u#tion to Anoppi- .. +ssignment 9 ! "nsta$$ Anoppi- $. +ssignment 3 ! 6un some statisti#s on te rea%ers2writers programs B. :ea%$o#.s ! "n a mu$tiGprogramming environment tere wi$$ e-ist severa$ pro#esses an% severa$ resour#es. Wen a pro#ess re5uest a resour#e tat is not avai$a&$e te pro#ess wi$$ enter a wait state unti$ te resour#e &e#omes avai$a&$e. On#e te resour#e is a#5uire%1 te pro#ess #an #ontinue it e-e#ution trea%. "t #an appen tat a pro#ess wi$$ never $eave its wait state &e#ause te resour#es re5ueste% are e$% an% not re$ease% &y oter waiting pro#esses. ,is situation is #a$$e% a %ea%$o#.. a. 4-amp$e) We are eating stea.s. " ave a .nife1 you ave a for.. " gra& my .nife an% you gra& your for.. " won8t $et you use my .nife unti$ you give me your for.1 an% you won8t $et me use your for. unti$ " $oan you my .nife. Wat appens1 we starve $i.e i%iots. &. System Mo%e$ ! te system is a finite num&er of resour#es %istri&ute% among a num&er of #ompeting pro#esses. i. 6esour#es) severa$ types1 ea# aving some num&er of instan#es. 4-amp$es may in#$u%e memory spa#e1 CP0 #y#$es1 fi$es1 "2O %evi#es (printers1 tape %rives1 an% watnot). ii. + pro#ess re5uests a resour#e &efore using it1 uses it1 an% ten re$eases it. 1. 6e5uest) "f te re5uest #annot &e grante% imme%iate$y (some oter pro#ess is using it) te re5uesting pro#ess must wait unti$ it #an a#5uire te resour#e. 9. 0se) ,e pro#ess operates using te resour#e. 3. 6e$ease) Wen te pro#ess %oes not nee% te resour#e anymore it re$eases it. iii. System #a$$s are use% to re5uest an% re$ease resour#es. 1. 4-amp$es in#$u%e) open1 #$ose1 ma$$o#1 free1 new1 %e$eteZ. et#. #. Ne#essary Con%itions for a %ea%$o#. i. Mutua$ 4-#$usion ! at $east one resour#e is e$% in a nonGsara&$e mo%e1 tat is on$y one pro#ess at a time #an use te resour#e ! e-amp$e1 a #riti#a$ se#tion. "f anoter pro#ess re5uests tat resour#e wi$e its &eing use%1 tat pro#ess wi$$ ave to wait. ii. ?o$% an% Wait ! ,ere must e-it a pro#ess tat is o$%ing at $east one resour#e an% waiting to a#5uire oter resour#es tat are e$% &y oter pro#esses. iii. No Preemption ! 6esour#es #annot &e preempte% ($i.e te CP0 is preempte% in a ,ime Saring system)1 tey are on$y re$ease% vo$untari$y &y te pro#ess using tem. 9B iv. Cir#u$ar wait ! ,ere must &e a set of pro#esses OP01 P1Z.PnQ su# tat P0 is waiting on a resour#e e$% &y P11 P1 is waiting on a pro#ess e$% &y P9 Z..PnG1 is waiting for a resour#e e$% &y Pn1 an% Pn is waiting on a pro#ess e$% &y P0. Cir#u$ar wait imp$ies ?o$% an% Wait. %. 6esour#e +$$o#ation @raps ! a set of verti#es 31 an% e%ges 4. ,e verti#es represent pro#esses an% resour#es1 te e%ges represent re5uests an% assignments (a$$o#ations of resour#es). i. 3 #onsists of pro#esses1 P1 an% resour#es1 6. ii. 4 #onsists of %ire#te% e%ges tat go from a pro#ess to a resour#e1 in%i#ating a re5uest1 or from a resour#e to a pro#ess1 in%i#ating an assignment of te resour#e to te pro#ess (assignment)1 or tin. of it as te resour#e is a$$o#ate% to te pro#ess. iii. 4-amp$e) ,e grap is %efine% &y te sets1 P (pro#esses)1 6 (resour#es)1 an% 4 (e%ges). 1. P M OP11 P91 P3Q 9. 6 M O611 691 631 64Q 3. 4 M OP1 611 P9 631 61 P91 69 P91 69 P11 63 P3Q 4. Noti#e tat in te a&ove e-amp$e tere are no #y#$es in te grap. + resour#e a$$o#ation grap wit out #y#$es in%i#ates tat no %ea%$o#.s e-ist. 9< C. P11 P91an% P3 are %ea%$o#.e%. ,ere are two #y#$es) a. OP11 611 P91 631 P31 691 P1Q &. OP91 631 P31 691 P9Q #. ,e %ea%$o#. e-ists &e#ause no pro#ess #an re$ease a resour#e &e#ause tey #annot run &e#ause tey are waiting for resour#es e$% &y oter pro#esses. =. ?ere is a grap wit a #y#$e tat is not %ea%$o#.e%. 30 E. Cy#$e is) a. OP11 611 P31 691 P1Q B. ,ere is no %ea% $o#. &e#ause P9 or P4 #an #omp$ete pro#essing an% re$ease instan#es of 61 an% 691 a$$owing P1 an% P3 to a#5uire te resour#es nee%e% to #omp$ete. <. Meto%s for an%$ing %ea%$o#.s an% te ;an.ers a$goritm. e. +ssignment C ! So$ve te 6esour#e +$$o#ation @raps f. ?an%$ing :ea%$o#.s ! Meto%s of for %ea$ing wit te %ea%$o#. pro&$em) i. :ea%$o#. Prevention) 0se of a proto#o$ to ensure tat system never enters a %ea%$o#. state. ,is meto% tries to ensure tat at $east one of te #on%itions for %ea%$o#. #annot o##ur &y #onstraining ow resour#es re5uests are ma%e. 1. Mutua$ 4-#$usion) ,is must o$% for nonGsara&$e resour#es1 su# as printers1 &ut resour#es su# as rea%Gon$y fi$es #an &e sare%1 tus &rea.ing mutua$ e-#$usion. "n genera$ toug %ea%$o#. prevention #annot &e a##omp$ise% &y %enying mutua$ e-#$usionL some resour#es are not sara&$e. 9. ?o$% an% Wait) Pro#esses #an &e as.e% to re5uest an% a#5uire a$$ resour#es &efore tey &eginL a$$ resour#es are o&taine% &y using system #a$$s1 wi# are move% to te &eginning of te pro#ess. +$ternative$y tey #an &e for#e% to re5uest resour#es on$y wen tey ave none. Pro&$ems wit tese meto%s) 31 a. Starvation) + pro#ess may ave to wait in%efinite$y for resour#es &efore it #an start. 3. No Preemption) ,o ensure tat tis #on%ition %oes not o$%1 te fo$$owing $ogi# #an &e use%. "f a pro#ess is o$%ing resour#es an% as outstan%ing re5uests for more resour#es tat #annot &e satisfie%1 ten it #an &e for#e% to re$ease te resour#es it is o$%ing. ,e pro#ess wi$$ &e restarte% on$y wen it #an regain its o$% resour#es an% te oter ones tat it nee%e%. Or wen a pro#ess is starting1 te OS #e#.s to see if te resour#es te pro#ess nee%s are avai$a&$e. "f so tey are a$$o#ate%1 if not1 te OS #e#.s to see if te nee%e% resour#es are &eing e$% &y oter waiting pro#esses. "f so1 tese resour#es are preempte% an% te pro#ess runs1 oterwise1 te pro#ess wit its partia$ $ist of resour#es is put into te wait 5ueue1 were its resour#es #an &e preempte% &y oter pro#esses. 4. Cir#u$ar Wait) +n of resour#e types is impose% an% ea# pro#ess re5uests resour#es in an in#reasing or%er of enumeration. ii. :ea%$o#. +voi%an#e) OS is given information a&out a pro#esses re5uire% resour#es of a pro#ess %uring its $ifetime. 'or ea# resour#e re5uest1 te system must #onsi%er wi# resour#es are #urrent$y avai$a&$e1 te resour#es #urrent$y a$$o#ate% to ea# pro#ess1 an% te future re5uests an% re$eases of ea# pro#ess1 to %e#i%e if te resour#e re5uest sou$% &e satisfie% or %e$aye%. ,ese a$goritms avoi% %ea%$o#.s &y using te resour#e state information to avoi% #ir#u$ar wait #on%itions. 1. Safe State) + state is safe if te system #an a$$o#ate resour#es up to its ma-imum in some or%er an% sti$$ avoi% a %ea%$o#.. 9. ,e system is in a safe state if tere e-ists a safe se5uen#e. 3. Safe Se5uen#e) 'or ea# P(i)1 te resour#es nee%e% #an &e satisfie% &y #urrent$y avai$a&$e resour#es an% te resour#es e$% &y te pro#esses P(>) tat #ame &efore it. P(>)) > N " Se5uen#e of Pro#esses) OP11 P91 P3Z..PnQ +$$ te resour#es Pi wi$$ nee% are avai$a&$e (not a$$o#ate% to any pro#ess) or are e$% &y P1 to P(iG1). 39 ;an.ers +$goritm ! n ! num&er of Pro#esses m ! num&er of resour#e types +vai$ViW ! num&er of resour#es of type i avai$a&$e Ma-Vi1 >W ! ma- [ of resour#es of type > tat pro#ess i wi$$ nee% +$$o#Vi1>W ! pro#ess i as tis man resour#es of type > Nee%Vi1 >W M ma-V"1 >W ! a$$o#Vi1 >WL Wor. M +vai$ 'inisViW M '+7S4L Wi$e tere e-ist i su# tat) 'inisViW M '+7S4 Nee%ViW NM Wor. O Wor. M Wor. X +$$o#L 'inisViW M ,604L Q "f a$$ of 'inis M ,6041 ten system is in a safe state. (4nter my e-amp$e ere) iii. System is a$$owe% to enter a %ea%$o#. state an% re#over. +n a$goritm monitors system state to %etermine if a %ea%$o#. as o##urre%1 an% uses a %ea%$o#. re#overy a$goritm wen one is %ete#te%. iv. "gnore te pro&$em a$$ togeter. @ive te responsi&i$ity for an%$ing %ea%$o#.s to te users. Many systems1 in#$u%ing 0N"F ave use% tis strategy. "n some systems %ea%$o#.s o##ur infre5uent$y (may&e on#e a year). Wen tis is te #ase1 it may ma.e more e#onomi# sense to ignore te pro&$em. <. Rui( 9 6eview (Wee. B) 10. Rui( 9 11. Memory Management ! Main memory is a $arge array of &ytes1 ea# wit its own a%%ress. a. Memory &asi#s i. One unit ($i.e a swit#) ;it (021) ii. Ni&&$e ! 4 &its iii. ;yte ! B &its 33 iv. Wor% ! B1 1=1 391 =4 &its v. Memory a%%ressing G ,e sma$$est pie#e of spa#e tat a CP0 #an usua$$y a%%ress is a &yte. + wor% is 4 &ytes1 some CP0s a%%ress on wor% or a$f wor% &oun%aries. +##ess to an% from memory is an%$e% &y te memory unit (memory #ontro$$er). 1. &yte a%%ressa&$e ! a$$ &ytes are a%%ressa&$e 9. wor% a%%ressa&$e ! #an on$y a%%ress on wor% &oun%aries 3. &us error ! attempt to a##ess memory on in#orre#t &oun%ary. a. ?ow %o we get aroun% tisT We use mas.ing an% sifting. &. ;in%ing ! a mapping from one a%%ress spa#e to anoter. #. Pro#ess of &in%ing) %. 7in.ing types) i. Stati# ! $i&rary routines in#$u%e% in #o%e. ii. :ynami# ! $i&raries $in.e% in at runtime. ,e :77 is $o#ate% &y $oo.ing at a stu& inserte% at #ompi$e time. Saves memory1 &ut more #omp$e-1 ta.es $onger to #ome up initia$$y1 an% is not as porta&$e. e. +%%ress types) i. Sym&o$i# ! a%%ress in a program1 $i.e a varia&$e name (CO0N,) 34 ii. 6e$o#ata&$e ! ,ese a%%ress are #a$#u$ate% from a referen#e point1 $i.e te &eginning of te program. ,e #ompi$er wi$$ generate tese at #ompi$e time. 1. offset ! is position of a%%ress #a$#u$ate% from program start. 9. Pysi#a$ +%%ress M Program Start a%%ress X offset. iii. +&so$ute (unre$o#ata&$e) ! ,ese are pysi#a$ a%%resses of te ma#ines main memory. iv. Position in%epen%ent ! runs anywere. 3aria&$es use re$ative $o#ations1 re$ative to PC. ;ase an% 7imit meto%. f. +%%ress ;in%ing i. Compi$e time ! 0sua$$y te #ompi$er turns sym&o$i# a%%resses into re$o#ata&$e a%%resses1 &ut if it is .nown aea% of time were a pro#ess as to resi%e in memory1 pysi#a$ a%%ress #an &e generate%. +&so$ute #o%e is generate%. ii. 7oa% time ! "f at #ompi$e time it is not .nown were te pro#ess wi$$ pysi#a$$y resi%e in memory te #ompi$er generates re$o#ata&$e #o%e. ,e $oa%er #onverts tis to a&so$ute a%%resses wen te program is $oa%e% into pysi#a$ memory. iii. 4-e#ution time ! Wen pro#esses are move% aroun% %uring teir e-e#ution1 fina$ &in%ing is save% for wen tey run. ,is &in%ing is %one &y te memory management unit (MM0) g. :ynami# 7oa%ing ! "n some #ases (many in fa#t) te entire program may not fit in pysi#a$ memory. "f noting is %one a&out tis1 pro#ess si(es are $imite% to te si(e of memory. + wor. aroun% tis is :ynami# 7oa%ing. i. "n tis te#ni5ue1 routines are .ept on %is. in re$o#ata&$e format. ii. Program starts1 main routine is in memory. Wen a su& routine is #a$$e%1 te #a$$ing routine #e#.s for its presen#e in memory1 if tere it #ontro$ transfers to it1 oterwise1 te re$o#ata&$e $in.ing $oa%er is #a$$e% an% te routine is $oa%e% from %is.. iii. @oo% wen program #ontains $arge amounts of #o%e tat are rare$y #a$$e%. iv. :oes not re5uire support from OS. Programmers responsi&i$ity to %esign program to use s#eme. OS provi%es $i&rary routines in support of %ynami# $oa%ing sometimes. . :ynami# 7in.e% 7i&raries ! Wi%e$y supporte%. 7in.ing of system $i&raries is postpone% unti$ run time. + stu& is in#$u%e% in te &inary image tat in%i#ates ow to $o#ate or $oa% te appropriate routine if te routines is not a$rea%y present. i. 0n%er tis s#eme a$$ pro#esses tat use te :77s e-e#ute on$y one #opy of te #o%e. ii. +%vantages in#$u%e) 1. Co%e savings. 9. 4asier to imp$ement up%ates an% &ug fi-es trougout te system. (saves reG$in.ing of a$$ programs using new $i&raries. iii. 0sua$$y re5uires OS support. 3C i. Over$ays ! + programmer imp$emente% te#ni5ue of e-e#uting #o%e tat is &igger tan te pysi#a$ memory. "n tis meto% te programmer %ivi%es te #o%e into se#tions tat wi$$ fit into memory. Wen te program as to swit# #o%e se#tions an Over$ay %river swaps in te nee%e% part of te #o%e an% restarts te program. >. 4-amp$e) 9 pass assem&$er tat re5uires 900. memory. "f on$y 1C0 . is avai$a&$e1 te over$ays #an &e %esigne% wit te fo$$owing memory re5uirements. Pass 1 ! E0. Pass 9 ! B0. Sym&o$ ta&$e ! 90. Common routines ! 30. Over$ay %river ! 10. Pass 1 wit nee%e% routines M E0. X 90. X 30. M 190. wit over$ay %river ! 130. Pass 9 wit nee%e% routines M B0. X 90. X 30. M 130. wit over$ay %river ! 140. So te assem&$er #an &e run wit 1C0. of memory. ,is s#eme %oes not re5uire spe#ia$ OS support &ut %oes re5uire te programmer to ave a goo% .now$e%ge of te program stru#ture. .. 7ogi#a$ versus Pysi#a$ +%%ress Spa#e ! CP0 generates a $ogi#a$ a%%ress (sometimes #a$$e% a virtua$ a%%ress)1 memory management unit MM0 turns te $ogi#a$ a%%ress into a pysi#a$ a%%ress an% $oa%s it into te M+6 (memory a%%ress register). i. ,e set of a$$ a%%resses generate% &y a program is #a$$e% te $ogi#a$ a%%ress spa#e. ,e ar%ware memory a%%resses #orrespon%ing to tese a%%resses are referre% to as pysi#a$ a%%ress spa#e. ii. Compi$e time &in%ing an% $oa% time &in%ing resu$t in $ogi#a$ a%%resses tat are te same as pysi#a$ a%%resses. iii. 4-e#ution time &in%ing ! $ogi#a$ an% pysi#a$ a%%resses are %ifferent from one anoter. iv. +%%ress trans$ation an%$e% &y te MM0. 1. Pysi#a$ +%%ress M 7ogi#a$ X &ase register (sometimes #a$$e% re$o#ation register) 9. ,e program on$y wor.s wit $ogi#a$ a%%resses (0 to program ma- a%%ress). ,ey are mappe% to 6 X ma- program a%%ress in pysi#a$ memory1 were 6 is te va$ue for te &ase register. 3. 7ogi#a$ to Pysi#a$ a%%ress mapping is te #entra$ #on#ept in memory management. v. 0ser Mo%e ! a##esses virtua$ a%%ress spa#e vi. Supervisor Mo%e ! a##esses pysi#a$ a%%ress spa#e 3= $. Swapping ! Pro#ess are memory resi%ent wen tey are running. "f tere are more pro#esses tan te memory #an o$%1 ten te OS swaps tem in an% out of memory from %is. so tey #an run. i. Wit a%%ress &in%ing is %one at #ompi$e or $oa% time1 te pro#ess must resi%e at a spe#ifi# p$a#e in pysi#a$ memory to run1 an% must &e swappe% &a#. an% fort from %is. to tat p$a#e. ii. ,is re5uirement is re$a-e% wit e-e#ution time &in%ing. iii. Pro#esses tat are swappe% out are tra#.e% &y te OS. iv. Swapping ta.es time. ,e time is proportiona$ to te amount of %ata tat must &e move% from %is. to memory. 4-amp$e) 1. a 100. pro#ess at 1000. per se#on% wit a B ms %is. $aten#y wou$% ta.e) a. 100.21000. X B ms M 10Bms. &. ,o swap watever was in memory out an% tis pro#ess &a#. in wou$% ta.e) 9 K 10Bms M 91=ms. v. 'or effi#ien#y reasons time in memory an% running sou$% &e $ong #ompare% to te time to swap te pro#ess from %is. to memory. m. Contiguous +$$o#ation ! Main memory a##ommo%ates te OS an% te user pro#esses. OS resi%es in one partition1 user pro#ess in te oter. OS is #ommon$y p$a#e% in $ow memory (a%%ress num&ers starting at 0) &e#ause interrupt ve#tors is often in $ow memory. +%vantages) Simp$e1 'ast. :isa%vantages) 'ragments memory1 tere may &e programs too &ig for memory. i. Sing$e Partition ! OS resi%es in $ow memory. 0ser pro#esses resi%e in ig memory. 1. Pro#esses an% OS are prote#te% from ea# oter &y using te &ase an% $imit register s#eme. 9. 4very a%%ress te CP0 generates is #e#.e% against tese registers. ?ar%ware is use% so it #an &e %one 5ui#.$y. 3. "t provi%es OS an% user programs prote#tion from running pro#esses. 3E ii. Mu$tip$e Partition ! "n te most &asi# #ase of mu$tip$e partition memory management memory is %ivi%e% into n e5ua$ si(e partitions (";M 3=0 use% tis s#eme). ,e num&er of partitions in te memory %etermines te %egree of mu$tiprogramming. Wen a partition is free1 te OS se$e#ts a pro#ess from te input 5ueue an% $oa%s into tat partition. iii. 7ater1 te e5ua$ num&er of partitions was %roppe% for a %ynami# system in wi# memory is .ept tra#. of &y using a ta&$e tat te$$s wi# part of memory is empty an% wi# is o##upie%. 1. "nitia$$y a$$ pro#ess memory is empty. 9. +s pro#esses are s#e%u$e%1 tey are move% into *o$es/ (areas of uno##upie% memory). ,e OS fin%s a o$e $arge enoug to o$% te pro#ess. Memory is a$$o#ate% unti$ tere is no o$e $arge enoug to o$% te ne-t pro#ess. ,e OS ten must wait unti$ a pro#ess #omp$etes an% frees its memory or s.ip %own te input 5ueue unti$ it fin%s a pro#ess sma$$ enoug to fit in one of te o$es. +%>a#ent o$es #an &e merge% to form $arger o$es. ,ere are severa$ a$$o#ation s#emes) a. 'irstG'it ! Put te pro#ess in te first o$e foun% tat wi$$ a##ommo%ate its memory re5uirements. Sear#ing stops as soon as a wo$e is foun% tat wor.s. 3B &. ;estG'it ! Put te pro#ess in to te sma$$est o$e tat wi$$ a##ommo%ate its memory re5uirements. ,is strategy pro%u#es te sma$$est remaining o$e2o$es. #. WorstG'it ! Put te pro#ess in to te $argest o$e tat wi$$ a##ommo%ate its memory re5uirements. ,is strategy pro%u#es te $argest remaining o$e2o$es. 3. Simu$ations sow tat firstGfit an% &estGfit wor. &est in terms of %e#reasing time an% storage uti$i(ation. Neiter is #$ear$y &etter1 &ut firstGfit is genera$$y faster. iv. "nterna$ an% 4-terna$ 'ragmentation 1. 4-terna$ 'ragmentation is wen te sum of te memory of te o$es is enoug to satisfy a memory re5uest &ut it not #ontiguous1 it is fragmente% into a $arge num&er of sma$$ o$es. ,o so$ve tis pro&$em (#an waste up to a tir% of te memory) #ompa#tion #an &e use%. Perio%i#a$$y suff$e te memory an% #reate a &ig &$o#. of free memory. 9. "nterna$ 'ragmentation ! Sometimes a o$e may &e &are$y $arger tan te pro#ess it is a$$o#ate% to. "n or%er to avoi% te overea% of tra#.ing very sma$$ o$es (te memory re5uire% to tra#. te tiny o$e wou$% &e more tan te o$e itse$f) more memory tan is re5uire% wou$% &e a$$o#ate% so tat te tra#.ing pro&$em #an &e $essene% (a$$o#ate te tiny o$e as part of te $arger re5uest). ,e memory tat is te %ifferen#e &etween te o$e si(e an% pro#ess si(e is interna$ fragmentation. 19. Paging an% 3irtua$ Memory ! 0se% to avoi% fragmentation. a. ;asi#s ! 4a# pro#ess as a page ta&$e. PageNum M $ogi#a$ a%%ress2pageSi(eL 'rameNum M page,a&$eVpageNumW.page Offset M $ogi#a$ a%%ress ! pageNumKpageSi(e Pysi#a$ +%%ress M 'rameNum K 'rameSi(e X Offset
3< Page si(es are usua$$y .ept to &e a power of 91 typi#a$$y &etween C19 &ytes an% 1= megs. ,is ma.es page an% offset #a$#u$ation a matter of sifting &its. 40 41 Paging attri&utes) 'orm of %ynami# re$o#ation. 7ogi#a$ a%%resses &oun% &y paging ar%ware to pysi#a$ a%%resses. No e-terna$ fragmentation. +ny free frame #an &e a$$o#ate% to any pro#ess tat nee%s it. Wi$$ ave interna$ fragmentation on $ast frame of pro#ess. Page si(e is a #ompromise &etween wanting to minimi(e interna$ page fragmentation an% minimi(ing te num&er of %is. a##esses1 an% te overea% re5uire% to store te paging ta&$es. Narrative of Paging Pro#ess ) Pro#ess arrives in system o "ts si(e is e-presse% in pages. o "f it re5uires n pages1 tere must &e n frames avai$a&$e in memory. "f te frames are avai$a&$e1 tey are a$$o#ate% to te pro#ess1 ea# frame $o#ation &eing re#or%e% in te pro#esses page ta&$e. 0ser program views memory as one #ontiguous pie#e even toug it is pysi#a$$y s#attere% trougout memory. +s program runs $ogi#a$ a%%resses are #onverte% to pysi#a$ a%%resses. 49 OS .eeps tra#. of wi# frames are use% an% wi# are avai$a&$e in te 'rame ta&$e. "ssues wit Paging) ,o a##ess a &yte of memory it ta.es 9 memory a##esses1 one for te page ta&$e1 one for te a##ess to memory. o ,rans$ation $oo.Gasi%e &uffers (,7;) are use% to a$$eviate tis pro&$em. ,7; is a sma$$ fast pie#e of asso#iative memory tat o$%s part of te page ta&$e in it. 7ogi#a$ a%%ress generate% &y CP01 page num&er presente% to ,7;. "f te page num&er is foun%1 ,7; outputs te mat#ing frame num&er. Pro#ess ta.es 10S $onger tan a %ire#t memory referen#e. "f page num&er not in ,7;1 page ta&$e is referen#e% an% a%%ress is forme%. ,7; up%ate%1 if fu$$ one of te entries is rep$a#e%. ,e per#ent of times tat a page num&er is foun% in ta&$e is te it ratio. 0sing te it ratio we #an #a$#u$ate te effe#tive memory a##ess time. B0 per#ent it ratio 90 nanose#on% ,7; sear# time 100 nanose#on% memory a##ess time. 4ffe#tive a##ess time M .B0 #+, - .,,& - /+,(90 X 100 X 100) M 140 nanose#on%s o Wen memory is fu$$ (page ta&$e fu$$) pages must &e swappe% in an% out from %is.. 13. Paging imp$ementation an% a$goritms a. 7o#a$ity of referen#e ! programs ten% to wor. in a parti#u$ar memory area an% move s$ow$y troug tem. &. :eman% Paging ! pages are on$y &rougt in wen tey are nee%e%. #. Page 'au$t ! event tat o##urs wen a page is not in 6+M %. :irty ;it ! in%i#ates if te page as &een #ange% sin#e it #ame into memory. "f it as1 wen it is e>e#te%1 it nee%s to &e written &a#. to %is. &efore it is .i#.e% out. e. Page 6ep$a#ement f. Page 6ep$a#ement +$goritms i. '"'O ! 'irst "n 'irst Out 1. ;e$a%y8s anoma$y ! give a system more resour#es (memory frames) an% it ma.es more fau$ts. '"'O is sus#epti&$e1 760 is not. ii. Optima$ (;e$a%y) ! fartest in te future. ,is is goo%1 &ut we ave a ar% time .nowing wat te future wi$$ &ring. iii. 760 ! 7east 6e#ent$y 0se%. @oo% in teory an% in pra#ti#e. (:irty &it set wen page #ange%1 ea# time page a##esse%1 time stamp 43 up%ate% or referen#e &it set. "f using referen#e &it1 ea# time 5uanta sifts referen#e wor% to te rigt. g. 4-amp$e of '"'O1 7601 an% optima$L page2frame si(e M 100L ma-frames M C e$$o tv $an%U num+%%s M 90 +%%ress Stream. E91 43 191 999 44 39E 4C 49B 993 39B 4C 39< 994 199 99C 4= 193 E99 4E 194 Page rep$a#ement ('"'O) 'rame ,a&$e G E [ [ [ [ 'rame ,a&$e G E 0 [ [ [ 'rame ,a&$e G E 0 1 [ [ 'rame ,a&$e G E 0 1 9 [ 'rame ,a&$e G E 0 1 9 [ 'rame ,a&$e G E 0 1 9 3 'rame ,a&$e G E 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 YYY page fau$t 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 E 1 9 3 YYY page fau$t 44 'rame ,a&$e G 4 E 0 9 3 YYY page fau$t 'rame ,a&$e G 4 E 0 1 3 YYY page fau$t page'au$ts M 4 Page rep$a#ement (760) 'rame ,a&$e G E [ [ [ [ 'rame ,a&$e G E 0 [ [ [ 'rame ,a&$e G E 0 1 [ [ 'rame ,a&$e G E 0 1 9 [ 'rame ,a&$e G E 0 1 9 [ 'rame ,a&$e G E 0 1 9 3 'rame ,a&$e G E 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 YYY page fau$t 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G 4 0 1 9 3 'rame ,a&$e G E 0 1 9 3 YYY page fau$t 'rame ,a&$e G E 0 1 9 3 'rame ,a&$e G E 0 1 9 3 page'au$ts M 9 ?ere is an optima$ (;e$a%y) e-amp$e. E [ [ [ [ E 0 [ [ [ E 0 1 [ [ E 0 1 9 [ E 0 1 9 [ E 0 1 9 3 E 0 1 9 3 4 0 1 9 3 YYY page fau$t . / / / / / / / / 4C E 0 1 9 3 YYY page fau$t E 0 1 9 3 E 0 1 9 3 . ;e$a%y8s anoma$y ! sometimes wit '"'O1 aving more resour#es resu$ts in more page fau$ts. i. Page referen#e string ! 11 91 31 41 11 91 C1 11 91 31 41 C 1. '"'O ! wit 4 frames resu$ts in 10 page fau$ts 1 9 3 4 1 9 C 1 9 3 4 C 1 1 1 1 C C C C 4 4 9 9 9 9 1 1 1 1 C 3 3 3 3 9 9 9 9 4 4 4 4 3 3 3 9. '"'O ! wit 3 frames resu$ts in < page fau$ts. 1 9 3 4 1 9 C 1 9 3 4 C 1 1 1 4 4 4 C C C 9 9 9 1 1 1 3 3 3 3 3 9 9 9 4 i. Counting a$goritms i. 7'0 ! 7east fre5uent$y use%. ii. M'0 ! Most fre5uenty use%. 14. +ssignment C ! Program a page swapper1 imp$ement '"'O an% 7601 sow some run statisti#s for various provi%e% %ata sets. (:ue in 9 wee.s) 1C. Pure :eman% Paging ! initia$$y a$$ pages on &a#.ing store (fast %is. or fast part of %is.). On initia$ startup1 or restarting after a #onte-t swit#1 many page fau$ts o##ur. 1=. :eman% Paging wit preGpaging ! #ompi$er te$$s system wi# pages are nee%e% for startup. +fter startup pages use% #an &e swappe%. ,is meto% e$ps to re%u#e te amount of page fau$ts on startup. 1E. ,rasing ! Wen a pro#ess #annot &e a$$o#ate% te minimum num&er of pages it nee%s to run it #an generate many page fau$ts. +t some point te OS is spen%ing most of te CP0 #y#$es servi#ing page fau$ts1 instea% of e-e#uting user pro#esses. 1B. Storage a. 'i$es Systems ! + fi$e is a #o$$e#tion of re$ate% %ata items (program1 te-t1 imageZ.) &. ,wo ways of %e#i%ing wat is in a fi$e) i. 0ser #onvention (K.o$% in 0ni- is usua$$y an o$% version of a fi$e1 wi$e K.#o$% wou$% usua$$y &e an o$% C sour#e #o%e fi$e. ) ii. OS %efine% (K.%o# in win%ows is a wor% fi$e) #. +##ess Meto%s) i. Se5uentia$ 4= ii. "n%e-e% ! Consists of an in%e- fi$e an% a %ata fi$e %. +ttri&utes i. name ii. type iii. $o#ation (on %is.) iv. si(e (num&er of re#or%s1 or &ytes) v. prote#tion info vi. owner vii. $ast mo%ifie% e. Operations i. #reation ii. trun#ate iii. %e$ete iv. open v. #$ose vi. appen% vii. rea% viii. write i-. see. -. te$$ f. :ire#tory ! #o$$e#tion of fi$es. "n :OS $in.s #an on$y go to $eaves. ,is .eeps #y#$es from o##urring. i. ,ree Stru#ture% ! a#y#$i# graps ii. + fi$e is %e$ete% on$y wen tere are no more $in.s to it. + fi$e may &e referen#e% from more tan one %ire#tory. g. Patnames i. +&so$ute ! &a#. to root ii. 6e$ative ! re$ative to #urrent wor.ing %ire#tory . Prote#tion i. +gainst oter users ii. +gainst se$f iii. Contro$ 1. wat ! rea%2write2e-e#ute1 appen%2%e$ete2$ist 9. wo ! you1 your group1 everyone 1<. 'i$e System "mp$ementation a. 'i$e Contro$ ;$o#. ! 'C;) :ire#tory ;$o#.1 %ata &. 'i$e System ! Consists of a$$ fi$es ('C;1 %ata)1 ar%ware1 %ire#tories1 format information (&$o#. si(e1 free &$o#.s) i. ;$o#.s ! ea# &$o#. as pysi#a$ a%%ress (tra#.1 se#tor) ii. :is. is a&stra#te% to an array of &$o#.s (B. ! 1=.) 1. ,o get %ata from %is. ! move ea% (see. time)1 wait for p$atter to spin aroun% to rigt p$a#e (rotationa$ $aten#y). 9. ,o rea%2write 5ui#.$y ! group &$o#.s of fi$e #$ose to ea# oter. We wou$% $i.e to a$$o#ate #ontiguous$y in ar%ware an% software. #. Meto%s of +$$o#ation 4E i. Contiguous ! suffers from e-terna$ fragmentation ii. 7in.e% a$$o#ation 1. 4$iminates e-terna$ fragmentation 9. 7ea%s to nonG#ontiguous fi$e %ata %istri&ution 3. On$y goo% for se5uentia$ a##esse% fi$es. 4. 7ost fi$e pointers #an #ause a fi$e to &e %amage%. C. :ire#tory wi$$ store) a. Name &. first &$o#. #. $ast &$o#. %. 4a# &$o#. as a pointer to te ne-t &$o#.. iii. '+, ('i$e +ttri&ute ,a&$e) 1. Simp$e an% effi#ient 9. 7in.e% a$$o#ation meto%. 3. "f '+, is not #a#e%1 it #an $ea% to $ots of %is. see.s. 4. '+, ! a. '+, at &eginning of ea# %is. partition. &. "t as one entry for ea# %is. &$o#. an% is in%e-e% &y num&er. #. ,e %ire#tory entry as entry for first fi$e &$o#.1 '+, as entry for te ne-t &$o#.. %. ,e $ast &$o#. in fi$e is signa$e% &y 4O' va$ue. e. 4mpty &$o#.s mar.e% &y 08s. f. "f '+, ta&$e gets wipe% out1 $oo. out. iv. "n%e-e% 1. :ire#tory as fi$e name an% $o#ation in%e- &$o#.. "n%e- &$o#. is a se5uentia$ $ist of te &$o#.s in te fi$e. v. 'ree Spa#e ! $in.e% into on fi$e. ;it 3e#tor (1 per &$o#. in%i#ates if te &$o#. is free or not. vi. :ire#tories ! simp$est way is to ma.e $inear ta&$e1 some systems use a as ta&$e. 90. "2O Systems a. 7ots of OS %ea$s wit fi$es (E0S) i. ?ar%ware %evi#es) 1. po$$ing 9. interrupt 3. interrupt wit :M+ ii. :evi#e types 1. ;$o#. a. :is. &. ,ape 9. Cara#ter a. Aey&oar% &. Seria$ i2o (COMM port) &. :is.s i. Stru#ture 4B ii. ?ea% S#e%u$ing 1. 'C'S ! 'irst Come 'irst Serve 9. SS,' ! Sortest See. ,ime 'irst 3. SC+N ! (e$evator a$goritm) ! serve a$$ re5uests going one way1 ten go te oter. a. Cy#$i# e$evator ! goes one %ire#tion1 ten ea% moves &a#. to start. 91. Rui( 3 review 99. Rui( 3 4<