高级操作系统全chapter4支持2016ados_第1页
高级操作系统全chapter4支持2016ados_第2页
高级操作系统全chapter4支持2016ados_第3页
高级操作系统全chapter4支持2016ados_第4页
高级操作系统全chapter4支持2016ados_第5页
已阅读5页,还剩149页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

AdvancedOperatingDistributedSystemsConceptsanddesignQingZhu,DepartmentofComputerRenminChapterOperatingSystem Teacher:QingInformationSchool,2DistributedSystems–ConceptsandDesign,GeorgeCouloris,andTim

nEdition3,4,©PearsonEducation2001,2005ThelectureisbasedonthisChapterChapter44.74.84 5Virtualmachine NetworkoperatingsystemBothUNIXandWindowsareexamplesofnetworkoperatingsystems.Thedefiningcharacteristicisthatthenodesrunninganetworkoperatingsystemretainautonomy(自治)inmanagingtheirownprocessingresources.Inotherwords,therearemultiplesystemimages,onepernode.7DistributedoperatingsystemOnecouldenvisage(正视)anoperatingsysteminwhichusersareneverconcernedwithwheretheirprogramsrunorthelocationofanyresources.ThereisasinglesystemAnoperatingsystemthatproducesasinglesystemimagelikethisforalltheresourcesinadistributedsystemiscalledadistributedoperatingsystem.8Distributedoperatingsystem 9 9ChapterChapter44.74.8Figure6.1Systemlayers操作系统层libraries&

communication,...communication,...Computer&Computer& Kernelsandserverprocessesarerequiredatleast Concurrentprocessing并发处理:客户应该可以共享 Communication通信:资源管理器在网络上或计算机Figure CoreOSfunctionality操作系统内核功 CoreO/SProcessmanagementincludescreating,managinganddestroyingprocesses.EveryprocesshasanaddressspaceandoneormoreThreadmanagementincludescreating,synchronizingCommunicationsmanagementincludesallcommunicationsbetweenthreadsinthesamecomputerandmayincluderemote MemorymanagementincludescontrolofphysicalandTheO/SSupervisorTheSupervisor:dispatchesinterrupts,systemcalltrapsandexceptions,thecontrolofmemorymanagementunitandhardwarecaches,andmanipulationoftheprocessorandfloatingpointChapterChapter44.74.8ProtectionAllresourcesmustbeprotectedfromNotethatthethreattoasystem’sintegritydoesnotcomeonlyfrommaliciouslycontrivedcode.Benigncodethatcontainsabugorwhichhasunanticipatedbehaviormaycausepartoftherestofthesystemtobehaveincorrectly.对系统完整性的 Protectionmightalsopreventthebypassingofrequiredactivitiessuchasloginauthenticationandauthorization.保护也考 KernelsandMostprocessorshaveahardwaremoderegisterthatpermitsprivilegedinstructionstobestrictlycontrolled.Generally,thereisasupervisormodeforprivilegedinstructionsandausermodeforunprivilegedinstructions. Separateaddressspacesareallocated,andonlytheprivilegedkernelcanaccesstheprivilegedspaces.Usuallyasystemcalltrapisrequiredtoaccessprivilegedinstructionsfromuserspace.地址空间被分开,只有 ProtectionProtectioncomesataprice,includingtheprocessorcyclestoswitchbetweenaddressspaces,thesupervisionandprotectionofsystemcalltraps,andtheestablishment,authenticationandauthorizationofprivilegedusersand Sincealloverheadconsumesexpensiveresources,itisalwaysakeyconcernofITmanagers.ChapterChapter41用进程(任务)作为资源所有权单位(theunitofresourceownership),量级进程)作为调度/执行/分派单位(theunitof共份资源

Linux、MacOSX、iOS 空间(用来局部变量和调用参数) 2内核级线程(Kernel-levelThreads> 实例:GNUPortablefrom用户级线程(UserLevel 线 实例:Windows、Linux、MacOS

WindowsNT、MacOSX、iOS3. 至强E5645CPU处理器、2 至强E5620CPU处理器、9个448核的NVIDIATeslaC2050GPU运算卡beexecutedsequentiallySpeedup=timetorunonsingleprocessor (1–f)+f/ofMultipleCoresFigure4.7 Figure4.7DatabaseWorkloadsonMultiple-ProcessorHardwareFigure4.8ScalingofDatabaseWorkloadsonMultipleProcessorChapterChapter44.74.8AtypicalprocessincludesanexecutionenvironmentandoneormoreAnexecutionenvironmentincludesanaddressthreadsynchronizationandcommunicationresourcessuchassemaphoresandcommunicationinterfacessuchassockets,andhigherlevelresourcessuchasopenfilesandSinceearlierprocessesmayhaveallowedonlyasinglethread,thetermmulti-threadedprocessisoftenusedforclarity.Figure6.3Addressspace地址空间0AddressAsshownonthepreviousdiagram,anaddressspaceisamanagementunitforthevirtualmemoryofaprocess.Itconsistsof regionsaccessiblebythethreadsoftheowning地址空间是进程虚存管理单元。是一个可以被进程的线程 Eachregionhasanextent(lowestvirtualaddressandsize),read/write/executepermissionsfortheprocessesthreadsandwhetheritgrowsupordown.每个区域包含如下性质:Itispageoriented,andgapsareleftbetweenregionstoallowforUnixAddressAddressspacesareageneralizationoftheUnixmodel,whichhadthreeAfixed,unmodifiabletextregioncontainingprogramAheap,extensibletowardhighervirtualAstack,extensibletowardlowervirtualAnindefinitenumberofadditionalregionshavesincebeenUNIXStackGenerallythereisaseparatestackforeachthread.Wheneverathreadorprocessisinterrupted,statusinformationisstoredonthestackthatwillpermittheprocessorthreadtocontinuefromthepointatwhichitwasinterrupted. 在栈中。容许进程或线程从这个断点继续执行。Usually,memoryallocatedtothestackisrecoveredwhentheprocessorthreadretrievestheinformationandresumes,asinterruptsoccurandresumeinalast-in,firstout(LIFO)manner.FileRegionsAfilestoredofflinecanbeloadedintoactivememory.Amappedfileisaccessedasanarrayofbytesinmemory.Suchafilecanreduceaccessoverheaddramatically,asitisordersofmagnitudefastertoaccessmemorythandiskfiles.映射文件:是一个在内存中可 SharedMemoryRegionsSometimesitisdesirabletosharememorybetweenprocesses,orbetweenaprocessandthekernel.Reasonsforsharingmemoryinclude:Librariesthatmightbelargeandwouldwasmemoryifeachprocessloadedacopy Kernelcallsthataccesssystemcallsand内核 DatasharingandcommunicationbetweenprocessesonsharedAnoperatingsystemcreatesprocessesatneed. adistributedenvironment,therearetwoindependentaspectsofthecreationprocess:ChoiceofatargetCreationofanexecutionenvironmentandaninitialthreadwithinitChoosingHostforProcessAtransfer decideswhethertosituatetheprocesslocallyor Alocation determineswhichnodeshouldhostthenewprocess.Locationpoliciesmaybestaticoradaptive.Staticpoliciesignorethecurrentstateofthesystemandaredesignedbasedontheexpectedlong-termcharacteristicsofthesystem.DynamicLocationPoliciesLoadsharingpoliciesusealoadmangertoallocateprocessestohosts.Sender-initiatedpoliciesrequirethenodecreatingtheprocesstospecifythehost.Migratorypoliciescanshiftprocessesbetweenhostsatanytime.Onceahostisselected,anewprocessrequiresanaddressspacewithinitializedcontentsanddefaultinformationsuchasfiles.Thenewaddressspacecanbedefinedstatically,orcopiedfromanexistingexecutionenvironment.一旦选择了主机,新进程需要一个包含地址空间和初始化信息Ifcopied,contentmaybesharedandnothingwrittentothenewenvironmentuntilsuchtimeasawriteinstructionoccursforeitherprocess.Thenthesharedcontentisdivided.Thistechniqueiscalledcopy-on-write(nextslide). Figure6.4 fromRA

a)Before b)AfterAsingleprocesscanhavemorethanoneactivitythreadsatthesametime.Forexample,itmaybeperforminganactivitywhileatthesametimeneedingtobeawareofbackgroundevents.Theremayalsobebackgroundactivitiessuchasloadinginformationintoabufferfromasocketorfile.Serversmayservicemanyrequestsfromdifferentusersatthesame一个进程可以同时有一个或多个线程。例如,同时执行一个背景活动,如,从socket或文件传送信息到器。在同时,服FigureandserverwithThread1

Thread2makesrequeststoserver

Receipt&

Input-NWorkerPoolArchitecture—apredeterminedfixednumberofthreadsisavailableforuseasneededandreturnedtothepoolafteruse.Thread-per-requestArchitecture—anewthreadisallocatedeachnewrequest,anddiscardedafterThread-per-connectionArchitecture—anewthreadisallocatedforeachnewconnection.Severalrequestscanusethatthreadsequentially.ThethreadisdiscardedwhentheconnectionisThread-per-objectArchitecture—anewthreadisallocatedforeachremoteobject.Allrequestsforthatobjectwaittousethatthread.Thethreadisdiscardedwhentheconnectiontotheobjectisdestroyed.对象线程体系结构:为每个 FigureAlternativeserverthreadingarchitectures(seealsoFigure

Whatisa ItisaprogramspathofMostprogramsrunasasinglethread,whichcouldcauseproblemsifaprogramneedsmultipleeventsoractionstooccuratthesametime.需要多或动作同时发生,就会产生问题。TheJavaVirtualMachineallowsanapplicationtohavemultiplethreadsrunningconcurrently.Whatisathread(cont.)Multi-threadingli llymeansmultiplelinesofasingleprogramcanbeexecutedatthesametime.However,itisdifferentfrommulti-processingbecauseallofthethreadssharethesameaddressspaceforbothcodeanddata,causingittobelessoverhead.So,bystartingathreadanefficientpathofexecutioniscreatedwhilestillsharingtheoriginaldataareafromtheFigureStateassociatedwithexecutionenvironmentsandExecution AddressspacetablesCommunicationinterfaces,openfilesSemaphores,othersynchronization

SavedprocessorPriorityandexecutionstate(suchSoftwareinterrupthandlingListofthread Executionenvironment Pagesofaddressspaceresidentinmemory;hardwarecache ThreadstatesRunningState:Athreadissaidtobeintherunningstatewhenitisbeingexecuted.ReadyState(NotRunnable):Athreadinthisstateisreadyforexecution,butisnotcurrentlyexecuted.OnceathreadgetsaccesstotheCPU,itgetsmovedtotheRunningstate. ThreadstatesDeadState:Athreadreachesthe“dead”statewhentherunmethodhasfinishedexecution.WaitingState(yielding):Inthisstatethethreadiswaitingforsomeactiontohappen.Oncethatactionhappens,thethreadgetsintothereadystate.Threadsinthewaitingstatecouldbe ,suspended,blocked,orwaitingfora等待态:在这个状态线程等待的发生。一旦时间发生,线程转成就绪态。等待态的线程可以睡眠、挂起、阻塞或等UsagesofThreadsThreadsareusedforallsortsofapplications,fromgeneral ctivedrawingapplicationstogames.Forinstanceaprogramisnotcapableofdrawingpictureswhilereadingkeystrokes.Sotheprogrameitherhastogivefullattentiontolisteningtokeystrokesordrawingpictures,otherwiseonethreadcanlistentothekeyboardwhiletheotherdrawsthepictures.UsagesofThreadsAnothergoodusageofthreadsinonasystemwithmultipleCPUsorcores.InthiscaseeachthreadwouldberunonaseparateCPU,resultingistrueparallelisminsteadoftimesharing.FigureJavathreadconstructorandmanagement CreatesanewthreadintheSUSPENDEDstate,whichwillbelongtogroupandbeidentifiedasname;thethreadwillexecutetherun()methodoftarget.Setandreturnthethread’spriority.Athreadexecutestherun()methodofitstargetobject,ifithasone,andotherwiseitsrun()method(ThreadimplementsJavathreadconstructorandmanagementmethods ChangethestateofthethreadfromSUSPENDEDto sleep(int CausethethreadtoentertheSUSPENDEDstateforthespecified EntertheREADYstateandinvokethe DestroytheFigureJavathreadsynchronization BlocksthecallingthreadforuptothespecifiedtimeuntilthreadhasInterruptsthread:causesittoreturnfromablockingmethodcallsuchas object.wait(longmillisecs,intBlocksthecallingthreaduntilacallmadetonotify()ornotifyAll()onobjectwakesthethread,orthethreadisinterrupted,orthespecifiedtimehaselapsed.Wakes,respectively,oneorallofanythreadsthathavecalledwait()onCreatingThreadsinTherearetwowaysinwhichJavaallowsforthecreationofathread.ExtendingaImplementinganCreatingThreadsThefirstistosimplyextendtheThreadclassandoverloadtherun()method.importpublicclassExampleextends{publicvoid{}}CreatingThreadsThesecondistoimplementtheRunnableUsingthiswecancreatethesameimportpublicclassExampleimplements{publicvoid{}}Therearetwowaystosynchronizethreadsbothofwhicharebasedonthesynchronizedkeyword,blocksandAsynchronizedmethodisonewhichspecifiessynchronizedaspartofits synchronizedvoidf(){/*body*/Blocksynchronizationtakesanargumentofwhichobjecttolock.Thisallowsanymethodtolockanyobject.synchronized(this){/*body*/Onethingtonoteisthatthesynchronizedkeywordisnotpartofamethod’ssignature,soitcan’tbeinheritedwhensubclassed.SuspendingThreadsLikethestopmethod,suspend()wasalsodeprecatedduetoallowingdeadlocktohappeninsomecases. Similarlytothestop()methodweneedtoaddsomethingtotheclassandtherunmethodtoallowthethreadtosuspenditselfwhenasked,andresumewhenSuspendingThreads(cont.)TherearetwowaysinwhichtosuspendaThethreadcallswait()onThethreadcalls线程调用:wait(,Thentoresumethethreadnotify()ornotifyAll()mustbecalled.然后,恢复线程调用notify(orprivatevolatilebooleansusThread=false;publicvoidsuspendThread(booleanval){susThread=val;}Suspendingpublicvoidrun()ThreadmyThread==Thread.currentThread();while(myThread==exampleThread){trysynchronized(this){}}catch(InterruptedException}}SuspendingThreadsIntheexampleitisimportanttorealizethatthecheckshouldbedoneafterthesleep()inrun()sothatwhenthethreadisresumeditdoesn’t ygobacktothewaitstate.该设置检查,以线程被恢复时,它不能很快地恢FastThreadsisahierarchic,event-basedthreadschedulingsystem.Itmanagesakernelonacomputerwithoneormoreprocessorsandasetofapplicationprocesses.Eachprocesshasauserlevelscheduler,whilethekernelallocatesvirtualprocessorstoprocesses.Partaofthenextslideshowsakernelallocationprocessesonathree-processormachine.Figure6.10Scheduleractivations

P

Ptoprocesses

KernelFigure6.10bthattheprocessnotifiesthekernelwhenavirtualprocessorisidleandnolongerneededorwhenanextravirtualprocessoristhatthekernelnotifiesaprocesswhenascheduleractivationnotifiesthatprocess’schedulerofanevent.Therearefourtypesofscheduleractivationevents,shownonthenextslide. User-LevelSchedulerAnewVirtualProcessorSchedulerActivationSchedulerActivationSchedulerActivationChapterChapter44.74.8InvocationInvocationperformanceisacriticalfactorindistributedsystemdesign.Themoredesignersseparatefunctionalitybetweenaddressspaces,themoreremoteinvocationsarerequired.必须越多的使用调用。Theinvocationofalocalprocesstakes cewithinlocalmemoryandmayinvolveafewtensofinstructioncycles.Invocationofaremoteprocessinvolvesnetworkactivitiesandpossiblyaccesstofiles,andmayrequirebillionsofinstructioncyclesinprocessorsrunningatspeedsmeasuredingigahertz. TheseinvocationactivitiesareexternaltothedesiredprocessingactivitiesandincreasecostswithoutaddingLatencyNullInvocationcostsarethedelaysrequiredtosetupcommunicationsandthenon-goalperformingoverheadofinvocations.Thesefixedoverheadcostsmeasurethelatencyoftheconnection.Substantialeffortsgointominimizingandreducinglatencycostsindistributedapplications.Slide6.11showssomeofthedelaysfordifferenttypesofinvocations.FigureInvocationsbetweenaddress

trapinstruction

Controltransfervia

User

UserRPC/RMI(between

InvocationCostsasapercentageofAsmoregoalworkisplishedforafixedamountofoverhead,theoverheadislessofaconcernasapercentageoftotalWithverysmalldatasizes,mostofthesystemtimebespentinoverheadWithlargedatatransfers,theoverheadcostsmaynegligibleasapercentageoftotalSlide6.12illustratesthisasagraphofRPCagainstpacketsizeinRPCSlide6.12 FigureRPCdelayagainstparameterRPC

size(bytes)RPCdelayagainstparametersizeThedelayisroughlyproportionaltothesizeuntilthesizereachesathresholdataboutnetworkpacketsize.Beyondthatthreshold,atleastoneextrapackethastobesent,tocarrytheextradata.Dependingontheprotocol,afurtherpacketmightbeusedtoacknowledgethisextrapacket.JumpinthegraphoccureachtimethenumberofpacketincreasesLightweightOnewaytoreducetheoverheadofaremoteinvocationistosharesomeofthecosts.Whileprocessinvocationisexpensive,someactivitiescanbedoneonceandthenreused,whileothersmustbedoneforeachcommunication.减少 LightweightRPCattemptstominimizeoverheadbysharingprocessactivitieswithinparentprocessesthatarepre-established.Overheadcostscanbereducedbyasmuchastwo-FigureAlightweightremoteprocedure

AA

andcopyresults

Trapto

ConcurrentInvocationAnotherapproachtoreducingcommunicationoverheadistoreducethenumberofmessagessenttoestablishtheconnectionandtocontinueprocessingwhilecommunicatinginsteadofsuspendingthreadsuntilamessageisreceived.SerializedandconcurrentinvocationsarecomparedonthenextFigureTimesforserializedandconcurrent

Thread-basedSingle isnotgood intsockfd;FILE*fp;{pthread_ttid;fp=fopen(…);/*Starttheusualway*/sockfd=Socket(…);/*Createathreadtosenddata*/Pthread_create(&tid,NULL,write_func,NULL);/*readdatafromsockfd*//*waitforchildthread*/Pthread_join(tid,NULL);}void*write_func(void{charsendline[MAXLINE];while(moredatainfp)ReadfromfpintoWritesendline[]intoShutdown(sockfd,SHUT_WR);}void{charwhile(moredatafromsockfd)Readfromsockfdintorecvline[];Writefromrecvline[]tostdout;}LockingLockinginMutexMutex–formutualintcounter=void*thread_func(void{int/*unprotectedcode*/val=counter;counter=val+return}intcounter=ptread_mutex_tmutex=void*thread_func(void{int/*protectedbymutex*/Pthread_mutex_lock(&mutex);val=counter;counter=val+1;Pthread_mutex_unlock(&mutex);return}ConditionVariable–forThinkofConditionVariable–forProducersandconsumersruninseparateProducerproducesdataandconsumerconsumesProducerhastoinformtheconsumerwhendataisConsumerhastoinformproducerwhenbufferspaceisWithoutWithoutCondition/*Globalsintdata_avail=pthread_mutex_tdata_mutex=void*producer(void{ProducedataInsertdatainto}{/*donothing–keeploo Extractdatafromif(queueisdata_avail=0;}WithWithConditionintdata_avail=pthread_cont_tdata_cond=PTHREAD_COND_INITIALIZER;{ProducedataInsertdataintodata_avail=1;}void*consumer(void{while(!data_avail)/*sleeponconditionvariable*/}/*wokenupExtractdatafromqueue;if(queueisempty)data_avail=}ChapterChapter44.74.8KernelModeandUserMostCPUssupporttwolevelsofInkernelmode,allinstructionsarepermittedandallmemoryandregistersareaccessible. Inusermode,memoryandregisteraccessisGenerally,almostalloperatingsystemscodeisexecutedinkernelmode,whileuserprocessesarelimitedtousermode.在用户模式,内存和寄存器被限制。一般地,几乎所有的KernelArchitectureMonolithicKernelsthatserveallthefunctionsoftheO/Smaynotbeideallysuitedfordistributedapplications.Theyaremassive,undifferentiatedandintractable.AnalternativeistohavethekernelperformthemostbasicionsandallowmicrokernelsthatcanbeadaptedforspecializedfunctionstomanagesystemFigure

FigureTheroleofthemicrokernel ThemicrokernelsupportsmiddlewareviaBasicServicesofanTaskTaskLocal/RemoteInterProcessCommunicationsFileSystemSecurityIntertaskHighPerformanceMulti-userMemoryDynamicRun-TimeExtendedExtendedservicesareacategoryofmiddlewarethatexploitthepotentialofnetworkstodistributeDBMS,TPMonitors,andNetworkOperatingServiceUbiquitousAccesstonetworkfileandprintBinarylargeobjectsGlobaldirectoriesandNetworkYellowAuthenticationandauthorizationSystemNetworkDatabaseandTransactionInternetServerPCAsymmetricMultiprocessingSymmetricMultiprocessingAllprocessorsareMultiserverGraphicalUserInterfaceStructureconsistsofanicon,aprimarywindowwith bar,andoneormoresecondarywindowsSupportingtasksmayhavesecondarywindowsand Anapplicationrepresentsatask,andusersmustfollowthestructureofataskChapterChapter4 虚拟是指通过某种技术把一个物理实体变成若干个逻辑上例如,在单CPU多道分时系统中,通过多道程序技术和分VirtualMachinesandVirtualization enablesasinglePCorservertosimultaneouslyrunmultipleoperatingsystemsormultiplesessionsofasingleOS(单机或amachinecanhostnumerousapplicationsincludingthosethatrunondifferentoperatingsystems,onasingle hostoperatingsystemcansupportaeachhasthecharacteristicsofaparticularOSand,insomeversionsofvirtualization,thecharacteristicsofaparticularhardware

Figure2.13showsatypicalarrangement.Thevirtualmachinemonitor(VMM)

VirtualMemoryVirtualMachineArchitectureInstructionsetarchitectureISA)指令系统体系结ApplicationbinaryinterfaceABI)应用程序二进制Applicationprogramminginterface(API)应用程序HowDoesItWork?Eachvirtualmachineisanemulationofacompletehardwaremachine+guestOS+applications,buttheVMexistsinuserTheVMMand(whenitispresent)thehostoperatingsystemruninkernelspace/mode.HowcanaguestOSrunninginuserspaceexecuteprivileged(特权)instructions?Itcan’t.Whenittries,theexecutionistrappedtotheVMM,whichthentakeschargeofexecutingtheinstructioninquestion.ProcessVirtualProcessVirtualMachine(进程虚拟机Isavirtual tformforexecutingasingleDoesnotlooklikeanyreal TheprocessVMinterprets codethathasbeencompiledtorunonthevirtualmachineExamples:JVM, ’sCLIJITSystemVirtualSystemVirtualMachine(系统虚拟机EachvirtualmachineisanisolatedenvironmentthatsharessystemresourceswithotherVMsappearstotheguestOSandtheappsitrunsasanexactcopyoftherealhardwareTheguestOSman

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论