您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 国内外标准规范 > Cgroups-on-Linux-Kernel
ControlgroupsLINUXKERNELFEATUREcgroups(abbreviatedfromcontrolgroups)isaLinuxkernelfeaturethatlimits,accountsforandisolatestheresourceusage(CPU,memory,diskI/O,network,etc.)ofacollectionofprocesses.Providesfeatures:ResourcelimitationPrioritizationAccountingControl*task*-process*cgroup*associatesasetoftaskswithasetofparametersforoneormoresubsystems.*hierarchy*isasetofcgroupsarrangedinatree,suchthateverytaskinthesystemisinexactlyoneofthecgroupsinthehierarchy,andasetofsubsystems;eachsubsystemhassystem-specificstateattachedtoeachcgroupinthehierarchy.Eachhierarchyhasaninstanceofthecgroupvirtualfilesystemassociatedwithit.*subsystem*isamodulethatmakesuseofthetaskgroupingfacilitiesprovidedbycgroupstotreatgroupsoftasksinparticularways.Asubsystemistypicallyaresourcecontrollerthatschedulesaresourceorappliesper-cgrouplimits,butitmaybeanythingthatwantstoactonagroupofprocesses,e.g.avirtualizationsubsystem.DefinitionsDefinitionsSubsystemcpusets:fascilitateassigningasetofCPUSandmemorynodestocgroups.TasksinacpusetcgroupmayonlybescheduledonCPUSassignedtothatcpuset.blkio:limitsper-cgroupblockio.cpuacct:providesper-cgroupcpuusageaccounting.devices:controlstheabilityoftaskstocreateorusedevicesnodesusingeitherablacklistorwhitelist.freezer:providesawayto'freeze'and'thaw'wholecgroups.Tasksinthecgroupwillnotbescheduledwhiletheyarefrozen.hugetlb:fascilitateslimitinghugetlbusagepercgroup.memory:allowsmemory,kernelmemory,andswapusagetobetrackedandlimited.net_cls:providesaninterfacefortaggingpacketsbasedonthesendercgroup.Thesetagscanthenbeusedbytc(trafficcontroller)toassignpriorities.net_prio:allowssettingnetworktrafficpriorityonaper-cgroupbasis.cpu:enablessettingofschedulingpreferencesonper-cgroupbasis.CgroupfilesystemEachcgroupisrepresentedbyadirectoryinthecgroupfilesystemcontainingthefollowingfilesdescribingthatcgroup:tasks:listoftasks(byPID)attachedtothatcgroup.Thislistisnotguaranteedtobesorted.WritingathreadIDintothisfilemovesthethreadintothiscgroup.cgroup.procs:listofthreadgroupIDsinthecgroup.ThislistisnotguaranteedtobesortedorfreeofduplicateTGIDs,anduserspaceshouldsort/uniquifythelistifthispropertyisrequired.WritingathreadgroupIDintothisfilemovesallthreadsinthatgroupintothiscgroup.notify_on_releaseflag:runthereleaseagentonexitrelease_agent:thepathtouseforreleasenotifications(thisfileexistsinthetopcgrouponly)BasicUsage(1)Mountacgrouphierarchywithonespecificsubsystems$mount-ttmpfscgroup_root/sys/fs/cgroup$mkdir/sys/fs/cgroup/cpuset$mount-tcgroupcpuset–ocpuset/sys/fs/cgroup/cpusetMountwithallavailablesubsystems$mount-tcgroupxxx/sys/fs/cgroupBasicUsage(2)Specifyahierarchy'srelease_agent:$mount-tcgroup-ocpuset,release_agent=/sbin/cpuset_release_agent“cpuset/sys/fs/cgroup/cpusetchangethevalueofrelease_agent:$echo/sbin/new_release_agent/sys/fs/cgroup/cpuset/release_agentcreateanewcgroupunder/sys/fs/cgroup/cpuset:$cd/sys/fs/cgroup/cpuset$mkdirmy_cgroupBasicUsage(3)attachprocesstoonecgroup:$/bin/echoPIDtasksremoveacgroup,justusermdir:$rmdirmy_sub_cgThenameofthesubsystemappearsaspartofthehierarchydescriptionin/proc/mountsand/proc/pid/cgroupsSubsystem-CpuThecpusubsystemschedulesCPUaccesstocgroups.CompletelyFairScheduler(CFS)cpu.cfs_period_uscpu.cfs_quota_uscpu.statcpu.sharesReal-Timescheduler(RT)cpu.rt_period_uscpu.rt_runtime_usSubsystem-CpuacctCreatenewaccountinggroupunder/sys/fs/cgroup/cpuacct$cd/sys/fs/cgroup/cpuacct$mkdirg1$echo$$g1/taskscpuacct.statfilelistsafewstatisticswhichfurtherdividetheCPUtimeobtainedbythecgroupintouserandsystemtimes.user:Timespentbytasksofthecgroupinusermode.system:Timespentbytasksofthecgroupinkernelmode.userandsystemareinUSER_HZunit.cpuacct.usage-CPUtimeconsumedbythiscpuacct.usage_percpuSubsystem-Cpuset-cpuset.cpus:listofCPUsinthatcpuset-cpuset.mems:listofMemoryNodesinthatcpuset-cpuset.memory_migrateflag:ifset,movepagestocpusetsnodes-cpuset.cpu_exclusiveflag:iscpuplacementexclusive?-cpuset.mem_exclusiveflag:ismemoryplacementexclusive?-cpuset.mem_hardwallflag:ismemoryallocationhardwalled-cpuset.memory_pressure:measureofhowmuchpagingpressureincpuset-cpuset.memory_spread_pageflag:ifset,spreadpagecacheevenlyonallowednodes-cpuset.memory_spread_slabflag:ifset,spreadslabcacheevenlyonallowednodes-cpuset.sched_load_balanceflag:ifset,loadbalancewithinCPUsonthatcpuset-cpuset.sched_relax_domain_level:thesearchingrangewhenmigratingtasksSubsystem-BlockIOTwoIOcontrolpolicies:Proportionalweighttimebaseddivisionofdiskpolicy.ItisimplementedinCFQ.HencethispolicytakeseffectonlyonleafnodeswhenCFQisbeingused.-blkio.weight-Specifiespercgroupweight.(10to1000)-blkio.weight_device–Specifypercgroupperdevicerules.#echo8:16300blkio.weight_deviceThrottlingpolicywhichcanbeusedtospecifyupperIOratelimitsondevices.-blkio.throttle.read_bps_device-SpecifiesupperlimitonREADratefromthedevice.echomajor:minorrate_bytes_per_second/cgrp/blkio.throttle.read_bps_device-blkio.throttle.write_bps_device-SpecifiesupperlimitonWRITEratetothedevice.-blkio.throttle.rea
本文标题:Cgroups-on-Linux-Kernel
链接地址:https://www.777doc.com/doc-7086598 .html