PPTslinux视频Linux Perance and Tuning_第1页
PPTslinux视频Linux Perance and Tuning_第2页
PPTslinux视频Linux Perance and Tuning_第3页
PPTslinux视频Linux Perance and Tuning_第4页
PPTslinux视频Linux Perance and Tuning_第5页
已阅读5页,还剩276页未读 继续免费阅读

下载本文档

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

文档简介

UnderstandingtheLinuxoperatingsystem,2020/5/24,LinuxPerformanceandTuning,page:2,register,CPU,NorthBridge,程序:局部性空间局部性、时间局部性,置换策略,CPU,N路关联,Writethrough:通写WriteBack:回写,VideoCard,SouthBridge,IOPort:65535一片连续端口临界区DMA:,poll,InterruptController,2020/5/24,LinuxPerformanceandTuning,page:3,Cpu:10G,2020/5/24,LinuxPerformanceandTuning,page:4,73:74,指令计数器,2020/5/24,LinuxPerformanceandTuning,page:5,2020/5/24,LinuxPerformanceandTuning,page:6,4k,page,pageframe(页框),2020/5/24,LinuxPerformanceandTuning,page:7,60-70%,仿真,ReadySleeping可打断不可打断,2020/5/24,LinuxPerformanceandTuning,page:8,MonitorOSVM,2020/5/24,LinuxPerformanceandTuning,page:9,Writeback(回写),计算机的体系运算器控制器存储设备输入设备输出设备,CPU,Memory,NB,SB,Writethrough:通写,I/Oports,MMU,TLB,2020/5/24,LinuxPerformanceandTuning,page:10,Cacheline,一级缓存指令缓存数据缓存,2020/5/24,LinuxPerformanceandTuning,page:11,完全关联Fullassociative部分关联Setassociative直接映射Directmapping,2020/5/24,LinuxPerformanceandTuning,page:12,2020/5/24,LinuxPerformanceandTuning,page:13,Schematicinteractionofdifferentperformancecomponents,Linuxprocessmanagement,2020/5/24,LinuxPerformanceandTuning,page:15,Whatisaprocess?,AprocessisaninstanceofexecutionthatrunsonaprocessorFromthekernelspointofview,thepurposeofaprocessistoactasanentitytowhichsystemresources(CPUtime,memory,etc.)areallocatedTheyincludeasetofresourcessuchasopenfilesandpendingsignals,internalkerneldata,processorstate,amemoryaddressspacewithoneormorememorymappings,oneormorethreadsofexecution,andadatasectioncontainingglobalvariables,2020/5/24,LinuxPerformanceandTuning,page:16,ProcessDescriptorandtheTaskStructure,Tomanageprocesses,thekernelmusthaveaclearpictureofwhateachprocessisdoingThekernelstoresthelistofprocessesinacirculardoublylinkedlistcalledthetasklistAllprocessesrunningonLinuxoperatingsystemaremanagedbythetask_structstructure,whichisalsocalledaprocessdescriptorThetask_structisarelativelylargedatastructure,ataround1.7kilobytesona32-bitmachine,2020/5/24,LinuxPerformanceandTuning,page:17,Theprocessdescriptorandtasklist,ListTask_structure,2020/5/24,LinuxPerformanceandTuning,page:18,TheLinuxprocessdescriptor,2020/5/24,LinuxPerformanceandTuning,page:19,ProcessState,TASK_RUNNINGTheprocessiseitherexecutingonaCPUorwaitingtobeexecutedTASK_INTERRUPTIBLETheprocessissuspended(sleeping)untilsomeconditionbecomestrue.Raisingahardwareinterrupt,releasingasystemresourcetheprocessiswaitingfor,ordeliveringasignalareexamplesofconditionsthatmightwakeuptheprocess(putitsstatebacktoTASK_RUNNING)AtypicalexampleofaTASK_INTERRUPTIBLEprocessisaprocesswaitingforkeyboardinterrupt,2020/5/24,LinuxPerformanceandTuning,page:20,TASK_UNINTERRUPTIBLELikeTASK_INTERRUPTIBLE,exceptthatdeliveringasignaltothesleepingprocessleavesitsstateunchangedAtypicalexampleofaTASK_UNINTERRUPTIBLEprocessisaprocesswaitingfordiskI/OoperationTASK_STOPPEDProcessexecutionhasbeenstopped;theprocessentersthisstateafterreceivingaSIGSTOP,SIGTSTP,SIGTTIN,orSIGTTOUsignal,2020/5/24,LinuxPerformanceandTuning,page:21,TASK_TRACEDProcessexecutionhasbeenstoppedbyadebuggerWhenaprocessisbeingmonitoredbyanother(suchaswhenadebuggerexecutesaptrace()systemcalltomonitoratestprogram),eachsignalmayputtheprocessintheTASK_TRACEDstateTASK_ZOMBIEProcessexecutionisterminated,buttheparentprocesshasnotyetissuedawait4()orwaitpid()systemcalltoreturninformationaboutthedeadprocess,2020/5/24,LinuxPerformanceandTuning,page:22,ProcessState,2020/5/24,LinuxPerformanceandTuning,page:23,Lifecycleofaprocess,Everyprocesshasitsownlifecyclesuchascreation,execution,termination,andremoval,2020/5/24,LinuxPerformanceandTuning,page:24,Whenaprocesscreatesanewprocess,thecreatingprocess(parentprocess)issuesafork()systemcallWhenafork()systemcallisissued,itgetsaprocessdescriptorforthenewlycreatedprocess(childprocess)andsetsanewprocessidItcopiesthevaluesoftheparentprocessprocessdescriptortothechildschilds.Atthistimetheentireaddressspaceoftheparentprocessisnotcopied;bothprocessessharethesameaddressspace,2020/5/24,LinuxPerformanceandTuning,page:25,Theexec()systemcallcopiesthenewprogramtotheaddressspaceofthechildprocessBecausebothprocessessharethesameaddressspace,writingnewprogramdatacausesapagefaultexceptionAtthispoint,thekernelassignsthenewphysicalpagetothechildprocessThisdeferredoperationiscalledtheCopyOnWrite,2020/5/24,LinuxPerformanceandTuning,page:26,Whenprogramexecutionhascompleted,thechildprocessterminateswithanexit()systemcallTheexit()systemcallreleasesmostofthedatastructureoftheprocessandnotifiestheparentprocessoftheterminationsendingasignalAtthistime,theprocessiscalledazombieprocess,2020/5/24,LinuxPerformanceandTuning,page:27,Thechildprocesswillnotbecompletelyremoveduntiltheparentprocessknowsoftheterminationofitschildprocessbythewait()systemcallAssoonastheparentprocessisnotifiedofthechildprocesstermination,itremovesallthedatastructureofthechildprocessandreleasetheprocessdescriptor,2020/5/24,LinuxPerformanceandTuning,page:28,Thread,AthreadisanexecutionunitgeneratedinasingleprocessItrunsparallelwithotherthreadsinthesameprocessTheycansharethesameresourcessuchasmemory,addressspace,openfiles,andsoonTheycanaccessthesamesetofapplicationdataAthreadisalsocalledLightWeightProcess(LWP)Becausetheyshareresources,eachthreadshouldnotchangetheirsharedresourcesatthesametimeTheimplementationofmutualexclusion,locking,serialization,andsoon,aretheuserapplicationsresponsibility,2020/5/24,LinuxPerformanceandTuning,page:29,Fromtheperformanceperspective,threadcreationislessexpensivethanprocesscreationbecauseathreaddoesnotneedtocopyresourcesoncreation,2020/5/24,LinuxPerformanceandTuning,page:30,IncurrentLinuximplementations,athreadissupportedwiththePortableOperatingSystemInterfaceforUNIX(POSIX)compliantlibrary(pthread)SeveralthreadimplementationsareavailableintheLinuxoperatingsystem:LinuxThreadsNativePOSIXThreadLibrary(NPTL)NextGenerationPOSIXThread(NGPT)UsingtheLD_ASSUME_KERNELenvironmentvariable,youcanchoosewhichthreadslibrarytheapplicationshoulduse,2020/5/24,LinuxPerformanceandTuning,page:31,Contextswitching,Tocontroltheexecutionofprocesses,thekernelmustbeabletosuspendtheexecutionoftheprocessrunningontheCPUandresumetheexecutionofsomeotherprocesspreviouslysuspendedThisactivitygoesvariouslybythenamesprocessswitch,taskswitch,orcontextswitchWhileeachprocesscanhaveitsownaddressspace,allprocesseshavetosharetheCPUregistersSobeforeresumingtheexecutionofaprocess,thekernelmustensurethateachsuchregisterisloadedwiththevalueithadwhentheprocesswassuspendedTheprocessdescriptorandtheareacalledkernelmodestackareusedtostorethecontext,2020/5/24,LinuxPerformanceandTuning,page:32,Contextswitching,2020/5/24,LinuxPerformanceandTuning,page:33,O(1)SCHED_OtherCFS:CompleteFairScheduler,2020/5/24,LinuxPerformanceandTuning,page:34,Processmemorysegments,AprocessusesitsownmemoryareatoperformworkTheworkvariesdependingonthesituationandprocessusageAprocesscanhavedifferentworkloadcharacteristicsanddifferentdatasizerequirementsTheprocesshastohandleaofvarietyofdatasizesTosatisfythisrequirement,theLinuxkernelusesadynamicmemoryallocationmechanismforeachprocess,2020/5/24,LinuxPerformanceandTuning,page:35,Processaddressspace,2020/5/24,LinuxPerformanceandTuning,page:36,Init,fork(),ProcessKernelCOW:写时复制CopyOnWriting,2020/5/24,LinuxPerformanceandTuning,page:37,Nginx:worker,SMP,2020/5/24,LinuxPerformanceandTuning,page:38,COWKernelinitinitfork():系统调用task_structMemoryParentCOW:CopyOnWrite,2020/5/24,LinuxPerformanceandTuning,page:39,多任务自愿式多任务抢占式多任务上下文切换(ContextSwitch),2020/5/24,LinuxPerformanceandTuning,page:40,BigOO(1)O(logn)O(n)O(n2)O(2n),2020/5/24,LinuxPerformanceandTuning,page:41,动态静态实时优先级0-990-139100-139120(-20至19),进程的类型交互式进程批处理进程实时进程交互式进程I/OBound批处理进程CPUBound,2020/5/24,LinuxPerformanceandTuning,page:42,Classesofprocesses,InteractiveprocessesTheseinteractconstantlywiththeirusers,andthereforespendalotoftimewaitingforkeypressesandmouseoperationsBatchprocessesThesedonotneeduserinteraction,andhencetheyoftenruninthebackgroundReal-timeprocessesThesehaveverystrongschedulingrequirementsSuchprocessesshouldneverbeblockedbylower-priorityprocesses,theyshouldhaveashortresponsetimeand,mostimportant,suchresponsetimeshouldhaveaminimumvarianceTypicalreal-timeprogramsarevideoandsoundapplications,robotcontrollers,andprogramsthatcollectdatafromphysicalsensors,2020/5/24,LinuxPerformanceandTuning,page:43,ProcessScheduling,MultitaskingMultitaskingoperatingsystemscomeintwoflavors:cooperativemultitaskingandpreemptivemultitaskingLinux,likeallUnixvariantsandmostmodernoperatingsystems,implementspreemptivemultitaskingInpreemptivemultitasking,thescheduler,oneofthekernelsubsystem,decideswhenaprocessistoceaserunningandanewprocessistobeginrunningTheactofinvoluntarilysuspendingarunningprocessiscalledpreemption,2020/5/24,LinuxPerformanceandTuning,page:44,LinuxsProcessScheduler,O(1)schedulerItscaleswellwiththenumberofrunnableprocesses,becauseitselectstheprocesstoruninconstanttime,independentlyofthenumberofrunnableprocessesItalsoscaleswellwiththenumberofprocessorsbecauseeachCPUhasitsownqueueofrunnableprocessesThenewalgorithmdoesabetterjobofdistinguishinginteractiveprocessesandbatchprocessesBut,O(1)schedulerhadseveralpathologicalfailuresrelatedtoschedulinglatency-sensitiveapplicationsThus,althoughtheO(1)schedulerwasidealforlargeserverworkloadswhichlackinteractiveprocessesitperformedbelowparondesktopsystems,whereinteractiveapplicationsaretheraisondtre,2020/5/24,LinuxPerformanceandTuning,page:45,Linuxkernel2.6O(1)scheduler,2020/5/24,LinuxPerformanceandTuning,page:46,LinuxschedulingisbasedonthetimesharingtechniqueSeveralprocessesrunintimemultiplexingbecausetheCPUtimeisdividedintoslices,oneforeachrunnableprocessTimesharingreliesontimerinterruptsandisthustransparenttoprocessesTheschedulingpolicyisalsobasedonrankingprocessesaccordingtotheirpriority,2020/5/24,LinuxPerformanceandTuning,page:47,ProcessPreemption,IfaprocessenterstheTASK_RUNNINGstate,thekernelcheckswhetheritsdynamicpriorityisgreaterthanthepriorityofthecurrentlyrunningprocessIfitis,theexecutionofcurrentisinterruptedandtheschedulerisinvokedtoselectanotherprocesstorunaprocessmayalsobepreemptedwhenitstimequantumexpireswhenthisoccurs,theneed_reschedfieldofthecurrentprocessisset,sotheschedulerisinvokedwhenthetimerinterrupthandlerterminates,2020/5/24,LinuxPerformanceandTuning,page:48,Preemptingthecurrentprocess,StandardpreemptionrulesCPUreceivesahardinterruptProcessrequestsIOProcessvoluntarilysurrenderstheCPUviasched_yieldScheduleralgorithmdeterminesthatprocessshouldbepreemptedViewingschedulerpolicyandprioritychrt-ppidpsaxopid,comm,rtprio,policytopTheinitprocessstartswithSCHED_OHTEREachprocessinheritsparentsschedulingpolicyandpriorityatcreatationtime,2020/5/24,LinuxPerformanceandTuning,page:49,SchedulingPolicy,PolicyisthebehavioroftheschedulerthatdetermineswhatrunswhenAschedulerspolicyoftendeterminestheoverallfeelofasystemandisresponsibleforoptimallyutilizingprocessortimeTheschedulingalgorithmoftraditionalUnixoperatingsystemsmustfulfillseveralconflictingobjectives:fastprocessresponsetimegoodthroughputforbackgroundjobsavoidanceofprocessstarvationreconciliationoftheneedsoflowhigh-priorityprocessesandsoonThesetofrulesusedtodeterminewhenandhowtoselectanewprocesstoruniscalledschedulingpolicy,2020/5/24,LinuxPerformanceandTuning,page:50,Characterizingprocesses,Whenspeakingaboutscheduling,processesaretraditionallyclassifiedasI/O-boundorCPU-boundTheformerischaracterizedasaprocessthatspendsmuchofitstimesubmittingandwaitingonI/OrequestsConversely,processor-boundprocessesspendmuchoftheirtimeexecutingcodeAschedulerpolicyforprocessor-boundprocessestendstorunsuchprocesseslessfrequentlybutforlongerdurationsLinux,aimingtoprovidegoodinteractiveresponseanddesktopperformance,optimizesforprocessresponse(lowlatency),thusfavoringI/O-boundprocessesoverprocessor-boundprocessors,2020/5/24,LinuxPerformanceandTuning,page:51,ProcessPriority,InLinux,processpriorityisdynamicTheschedulerkeepstrackofwhatprocessesaredoingandadjuststheirprioritiesperiodicallyProcessesthathavebeendeniedtheuseofaCPUforalongtimeintervalareboostedbydynamicallyincreasingtheirpriorityProcessesrunningforalongtimearepenalizedbydecreasingtheirpriority,2020/5/24,LinuxPerformanceandTuning,page:52,Staticpriority,Everyconventionalprocesshasitsownstaticpriority,whichisavalueusedbytheschedulertoratetheprocesswithrespecttotheotherconventionalprocessesinthesystemThekernelrepresentsthestaticpriorityofaconventionalprocesswithanumberrangingfrom100(highestpriority)to139(lowestpriority)NewprocessalwaysinheritsthestaticpriorityofitsparentHowever,ausercanchangethestaticpriorityoftheprocessesthatheownsbypassingsomenicevalues,2020/5/24,LinuxPerformanceandTuning,page:53,real-timepriority,0-99higherreal-timepriorityvaluescorrespondtoagreaterpriorityAllreal-timeprocessesareatahigherprioritythannormalprocesses;thatis,thereal-timepriorityandnicevalueareindisjointvaluespacesps-eostate,uid,pid,ppid,rtprio,time,comm,2020/5/24,LinuxPerformanceandTuning,page:54,Timeslice,ThetimesliceisthenumericvaluethatrepresentshowlongataskcanrununtilitispreemptedTheschedulerpolicymustdictateadefaulttimeslice,whichisnotatrivialexercise,2020/5/24,LinuxPerformanceandTuning,page:55,TheSchedulingAlgorithm,SchedulerClassesTheLinuxschedulerismodular,enablingdifferentalgorithmstoscheduledifferenttypesofprocessesThismodularityiscalledschedulerclassesSchedulerclassesenabledifferent,pluggablealgorithmstocoexist,schedulingtheirowntypesofprocessesEachschedulerclasshasapriority.Thehighestpriorityschedulerclassthathasarunnableprocesswins,selectingwhorunsnext,2020/5/24,LinuxPerformanceandTuning,page:56,Schedulingclasses,EveryLinuxprocessisalwaysscheduledaccordingtooneofthefollowingschedulingclasses:SCHED_FIFO1-99AFirst-In,First-Outreal-timeprocessSCHED_RRARoundRobinreal-timeprocessSCHED_NORMAL(100-139)Aconventional,time-sharedprocessAlsonamedbySCHED_OTHERFornormalprocesses,2020/5/24,LinuxPerformanceandTuning,page:57,SCHED_OTHER,PrioritymayvaryProcesseswithequalprioritycanpreemptcurrentprocessevery20mstopreventCPUstarvationCPUboundprocessesreceivea+5prioritypenaltyafterpreemptionInteractivetasksspendtimewaitingforIOSchedulertrackstimespentwaitingforIOforeachprocessandcalculatesasleepaverageHighsleepaverageindicatesinteractiveprocessInteractiveprocessesmaybere-insertedintotheactivequeueIfnot,receivea-5priorityboostandmovetoexpiredqueue,2020/5/24,LinuxPerformanceandTuning,page:58,Tuningschedulerpolicy,SCHED_FIFOchrt-f1-99/path/to/programargumentsSCHED_RRchrt-r1-99/path/to/programargumentsSCHED_OTHER(SCHED_NORMAL)nicerenice,2020/5/24,LinuxPerformanceandTuning,page:59,调度类别:RTSCHED_FIFOSCHED_RR100-139SCHED_OtherSCHED_BATCHSCHED_IDLE,抢占tick:时钟中断100Hz1000HzRHEL6.4ticklessinterrupt-driven硬中断软中断深度睡眠,2020/5/24,LinuxPerformanceandTuning,page:60,I1,D1,0,1,2,3,2020/5/24,LinuxPerformanceandTuning,page:61,0,1,2020/5/24,LinuxPerformanceandTuning,page:62,socket,SMP对称多处理器,2020/5/24,LinuxPerformanceandTuning,page:63,LocalandRemoteMemoryAccessinNUMATopolog,2020/5/24,LinuxPerformanceandTuning,page:64,2020/5/24,LinuxPerformanceandTuning,page:65,ViewingCPUperformancedata,Loadaverage:averagelengthofrunqueuesConsidersonlytasksinTASK_RUNNABLEandTASK_UNINTERRUPTABLEsar-qtopwuptimevmstat15CPUutilizationmpstat12sar-PALL12iostat-c12/proc/statdstat-c,2020/5/24,LinuxPerformanceandTuning,page:66,HardwaretimersareusedasclocksRTCTSCAPICPIC100Hz,10mstick,jiffytick_divider=1,2020/5/24,LinuxPerformanceandTuning,page:67,EqualizingCPUvisitcount,ProcessmovestotheexpiredqueuewhenpreemptedImposesabuilt-inaffinityfortheCPUCanleadtounbalancedrunqueuesSchedulerrebalancesrunqueuesEvery100msifallprocessorsarebusyEvery1msifaCPUisidleViewaspecificprocesswatch-n.5psaxocomm,pid,psr|grepprogram_nameConsequencesLowervisitcountleadstohigherthroughputMovingatasktoanotherCPUguaranteesacachemiss,2020/5/24,LinuxPerformanceandTuning,page:68,Tuningprocessaffinitywithtaskset,UsethetasksetcommandtopinatasktoaCPUtasksetoptsmask|listpid|commandarg.#taskset-c-pcpulistPIDmask0 x00000001CPU#00 x00000002CPU#10 x00000003CPU#0andCPU#1ConsequencesImprovecachehits(lowerservicetime)forapplicationswithunitcachestrideUnbalancedrunqueuescancauselogwaittimesForNUMA,avoidnon-localmemoryaccesses,2020/5/24,LinuxPerformanceandTuning,page:69,0-30,30 x00000001:00 x00000011:0,1,2020/5/24,LinuxPerformanceandTuning,page:70,Tuningrunqueuelengthwithtaskset,RestrictlengthofaCPUrunqueueIsolateaCPUfromautomaticschedulingin/etc/grub.confisolcpus=cpunumber,cpunumberPintaskstothatCPUwithtasksetConsidermovingIRQsofftheCPU,2020/5/24,LinuxPerformanceandTuning,page:71,echocpu_mask/proc/irq/smp_affinity,0,12-15:,2020/5/24,LinuxPerformanceandTuning,page:72,Schedulerdomains,GroupprocessorsintocpusetsEachcpusetrepresentsaschedulerdomainSupportsbothmulti-coreandNUMAarchitecturesSimplemanagementinterfacethroughthecpusetvirtualfilesystemTherootcpusetcontainsallsystemresourcesChildcpusetsEachcpusetmustcontainatleastoneCPUandonememoryzoneChildcpusetscanbenestedDynamicallyattachtaskstoacpusetConsequencesControllatencyduetoqueuelength,cache,andNUMAzonesAssignprocesseswithdifferentCPUcharacteristicstodifferentcpusetsScalableforcomplexperformancescenarios,2020/5/24,LinuxPerformanceandTuning,page:73,Numa,0,2,1,3,2020/5/24,LinuxPerformanceandTuning,page:74,Configuringtherootcpuset,Createamountpointat/cpusetsAddanentryto/etc/fstabcpuset/cpusetscpusetdefaults00Mountthefilesystemtoautomaticallycreatethecpuset/cpusets/cpus/cpusets/mems/cpusets/tasksAllCPUsandmemoryzonesbelongtotherootcpusetAllexistingPIDsareassignedtotherootcpuset,2020/5/24,LinuxPerformanceandTuning,page:75,Configuringachildcpuset,Createasubdirectoryoftherootcpusetmkdir/cpusets/mageduAssignresourcesasarangeorcomma-separatedlistecho0/cpusets/magedu/cpusecho0/cpusets/magedu/memsAttachonetaskatatimeechopidofprocess/cpusets/magedu/tasksPersistin/etc/rc.local,Linuxmemoryarchitecture,2020/5/2

温馨提示

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

评论

0/150

提交评论