cgroup-v2.rst 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440
  1. .. _cgroup-v2:
  2. ================
  3. Control Group v2
  4. ================
  5. :Date: October, 2015
  6. :Author: Tejun Heo <tj@kernel.org>
  7. This is the authoritative documentation on the design, interface and
  8. conventions of cgroup v2. It describes all userland-visible aspects
  9. of cgroup including core and specific controller behaviors. All
  10. future changes must be reflected in this document. Documentation for
  11. v1 is available under :ref:`Documentation/admin-guide/cgroup-v1/index.rst <cgroup-v1>`.
  12. .. CONTENTS
  13. [Whenever any new section is added to this document, please also add
  14. an entry here.]
  15. 1. Introduction
  16. 1-1. Terminology
  17. 1-2. What is cgroup?
  18. 2. Basic Operations
  19. 2-1. Mounting
  20. 2-2. Organizing Processes and Threads
  21. 2-2-1. Processes
  22. 2-2-2. Threads
  23. 2-3. [Un]populated Notification
  24. 2-4. Controlling Controllers
  25. 2-4-1. Availability
  26. 2-4-2. Enabling and Disabling
  27. 2-4-3. Top-down Constraint
  28. 2-4-4. No Internal Process Constraint
  29. 2-5. Delegation
  30. 2-5-1. Model of Delegation
  31. 2-5-2. Delegation Containment
  32. 2-6. Guidelines
  33. 2-6-1. Organize Once and Control
  34. 2-6-2. Avoid Name Collisions
  35. 3. Resource Distribution Models
  36. 3-1. Weights
  37. 3-2. Limits
  38. 3-3. Protections
  39. 3-4. Allocations
  40. 4. Interface Files
  41. 4-1. Format
  42. 4-2. Conventions
  43. 4-3. Core Interface Files
  44. 5. Controllers
  45. 5-1. CPU
  46. 5-1-1. CPU Interface Files
  47. 5-2. Memory
  48. 5-2-1. Memory Interface Files
  49. 5-2-2. Usage Guidelines
  50. 5-2-3. Reclaim Protection
  51. 5-2-4. Memory Ownership
  52. 5-3. IO
  53. 5-3-1. IO Interface Files
  54. 5-3-2. Writeback
  55. 5-3-3. IO Latency
  56. 5-3-3-1. How IO Latency Throttling Works
  57. 5-3-3-2. IO Latency Interface Files
  58. 5-3-4. IO Priority
  59. 5-4. PID
  60. 5-4-1. PID Interface Files
  61. 5-5. Cpuset
  62. 5.5-1. Cpuset Interface Files
  63. 5-6. Device controller
  64. 5-7. RDMA
  65. 5-7-1. RDMA Interface Files
  66. 5-8. DMEM
  67. 5-8-1. DMEM Interface Files
  68. 5-9. HugeTLB
  69. 5.9-1. HugeTLB Interface Files
  70. 5-10. Misc
  71. 5.10-1 Misc Interface Files
  72. 5.10-2 Migration and Ownership
  73. 5-11. Others
  74. 5-11-1. perf_event
  75. 5-N. Non-normative information
  76. 5-N-1. CPU controller root cgroup process behaviour
  77. 5-N-2. IO controller root cgroup process behaviour
  78. 6. Namespace
  79. 6-1. Basics
  80. 6-2. The Root and Views
  81. 6-3. Migration and setns(2)
  82. 6-4. Interaction with Other Namespaces
  83. P. Information on Kernel Programming
  84. P-1. Filesystem Support for Writeback
  85. D. Deprecated v1 Core Features
  86. R. Issues with v1 and Rationales for v2
  87. R-1. Multiple Hierarchies
  88. R-2. Thread Granularity
  89. R-3. Competition Between Inner Nodes and Threads
  90. R-4. Other Interface Issues
  91. R-5. Controller Issues and Remedies
  92. R-5-1. Memory
  93. Introduction
  94. ============
  95. Terminology
  96. -----------
  97. "cgroup" stands for "control group" and is never capitalized. The
  98. singular form is used to designate the whole feature and also as a
  99. qualifier as in "cgroup controllers". When explicitly referring to
  100. multiple individual control groups, the plural form "cgroups" is used.
  101. What is cgroup?
  102. ---------------
  103. cgroup is a mechanism to organize processes hierarchically and
  104. distribute system resources along the hierarchy in a controlled and
  105. configurable manner.
  106. cgroup is largely composed of two parts - the core and controllers.
  107. cgroup core is primarily responsible for hierarchically organizing
  108. processes. A cgroup controller is usually responsible for
  109. distributing a specific type of system resource along the hierarchy
  110. although there are utility controllers which serve purposes other than
  111. resource distribution.
  112. cgroups form a tree structure and every process in the system belongs
  113. to one and only one cgroup. All threads of a process belong to the
  114. same cgroup. On creation, all processes are put in the cgroup that
  115. the parent process belongs to at the time. A process can be migrated
  116. to another cgroup. Migration of a process doesn't affect already
  117. existing descendant processes.
  118. Following certain structural constraints, controllers may be enabled or
  119. disabled selectively on a cgroup. All controller behaviors are
  120. hierarchical - if a controller is enabled on a cgroup, it affects all
  121. processes which belong to the cgroups consisting the inclusive
  122. sub-hierarchy of the cgroup. When a controller is enabled on a nested
  123. cgroup, it always restricts the resource distribution further. The
  124. restrictions set closer to the root in the hierarchy can not be
  125. overridden from further away.
  126. Basic Operations
  127. ================
  128. Mounting
  129. --------
  130. Unlike v1, cgroup v2 has only single hierarchy. The cgroup v2
  131. hierarchy can be mounted with the following mount command::
  132. # mount -t cgroup2 none $MOUNT_POINT
  133. cgroup2 filesystem has the magic number 0x63677270 ("cgrp"). All
  134. controllers which support v2 and are not bound to a v1 hierarchy are
  135. automatically bound to the v2 hierarchy and show up at the root.
  136. Controllers which are not in active use in the v2 hierarchy can be
  137. bound to other hierarchies. This allows mixing v2 hierarchy with the
  138. legacy v1 multiple hierarchies in a fully backward compatible way.
  139. A controller can be moved across hierarchies only after the controller
  140. is no longer referenced in its current hierarchy. Because per-cgroup
  141. controller states are destroyed asynchronously and controllers may
  142. have lingering references, a controller may not show up immediately on
  143. the v2 hierarchy after the final umount of the previous hierarchy.
  144. Similarly, a controller should be fully disabled to be moved out of
  145. the unified hierarchy and it may take some time for the disabled
  146. controller to become available for other hierarchies; furthermore, due
  147. to inter-controller dependencies, other controllers may need to be
  148. disabled too.
  149. While useful for development and manual configurations, moving
  150. controllers dynamically between the v2 and other hierarchies is
  151. strongly discouraged for production use. It is recommended to decide
  152. the hierarchies and controller associations before starting using the
  153. controllers after system boot.
  154. During transition to v2, system management software might still
  155. automount the v1 cgroup filesystem and so hijack all controllers
  156. during boot, before manual intervention is possible. To make testing
  157. and experimenting easier, the kernel parameter cgroup_no_v1= allows
  158. disabling controllers in v1 and make them always available in v2.
  159. cgroup v2 currently supports the following mount options.
  160. nsdelegate
  161. Consider cgroup namespaces as delegation boundaries. This
  162. option is system wide and can only be set on mount or modified
  163. through remount from the init namespace. The mount option is
  164. ignored on non-init namespace mounts. Please refer to the
  165. Delegation section for details.
  166. favordynmods
  167. Reduce the latencies of dynamic cgroup modifications such as
  168. task migrations and controller on/offs at the cost of making
  169. hot path operations such as forks and exits more expensive.
  170. The static usage pattern of creating a cgroup, enabling
  171. controllers, and then seeding it with CLONE_INTO_CGROUP is
  172. not affected by this option.
  173. memory_localevents
  174. Only populate memory.events with data for the current cgroup,
  175. and not any subtrees. This is legacy behaviour, the default
  176. behaviour without this option is to include subtree counts.
  177. This option is system wide and can only be set on mount or
  178. modified through remount from the init namespace. The mount
  179. option is ignored on non-init namespace mounts.
  180. memory_recursiveprot
  181. Recursively apply memory.min and memory.low protection to
  182. entire subtrees, without requiring explicit downward
  183. propagation into leaf cgroups. This allows protecting entire
  184. subtrees from one another, while retaining free competition
  185. within those subtrees. This should have been the default
  186. behavior but is a mount-option to avoid regressing setups
  187. relying on the original semantics (e.g. specifying bogusly
  188. high 'bypass' protection values at higher tree levels).
  189. memory_hugetlb_accounting
  190. Count HugeTLB memory usage towards the cgroup's overall
  191. memory usage for the memory controller (for the purpose of
  192. statistics reporting and memory protetion). This is a new
  193. behavior that could regress existing setups, so it must be
  194. explicitly opted in with this mount option.
  195. A few caveats to keep in mind:
  196. * There is no HugeTLB pool management involved in the memory
  197. controller. The pre-allocated pool does not belong to anyone.
  198. Specifically, when a new HugeTLB folio is allocated to
  199. the pool, it is not accounted for from the perspective of the
  200. memory controller. It is only charged to a cgroup when it is
  201. actually used (for e.g at page fault time). Host memory
  202. overcommit management has to consider this when configuring
  203. hard limits. In general, HugeTLB pool management should be
  204. done via other mechanisms (such as the HugeTLB controller).
  205. * Failure to charge a HugeTLB folio to the memory controller
  206. results in SIGBUS. This could happen even if the HugeTLB pool
  207. still has pages available (but the cgroup limit is hit and
  208. reclaim attempt fails).
  209. * Charging HugeTLB memory towards the memory controller affects
  210. memory protection and reclaim dynamics. Any userspace tuning
  211. (of low, min limits for e.g) needs to take this into account.
  212. * HugeTLB pages utilized while this option is not selected
  213. will not be tracked by the memory controller (even if cgroup
  214. v2 is remounted later on).
  215. pids_localevents
  216. The option restores v1-like behavior of pids.events:max, that is only
  217. local (inside cgroup proper) fork failures are counted. Without this
  218. option pids.events.max represents any pids.max enforcemnt across
  219. cgroup's subtree.
  220. Organizing Processes and Threads
  221. --------------------------------
  222. Processes
  223. ~~~~~~~~~
  224. Initially, only the root cgroup exists to which all processes belong.
  225. A child cgroup can be created by creating a sub-directory::
  226. # mkdir $CGROUP_NAME
  227. A given cgroup may have multiple child cgroups forming a tree
  228. structure. Each cgroup has a read-writable interface file
  229. "cgroup.procs". When read, it lists the PIDs of all processes which
  230. belong to the cgroup one-per-line. The PIDs are not ordered and the
  231. same PID may show up more than once if the process got moved to
  232. another cgroup and then back or the PID got recycled while reading.
  233. A process can be migrated into a cgroup by writing its PID to the
  234. target cgroup's "cgroup.procs" file. Only one process can be migrated
  235. on a single write(2) call. If a process is composed of multiple
  236. threads, writing the PID of any thread migrates all threads of the
  237. process.
  238. When a process forks a child process, the new process is born into the
  239. cgroup that the forking process belongs to at the time of the
  240. operation. After exit, a process stays associated with the cgroup
  241. that it belonged to at the time of exit until it's reaped; however, a
  242. zombie process does not appear in "cgroup.procs" and thus can't be
  243. moved to another cgroup.
  244. A cgroup which doesn't have any children or live processes can be
  245. destroyed by removing the directory. Note that a cgroup which doesn't
  246. have any children and is associated only with zombie processes is
  247. considered empty and can be removed::
  248. # rmdir $CGROUP_NAME
  249. "/proc/$PID/cgroup" lists a process's cgroup membership. If legacy
  250. cgroup is in use in the system, this file may contain multiple lines,
  251. one for each hierarchy. The entry for cgroup v2 is always in the
  252. format "0::$PATH"::
  253. # cat /proc/842/cgroup
  254. ...
  255. 0::/test-cgroup/test-cgroup-nested
  256. If the process becomes a zombie and the cgroup it was associated with
  257. is removed subsequently, " (deleted)" is appended to the path::
  258. # cat /proc/842/cgroup
  259. ...
  260. 0::/test-cgroup/test-cgroup-nested (deleted)
  261. Threads
  262. ~~~~~~~
  263. cgroup v2 supports thread granularity for a subset of controllers to
  264. support use cases requiring hierarchical resource distribution across
  265. the threads of a group of processes. By default, all threads of a
  266. process belong to the same cgroup, which also serves as the resource
  267. domain to host resource consumptions which are not specific to a
  268. process or thread. The thread mode allows threads to be spread across
  269. a subtree while still maintaining the common resource domain for them.
  270. Controllers which support thread mode are called threaded controllers.
  271. The ones which don't are called domain controllers.
  272. Marking a cgroup threaded makes it join the resource domain of its
  273. parent as a threaded cgroup. The parent may be another threaded
  274. cgroup whose resource domain is further up in the hierarchy. The root
  275. of a threaded subtree, that is, the nearest ancestor which is not
  276. threaded, is called threaded domain or thread root interchangeably and
  277. serves as the resource domain for the entire subtree.
  278. Inside a threaded subtree, threads of a process can be put in
  279. different cgroups and are not subject to the no internal process
  280. constraint - threaded controllers can be enabled on non-leaf cgroups
  281. whether they have threads in them or not.
  282. As the threaded domain cgroup hosts all the domain resource
  283. consumptions of the subtree, it is considered to have internal
  284. resource consumptions whether there are processes in it or not and
  285. can't have populated child cgroups which aren't threaded. Because the
  286. root cgroup is not subject to no internal process constraint, it can
  287. serve both as a threaded domain and a parent to domain cgroups.
  288. The current operation mode or type of the cgroup is shown in the
  289. "cgroup.type" file which indicates whether the cgroup is a normal
  290. domain, a domain which is serving as the domain of a threaded subtree,
  291. or a threaded cgroup.
  292. On creation, a cgroup is always a domain cgroup and can be made
  293. threaded by writing "threaded" to the "cgroup.type" file. The
  294. operation is single direction::
  295. # echo threaded > cgroup.type
  296. Once threaded, the cgroup can't be made a domain again. To enable the
  297. thread mode, the following conditions must be met.
  298. - As the cgroup will join the parent's resource domain. The parent
  299. must either be a valid (threaded) domain or a threaded cgroup.
  300. - When the parent is an unthreaded domain, it must not have any domain
  301. controllers enabled or populated domain children. The root is
  302. exempt from this requirement.
  303. Topology-wise, a cgroup can be in an invalid state. Please consider
  304. the following topology::
  305. A (threaded domain) - B (threaded) - C (domain, just created)
  306. C is created as a domain but isn't connected to a parent which can
  307. host child domains. C can't be used until it is turned into a
  308. threaded cgroup. "cgroup.type" file will report "domain (invalid)" in
  309. these cases. Operations which fail due to invalid topology use
  310. EOPNOTSUPP as the errno.
  311. A domain cgroup is turned into a threaded domain when one of its child
  312. cgroup becomes threaded or threaded controllers are enabled in the
  313. "cgroup.subtree_control" file while there are processes in the cgroup.
  314. A threaded domain reverts to a normal domain when the conditions
  315. clear.
  316. When read, "cgroup.threads" contains the list of the thread IDs of all
  317. threads in the cgroup. Except that the operations are per-thread
  318. instead of per-process, "cgroup.threads" has the same format and
  319. behaves the same way as "cgroup.procs". While "cgroup.threads" can be
  320. written to in any cgroup, as it can only move threads inside the same
  321. threaded domain, its operations are confined inside each threaded
  322. subtree.
  323. The threaded domain cgroup serves as the resource domain for the whole
  324. subtree, and, while the threads can be scattered across the subtree,
  325. all the processes are considered to be in the threaded domain cgroup.
  326. "cgroup.procs" in a threaded domain cgroup contains the PIDs of all
  327. processes in the subtree and is not readable in the subtree proper.
  328. However, "cgroup.procs" can be written to from anywhere in the subtree
  329. to migrate all threads of the matching process to the cgroup.
  330. Only threaded controllers can be enabled in a threaded subtree. When
  331. a threaded controller is enabled inside a threaded subtree, it only
  332. accounts for and controls resource consumptions associated with the
  333. threads in the cgroup and its descendants. All consumptions which
  334. aren't tied to a specific thread belong to the threaded domain cgroup.
  335. Because a threaded subtree is exempt from no internal process
  336. constraint, a threaded controller must be able to handle competition
  337. between threads in a non-leaf cgroup and its child cgroups. Each
  338. threaded controller defines how such competitions are handled.
  339. Currently, the following controllers are threaded and can be enabled
  340. in a threaded cgroup::
  341. - cpu
  342. - cpuset
  343. - perf_event
  344. - pids
  345. [Un]populated Notification
  346. --------------------------
  347. Each non-root cgroup has a "cgroup.events" file which contains
  348. "populated" field indicating whether the cgroup's sub-hierarchy has
  349. live processes in it. Its value is 0 if there is no live process in
  350. the cgroup and its descendants; otherwise, 1. poll and [id]notify
  351. events are triggered when the value changes. This can be used, for
  352. example, to start a clean-up operation after all processes of a given
  353. sub-hierarchy have exited. The populated state updates and
  354. notifications are recursive. Consider the following sub-hierarchy
  355. where the numbers in the parentheses represent the numbers of processes
  356. in each cgroup::
  357. A(4) - B(0) - C(1)
  358. \ D(0)
  359. A, B and C's "populated" fields would be 1 while D's 0. After the one
  360. process in C exits, B and C's "populated" fields would flip to "0" and
  361. file modified events will be generated on the "cgroup.events" files of
  362. both cgroups.
  363. Controlling Controllers
  364. -----------------------
  365. Availability
  366. ~~~~~~~~~~~~
  367. A controller is available in a cgroup when it is supported by the kernel (i.e.,
  368. compiled in, not disabled and not attached to a v1 hierarchy) and listed in the
  369. "cgroup.controllers" file. Availability means the controller's interface files
  370. are exposed in the cgroup’s directory, allowing the distribution of the target
  371. resource to be observed or controlled within that cgroup.
  372. Enabling and Disabling
  373. ~~~~~~~~~~~~~~~~~~~~~~
  374. Each cgroup has a "cgroup.controllers" file which lists all
  375. controllers available for the cgroup to enable::
  376. # cat cgroup.controllers
  377. cpu io memory
  378. No controller is enabled by default. Controllers can be enabled and
  379. disabled by writing to the "cgroup.subtree_control" file::
  380. # echo "+cpu +memory -io" > cgroup.subtree_control
  381. Only controllers which are listed in "cgroup.controllers" can be
  382. enabled. When multiple operations are specified as above, either they
  383. all succeed or fail. If multiple operations on the same controller
  384. are specified, the last one is effective.
  385. Enabling a controller in a cgroup indicates that the distribution of
  386. the target resource across its immediate children will be controlled.
  387. Consider the following sub-hierarchy. The enabled controllers are
  388. listed in parentheses::
  389. A(cpu,memory) - B(memory) - C()
  390. \ D()
  391. As A has "cpu" and "memory" enabled, A will control the distribution
  392. of CPU cycles and memory to its children, in this case, B. As B has
  393. "memory" enabled but not "CPU", C and D will compete freely on CPU
  394. cycles but their division of memory available to B will be controlled.
  395. As a controller regulates the distribution of the target resource to
  396. the cgroup's children, enabling it creates the controller's interface
  397. files in the child cgroups. In the above example, enabling "cpu" on B
  398. would create the "cpu." prefixed controller interface files in C and
  399. D. Likewise, disabling "memory" from B would remove the "memory."
  400. prefixed controller interface files from C and D. This means that the
  401. controller interface files - anything which doesn't start with
  402. "cgroup." are owned by the parent rather than the cgroup itself.
  403. Top-down Constraint
  404. ~~~~~~~~~~~~~~~~~~~
  405. Resources are distributed top-down and a cgroup can further distribute
  406. a resource only if the resource has been distributed to it from the
  407. parent. This means that all non-root "cgroup.subtree_control" files
  408. can only contain controllers which are enabled in the parent's
  409. "cgroup.subtree_control" file. A controller can be enabled only if
  410. the parent has the controller enabled and a controller can't be
  411. disabled if one or more children have it enabled.
  412. No Internal Process Constraint
  413. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  414. Non-root cgroups can distribute domain resources to their children
  415. only when they don't have any processes of their own. In other words,
  416. only domain cgroups which don't contain any processes can have domain
  417. controllers enabled in their "cgroup.subtree_control" files.
  418. This guarantees that, when a domain controller is looking at the part
  419. of the hierarchy which has it enabled, processes are always only on
  420. the leaves. This rules out situations where child cgroups compete
  421. against internal processes of the parent.
  422. The root cgroup is exempt from this restriction. Root contains
  423. processes and anonymous resource consumption which can't be associated
  424. with any other cgroups and requires special treatment from most
  425. controllers. How resource consumption in the root cgroup is governed
  426. is up to each controller (for more information on this topic please
  427. refer to the Non-normative information section in the Controllers
  428. chapter).
  429. Note that the restriction doesn't get in the way if there is no
  430. enabled controller in the cgroup's "cgroup.subtree_control". This is
  431. important as otherwise it wouldn't be possible to create children of a
  432. populated cgroup. To control resource distribution of a cgroup, the
  433. cgroup must create children and transfer all its processes to the
  434. children before enabling controllers in its "cgroup.subtree_control"
  435. file.
  436. Delegation
  437. ----------
  438. Model of Delegation
  439. ~~~~~~~~~~~~~~~~~~~
  440. A cgroup can be delegated in two ways. First, to a less privileged
  441. user by granting write access of the directory and its "cgroup.procs",
  442. "cgroup.threads" and "cgroup.subtree_control" files to the user.
  443. Second, if the "nsdelegate" mount option is set, automatically to a
  444. cgroup namespace on namespace creation.
  445. Because the resource control interface files in a given directory
  446. control the distribution of the parent's resources, the delegatee
  447. shouldn't be allowed to write to them. For the first method, this is
  448. achieved by not granting access to these files. For the second, files
  449. outside the namespace should be hidden from the delegatee by the means
  450. of at least mount namespacing, and the kernel rejects writes to all
  451. files on a namespace root from inside the cgroup namespace, except for
  452. those files listed in "/sys/kernel/cgroup/delegate" (including
  453. "cgroup.procs", "cgroup.threads", "cgroup.subtree_control", etc.).
  454. The end results are equivalent for both delegation types. Once
  455. delegated, the user can build sub-hierarchy under the directory,
  456. organize processes inside it as it sees fit and further distribute the
  457. resources it received from the parent. The limits and other settings
  458. of all resource controllers are hierarchical and regardless of what
  459. happens in the delegated sub-hierarchy, nothing can escape the
  460. resource restrictions imposed by the parent.
  461. Currently, cgroup doesn't impose any restrictions on the number of
  462. cgroups in or nesting depth of a delegated sub-hierarchy; however,
  463. this may be limited explicitly in the future.
  464. Delegation Containment
  465. ~~~~~~~~~~~~~~~~~~~~~~
  466. A delegated sub-hierarchy is contained in the sense that processes
  467. can't be moved into or out of the sub-hierarchy by the delegatee.
  468. For delegations to a less privileged user, this is achieved by
  469. requiring the following conditions for a process with a non-root euid
  470. to migrate a target process into a cgroup by writing its PID to the
  471. "cgroup.procs" file.
  472. - The writer must have write access to the "cgroup.procs" file.
  473. - The writer must have write access to the "cgroup.procs" file of the
  474. common ancestor of the source and destination cgroups.
  475. The above two constraints ensure that while a delegatee may migrate
  476. processes around freely in the delegated sub-hierarchy it can't pull
  477. in from or push out to outside the sub-hierarchy.
  478. For an example, let's assume cgroups C0 and C1 have been delegated to
  479. user U0 who created C00, C01 under C0 and C10 under C1 as follows and
  480. all processes under C0 and C1 belong to U0::
  481. ~~~~~~~~~~~~~ - C0 - C00
  482. ~ cgroup ~ \ C01
  483. ~ hierarchy ~
  484. ~~~~~~~~~~~~~ - C1 - C10
  485. Let's also say U0 wants to write the PID of a process which is
  486. currently in C10 into "C00/cgroup.procs". U0 has write access to the
  487. file; however, the common ancestor of the source cgroup C10 and the
  488. destination cgroup C00 is above the points of delegation and U0 would
  489. not have write access to its "cgroup.procs" files and thus the write
  490. will be denied with -EACCES.
  491. For delegations to namespaces, containment is achieved by requiring
  492. that both the source and destination cgroups are reachable from the
  493. namespace of the process which is attempting the migration. If either
  494. is not reachable, the migration is rejected with -ENOENT.
  495. Guidelines
  496. ----------
  497. Organize Once and Control
  498. ~~~~~~~~~~~~~~~~~~~~~~~~~
  499. Migrating a process across cgroups is a relatively expensive operation
  500. and stateful resources such as memory are not moved together with the
  501. process. This is an explicit design decision as there often exist
  502. inherent trade-offs between migration and various hot paths in terms
  503. of synchronization cost.
  504. As such, migrating processes across cgroups frequently as a means to
  505. apply different resource restrictions is discouraged. A workload
  506. should be assigned to a cgroup according to the system's logical and
  507. resource structure once on start-up. Dynamic adjustments to resource
  508. distribution can be made by changing controller configuration through
  509. the interface files.
  510. Avoid Name Collisions
  511. ~~~~~~~~~~~~~~~~~~~~~
  512. Interface files for a cgroup and its children cgroups occupy the same
  513. directory and it is possible to create children cgroups which collide
  514. with interface files.
  515. All cgroup core interface files are prefixed with "cgroup." and each
  516. controller's interface files are prefixed with the controller name and
  517. a dot. A controller's name is composed of lower case alphabets and
  518. '_'s but never begins with an '_' so it can be used as the prefix
  519. character for collision avoidance. Also, interface file names won't
  520. start or end with terms which are often used in categorizing workloads
  521. such as job, service, slice, unit or workload.
  522. cgroup doesn't do anything to prevent name collisions and it's the
  523. user's responsibility to avoid them.
  524. Resource Distribution Models
  525. ============================
  526. cgroup controllers implement several resource distribution schemes
  527. depending on the resource type and expected use cases. This section
  528. describes major schemes in use along with their expected behaviors.
  529. Weights
  530. -------
  531. A parent's resource is distributed by adding up the weights of all
  532. active children and giving each the fraction matching the ratio of its
  533. weight against the sum. As only children which can make use of the
  534. resource at the moment participate in the distribution, this is
  535. work-conserving. Due to the dynamic nature, this model is usually
  536. used for stateless resources.
  537. All weights are in the range [1, 10000] with the default at 100. This
  538. allows symmetric multiplicative biases in both directions at fine
  539. enough granularity while staying in the intuitive range.
  540. As long as the weight is in range, all configuration combinations are
  541. valid and there is no reason to reject configuration changes or
  542. process migrations.
  543. "cpu.weight" proportionally distributes CPU cycles to active children
  544. and is an example of this type.
  545. .. _cgroupv2-limits-distributor:
  546. Limits
  547. ------
  548. A child can only consume up to the configured amount of the resource.
  549. Limits can be over-committed - the sum of the limits of children can
  550. exceed the amount of resource available to the parent.
  551. Limits are in the range [0, max] and defaults to "max", which is noop.
  552. As limits can be over-committed, all configuration combinations are
  553. valid and there is no reason to reject configuration changes or
  554. process migrations.
  555. "io.max" limits the maximum BPS and/or IOPS that a cgroup can consume
  556. on an IO device and is an example of this type.
  557. .. _cgroupv2-protections-distributor:
  558. Protections
  559. -----------
  560. A cgroup is protected up to the configured amount of the resource
  561. as long as the usages of all its ancestors are under their
  562. protected levels. Protections can be hard guarantees or best effort
  563. soft boundaries. Protections can also be over-committed in which case
  564. only up to the amount available to the parent is protected among
  565. children.
  566. Protections are in the range [0, max] and defaults to 0, which is
  567. noop.
  568. As protections can be over-committed, all configuration combinations
  569. are valid and there is no reason to reject configuration changes or
  570. process migrations.
  571. "memory.low" implements best-effort memory protection and is an
  572. example of this type.
  573. Allocations
  574. -----------
  575. A cgroup is exclusively allocated a certain amount of a finite
  576. resource. Allocations can't be over-committed - the sum of the
  577. allocations of children can not exceed the amount of resource
  578. available to the parent.
  579. Allocations are in the range [0, max] and defaults to 0, which is no
  580. resource.
  581. As allocations can't be over-committed, some configuration
  582. combinations are invalid and should be rejected. Also, if the
  583. resource is mandatory for execution of processes, process migrations
  584. may be rejected.
  585. Interface Files
  586. ===============
  587. Format
  588. ------
  589. All interface files should be in one of the following formats whenever
  590. possible::
  591. New-line separated values
  592. (when only one value can be written at once)
  593. VAL0\n
  594. VAL1\n
  595. ...
  596. Space separated values
  597. (when read-only or multiple values can be written at once)
  598. VAL0 VAL1 ...\n
  599. Flat keyed
  600. KEY0 VAL0\n
  601. KEY1 VAL1\n
  602. ...
  603. Nested keyed
  604. KEY0 SUB_KEY0=VAL00 SUB_KEY1=VAL01...
  605. KEY1 SUB_KEY0=VAL10 SUB_KEY1=VAL11...
  606. ...
  607. For a writable file, the format for writing should generally match
  608. reading; however, controllers may allow omitting later fields or
  609. implement restricted shortcuts for most common use cases.
  610. For both flat and nested keyed files, only the values for a single key
  611. can be written at a time. For nested keyed files, the sub key pairs
  612. may be specified in any order and not all pairs have to be specified.
  613. Conventions
  614. -----------
  615. - Settings for a single feature should be contained in a single file.
  616. - The root cgroup should be exempt from resource control and thus
  617. shouldn't have resource control interface files.
  618. - The default time unit is microseconds. If a different unit is ever
  619. used, an explicit unit suffix must be present.
  620. - A parts-per quantity should use a percentage decimal with at least
  621. two digit fractional part - e.g. 13.40.
  622. - If a controller implements weight based resource distribution, its
  623. interface file should be named "weight" and have the range [1,
  624. 10000] with 100 as the default. The values are chosen to allow
  625. enough and symmetric bias in both directions while keeping it
  626. intuitive (the default is 100%).
  627. - If a controller implements an absolute resource guarantee and/or
  628. limit, the interface files should be named "min" and "max"
  629. respectively. If a controller implements best effort resource
  630. guarantee and/or limit, the interface files should be named "low"
  631. and "high" respectively.
  632. In the above four control files, the special token "max" should be
  633. used to represent upward infinity for both reading and writing.
  634. - If a setting has a configurable default value and keyed specific
  635. overrides, the default entry should be keyed with "default" and
  636. appear as the first entry in the file.
  637. The default value can be updated by writing either "default $VAL" or
  638. "$VAL".
  639. When writing to update a specific override, "default" can be used as
  640. the value to indicate removal of the override. Override entries
  641. with "default" as the value must not appear when read.
  642. For example, a setting which is keyed by major:minor device numbers
  643. with integer values may look like the following::
  644. # cat cgroup-example-interface-file
  645. default 150
  646. 8:0 300
  647. The default value can be updated by::
  648. # echo 125 > cgroup-example-interface-file
  649. or::
  650. # echo "default 125" > cgroup-example-interface-file
  651. An override can be set by::
  652. # echo "8:16 170" > cgroup-example-interface-file
  653. and cleared by::
  654. # echo "8:0 default" > cgroup-example-interface-file
  655. # cat cgroup-example-interface-file
  656. default 125
  657. 8:16 170
  658. - For events which are not very high frequency, an interface file
  659. "events" should be created which lists event key value pairs.
  660. Whenever a notifiable event happens, file modified event should be
  661. generated on the file.
  662. Core Interface Files
  663. --------------------
  664. All cgroup core files are prefixed with "cgroup."
  665. cgroup.type
  666. A read-write single value file which exists on non-root
  667. cgroups.
  668. When read, it indicates the current type of the cgroup, which
  669. can be one of the following values.
  670. - "domain" : A normal valid domain cgroup.
  671. - "domain threaded" : A threaded domain cgroup which is
  672. serving as the root of a threaded subtree.
  673. - "domain invalid" : A cgroup which is in an invalid state.
  674. It can't be populated or have controllers enabled. It may
  675. be allowed to become a threaded cgroup.
  676. - "threaded" : A threaded cgroup which is a member of a
  677. threaded subtree.
  678. A cgroup can be turned into a threaded cgroup by writing
  679. "threaded" to this file.
  680. cgroup.procs
  681. A read-write new-line separated values file which exists on
  682. all cgroups.
  683. When read, it lists the PIDs of all processes which belong to
  684. the cgroup one-per-line. The PIDs are not ordered and the
  685. same PID may show up more than once if the process got moved
  686. to another cgroup and then back or the PID got recycled while
  687. reading.
  688. A PID can be written to migrate the process associated with
  689. the PID to the cgroup. The writer should match all of the
  690. following conditions.
  691. - It must have write access to the "cgroup.procs" file.
  692. - It must have write access to the "cgroup.procs" file of the
  693. common ancestor of the source and destination cgroups.
  694. When delegating a sub-hierarchy, write access to this file
  695. should be granted along with the containing directory.
  696. In a threaded cgroup, reading this file fails with EOPNOTSUPP
  697. as all the processes belong to the thread root. Writing is
  698. supported and moves every thread of the process to the cgroup.
  699. cgroup.threads
  700. A read-write new-line separated values file which exists on
  701. all cgroups.
  702. When read, it lists the TIDs of all threads which belong to
  703. the cgroup one-per-line. The TIDs are not ordered and the
  704. same TID may show up more than once if the thread got moved to
  705. another cgroup and then back or the TID got recycled while
  706. reading.
  707. A TID can be written to migrate the thread associated with the
  708. TID to the cgroup. The writer should match all of the
  709. following conditions.
  710. - It must have write access to the "cgroup.threads" file.
  711. - The cgroup that the thread is currently in must be in the
  712. same resource domain as the destination cgroup.
  713. - It must have write access to the "cgroup.procs" file of the
  714. common ancestor of the source and destination cgroups.
  715. When delegating a sub-hierarchy, write access to this file
  716. should be granted along with the containing directory.
  717. cgroup.controllers
  718. A read-only space separated values file which exists on all
  719. cgroups.
  720. It shows space separated list of all controllers available to
  721. the cgroup. The controllers are not ordered.
  722. cgroup.subtree_control
  723. A read-write space separated values file which exists on all
  724. cgroups. Starts out empty.
  725. When read, it shows space separated list of the controllers
  726. which are enabled to control resource distribution from the
  727. cgroup to its children.
  728. Space separated list of controllers prefixed with '+' or '-'
  729. can be written to enable or disable controllers. A controller
  730. name prefixed with '+' enables the controller and '-'
  731. disables. If a controller appears more than once on the list,
  732. the last one is effective. When multiple enable and disable
  733. operations are specified, either all succeed or all fail.
  734. cgroup.events
  735. A read-only flat-keyed file which exists on non-root cgroups.
  736. The following entries are defined. Unless specified
  737. otherwise, a value change in this file generates a file
  738. modified event.
  739. populated
  740. 1 if the cgroup or its descendants contains any live
  741. processes; otherwise, 0.
  742. frozen
  743. 1 if the cgroup is frozen; otherwise, 0.
  744. cgroup.max.descendants
  745. A read-write single value files. The default is "max".
  746. Maximum allowed number of descent cgroups.
  747. If the actual number of descendants is equal or larger,
  748. an attempt to create a new cgroup in the hierarchy will fail.
  749. cgroup.max.depth
  750. A read-write single value files. The default is "max".
  751. Maximum allowed descent depth below the current cgroup.
  752. If the actual descent depth is equal or larger,
  753. an attempt to create a new child cgroup will fail.
  754. cgroup.stat
  755. A read-only flat-keyed file with the following entries:
  756. nr_descendants
  757. Total number of visible descendant cgroups.
  758. nr_dying_descendants
  759. Total number of dying descendant cgroups. A cgroup becomes
  760. dying after being deleted by a user. The cgroup will remain
  761. in dying state for some time undefined time (which can depend
  762. on system load) before being completely destroyed.
  763. A process can't enter a dying cgroup under any circumstances,
  764. a dying cgroup can't revive.
  765. A dying cgroup can consume system resources not exceeding
  766. limits, which were active at the moment of cgroup deletion.
  767. nr_subsys_<cgroup_subsys>
  768. Total number of live cgroup subsystems (e.g memory
  769. cgroup) at and beneath the current cgroup.
  770. nr_dying_subsys_<cgroup_subsys>
  771. Total number of dying cgroup subsystems (e.g. memory
  772. cgroup) at and beneath the current cgroup.
  773. cgroup.stat.local
  774. A read-only flat-keyed file which exists in non-root cgroups.
  775. The following entry is defined:
  776. frozen_usec
  777. Cumulative time that this cgroup has spent between freezing and
  778. thawing, regardless of whether by self or ancestor groups.
  779. NB: (not) reaching "frozen" state is not accounted here.
  780. Using the following ASCII representation of a cgroup's freezer
  781. state, ::
  782. 1 _____
  783. frozen 0 __/ \__
  784. ab cd
  785. the duration being measured is the span between a and c.
  786. cgroup.freeze
  787. A read-write single value file which exists on non-root cgroups.
  788. Allowed values are "0" and "1". The default is "0".
  789. Writing "1" to the file causes freezing of the cgroup and all
  790. descendant cgroups. This means that all belonging processes will
  791. be stopped and will not run until the cgroup will be explicitly
  792. unfrozen. Freezing of the cgroup may take some time; when this action
  793. is completed, the "frozen" value in the cgroup.events control file
  794. will be updated to "1" and the corresponding notification will be
  795. issued.
  796. A cgroup can be frozen either by its own settings, or by settings
  797. of any ancestor cgroups. If any of ancestor cgroups is frozen, the
  798. cgroup will remain frozen.
  799. Processes in the frozen cgroup can be killed by a fatal signal.
  800. They also can enter and leave a frozen cgroup: either by an explicit
  801. move by a user, or if freezing of the cgroup races with fork().
  802. If a process is moved to a frozen cgroup, it stops. If a process is
  803. moved out of a frozen cgroup, it becomes running.
  804. Frozen status of a cgroup doesn't affect any cgroup tree operations:
  805. it's possible to delete a frozen (and empty) cgroup, as well as
  806. create new sub-cgroups.
  807. cgroup.kill
  808. A write-only single value file which exists in non-root cgroups.
  809. The only allowed value is "1".
  810. Writing "1" to the file causes the cgroup and all descendant cgroups to
  811. be killed. This means that all processes located in the affected cgroup
  812. tree will be killed via SIGKILL.
  813. Killing a cgroup tree will deal with concurrent forks appropriately and
  814. is protected against migrations.
  815. In a threaded cgroup, writing this file fails with EOPNOTSUPP as
  816. killing cgroups is a process directed operation, i.e. it affects
  817. the whole thread-group.
  818. cgroup.pressure
  819. A read-write single value file that allowed values are "0" and "1".
  820. The default is "1".
  821. Writing "0" to the file will disable the cgroup PSI accounting.
  822. Writing "1" to the file will re-enable the cgroup PSI accounting.
  823. This control attribute is not hierarchical, so disable or enable PSI
  824. accounting in a cgroup does not affect PSI accounting in descendants
  825. and doesn't need pass enablement via ancestors from root.
  826. The reason this control attribute exists is that PSI accounts stalls for
  827. each cgroup separately and aggregates it at each level of the hierarchy.
  828. This may cause non-negligible overhead for some workloads when under
  829. deep level of the hierarchy, in which case this control attribute can
  830. be used to disable PSI accounting in the non-leaf cgroups.
  831. irq.pressure
  832. A read-write nested-keyed file.
  833. Shows pressure stall information for IRQ/SOFTIRQ. See
  834. :ref:`Documentation/accounting/psi.rst <psi>` for details.
  835. Controllers
  836. ===========
  837. .. _cgroup-v2-cpu:
  838. CPU
  839. ---
  840. The "cpu" controllers regulates distribution of CPU cycles. This
  841. controller implements weight and absolute bandwidth limit models for
  842. normal scheduling policy and absolute bandwidth allocation model for
  843. realtime scheduling policy.
  844. In all the above models, cycles distribution is defined only on a temporal
  845. base and it does not account for the frequency at which tasks are executed.
  846. The (optional) utilization clamping support allows to hint the schedutil
  847. cpufreq governor about the minimum desired frequency which should always be
  848. provided by a CPU, as well as the maximum desired frequency, which should not
  849. be exceeded by a CPU.
  850. WARNING: cgroup2 cpu controller doesn't yet support the (bandwidth) control of
  851. realtime processes. For a kernel built with the CONFIG_RT_GROUP_SCHED option
  852. enabled for group scheduling of realtime processes, the cpu controller can only
  853. be enabled when all RT processes are in the root cgroup. Be aware that system
  854. management software may already have placed RT processes into non-root cgroups
  855. during the system boot process, and these processes may need to be moved to the
  856. root cgroup before the cpu controller can be enabled with a
  857. CONFIG_RT_GROUP_SCHED enabled kernel.
  858. With CONFIG_RT_GROUP_SCHED disabled, this limitation does not apply and some of
  859. the interface files either affect realtime processes or account for them. See
  860. the following section for details. Only the cpu controller is affected by
  861. CONFIG_RT_GROUP_SCHED. Other controllers can be used for the resource control of
  862. realtime processes irrespective of CONFIG_RT_GROUP_SCHED.
  863. CPU Interface Files
  864. ~~~~~~~~~~~~~~~~~~~
  865. The interaction of a process with the cpu controller depends on its scheduling
  866. policy and the underlying scheduler. From the point of view of the cpu controller,
  867. processes can be categorized as follows:
  868. * Processes under the fair-class scheduler
  869. * Processes under a BPF scheduler with the ``cgroup_set_weight`` callback
  870. * Everything else: ``SCHED_{FIFO,RR,DEADLINE}`` and processes under a BPF scheduler
  871. without the ``cgroup_set_weight`` callback
  872. For details on when a process is under the fair-class scheduler or a BPF scheduler,
  873. check out :ref:`Documentation/scheduler/sched-ext.rst <sched-ext>`.
  874. For each of the following interface files, the above categories
  875. will be referred to. All time durations are in microseconds.
  876. cpu.stat
  877. A read-only flat-keyed file.
  878. This file exists whether the controller is enabled or not.
  879. It always reports the following three stats, which account for all the
  880. processes in the cgroup:
  881. - usage_usec
  882. - user_usec
  883. - system_usec
  884. and the following five when the controller is enabled, which account for
  885. only the processes under the fair-class scheduler:
  886. - nr_periods
  887. - nr_throttled
  888. - throttled_usec
  889. - nr_bursts
  890. - burst_usec
  891. cpu.weight
  892. A read-write single value file which exists on non-root
  893. cgroups. The default is "100".
  894. For non idle groups (cpu.idle = 0), the weight is in the
  895. range [1, 10000].
  896. If the cgroup has been configured to be SCHED_IDLE (cpu.idle = 1),
  897. then the weight will show as a 0.
  898. This file affects only processes under the fair-class scheduler and a BPF
  899. scheduler with the ``cgroup_set_weight`` callback depending on what the
  900. callback actually does.
  901. cpu.weight.nice
  902. A read-write single value file which exists on non-root
  903. cgroups. The default is "0".
  904. The nice value is in the range [-20, 19].
  905. This interface file is an alternative interface for
  906. "cpu.weight" and allows reading and setting weight using the
  907. same values used by nice(2). Because the range is smaller and
  908. granularity is coarser for the nice values, the read value is
  909. the closest approximation of the current weight.
  910. This file affects only processes under the fair-class scheduler and a BPF
  911. scheduler with the ``cgroup_set_weight`` callback depending on what the
  912. callback actually does.
  913. cpu.max
  914. A read-write two value file which exists on non-root cgroups.
  915. The default is "max 100000".
  916. The maximum bandwidth limit. It's in the following format::
  917. $MAX $PERIOD
  918. which indicates that the group may consume up to $MAX in each
  919. $PERIOD duration. "max" for $MAX indicates no limit. If only
  920. one number is written, $MAX is updated.
  921. This file affects only processes under the fair-class scheduler.
  922. cpu.max.burst
  923. A read-write single value file which exists on non-root
  924. cgroups. The default is "0".
  925. The burst in the range [0, $MAX].
  926. This file affects only processes under the fair-class scheduler.
  927. cpu.pressure
  928. A read-write nested-keyed file.
  929. Shows pressure stall information for CPU. See
  930. :ref:`Documentation/accounting/psi.rst <psi>` for details.
  931. This file accounts for all the processes in the cgroup.
  932. cpu.uclamp.min
  933. A read-write single value file which exists on non-root cgroups.
  934. The default is "0", i.e. no utilization boosting.
  935. The requested minimum utilization (protection) as a percentage
  936. rational number, e.g. 12.34 for 12.34%.
  937. This interface allows reading and setting minimum utilization clamp
  938. values similar to the sched_setattr(2). This minimum utilization
  939. value is used to clamp the task specific minimum utilization clamp,
  940. including those of realtime processes.
  941. The requested minimum utilization (protection) is always capped by
  942. the current value for the maximum utilization (limit), i.e.
  943. `cpu.uclamp.max`.
  944. This file affects all the processes in the cgroup.
  945. cpu.uclamp.max
  946. A read-write single value file which exists on non-root cgroups.
  947. The default is "max". i.e. no utilization capping
  948. The requested maximum utilization (limit) as a percentage rational
  949. number, e.g. 98.76 for 98.76%.
  950. This interface allows reading and setting maximum utilization clamp
  951. values similar to the sched_setattr(2). This maximum utilization
  952. value is used to clamp the task specific maximum utilization clamp,
  953. including those of realtime processes.
  954. This file affects all the processes in the cgroup.
  955. cpu.idle
  956. A read-write single value file which exists on non-root cgroups.
  957. The default is 0.
  958. This is the cgroup analog of the per-task SCHED_IDLE sched policy.
  959. Setting this value to a 1 will make the scheduling policy of the
  960. cgroup SCHED_IDLE. The threads inside the cgroup will retain their
  961. own relative priorities, but the cgroup itself will be treated as
  962. very low priority relative to its peers.
  963. This file affects only processes under the fair-class scheduler.
  964. Memory
  965. ------
  966. The "memory" controller regulates distribution of memory. Memory is
  967. stateful and implements both limit and protection models. Due to the
  968. intertwining between memory usage and reclaim pressure and the
  969. stateful nature of memory, the distribution model is relatively
  970. complex.
  971. While not completely water-tight, all major memory usages by a given
  972. cgroup are tracked so that the total memory consumption can be
  973. accounted and controlled to a reasonable extent. Currently, the
  974. following types of memory usages are tracked.
  975. - Userland memory - page cache and anonymous memory.
  976. - Kernel data structures such as dentries and inodes.
  977. - TCP socket buffers.
  978. The above list may expand in the future for better coverage.
  979. Memory Interface Files
  980. ~~~~~~~~~~~~~~~~~~~~~~
  981. All memory amounts are in bytes. If a value which is not aligned to
  982. PAGE_SIZE is written, the value may be rounded up to the closest
  983. PAGE_SIZE multiple when read back.
  984. memory.current
  985. A read-only single value file which exists on non-root
  986. cgroups.
  987. The total amount of memory currently being used by the cgroup
  988. and its descendants.
  989. memory.min
  990. A read-write single value file which exists on non-root
  991. cgroups. The default is "0".
  992. Hard memory protection. If the memory usage of a cgroup
  993. is within its effective min boundary, the cgroup's memory
  994. won't be reclaimed under any conditions. If there is no
  995. unprotected reclaimable memory available, OOM killer
  996. is invoked. Above the effective min boundary (or
  997. effective low boundary if it is higher), pages are reclaimed
  998. proportionally to the overage, reducing reclaim pressure for
  999. smaller overages.
  1000. Effective min boundary is limited by memory.min values of
  1001. ancestor cgroups. If there is memory.min overcommitment
  1002. (child cgroup or cgroups are requiring more protected memory
  1003. than parent will allow), then each child cgroup will get
  1004. the part of parent's protection proportional to its
  1005. actual memory usage below memory.min.
  1006. Putting more memory than generally available under this
  1007. protection is discouraged and may lead to constant OOMs.
  1008. memory.low
  1009. A read-write single value file which exists on non-root
  1010. cgroups. The default is "0".
  1011. Best-effort memory protection. If the memory usage of a
  1012. cgroup is within its effective low boundary, the cgroup's
  1013. memory won't be reclaimed unless there is no reclaimable
  1014. memory available in unprotected cgroups.
  1015. Above the effective low boundary (or
  1016. effective min boundary if it is higher), pages are reclaimed
  1017. proportionally to the overage, reducing reclaim pressure for
  1018. smaller overages.
  1019. Effective low boundary is limited by memory.low values of
  1020. ancestor cgroups. If there is memory.low overcommitment
  1021. (child cgroup or cgroups are requiring more protected memory
  1022. than parent will allow), then each child cgroup will get
  1023. the part of parent's protection proportional to its
  1024. actual memory usage below memory.low.
  1025. Putting more memory than generally available under this
  1026. protection is discouraged.
  1027. memory.high
  1028. A read-write single value file which exists on non-root
  1029. cgroups. The default is "max".
  1030. Memory usage throttle limit. If a cgroup's usage goes
  1031. over the high boundary, the processes of the cgroup are
  1032. throttled and put under heavy reclaim pressure.
  1033. Going over the high limit never invokes the OOM killer and
  1034. under extreme conditions the limit may be breached. The high
  1035. limit should be used in scenarios where an external process
  1036. monitors the limited cgroup to alleviate heavy reclaim
  1037. pressure.
  1038. If memory.high is opened with O_NONBLOCK then the synchronous
  1039. reclaim is bypassed. This is useful for admin processes that
  1040. need to dynamically adjust the job's memory limits without
  1041. expending their own CPU resources on memory reclamation. The
  1042. job will trigger the reclaim and/or get throttled on its
  1043. next charge request.
  1044. Please note that with O_NONBLOCK, there is a chance that the
  1045. target memory cgroup may take indefinite amount of time to
  1046. reduce usage below the limit due to delayed charge request or
  1047. busy-hitting its memory to slow down reclaim.
  1048. memory.max
  1049. A read-write single value file which exists on non-root
  1050. cgroups. The default is "max".
  1051. Memory usage hard limit. This is the main mechanism to limit
  1052. memory usage of a cgroup. If a cgroup's memory usage reaches
  1053. this limit and can't be reduced, the OOM killer is invoked in
  1054. the cgroup. Under certain circumstances, the usage may go
  1055. over the limit temporarily.
  1056. In default configuration regular 0-order allocations always
  1057. succeed unless OOM killer chooses current task as a victim.
  1058. Some kinds of allocations don't invoke the OOM killer.
  1059. Caller could retry them differently, return into userspace
  1060. as -ENOMEM or silently ignore in cases like disk readahead.
  1061. If memory.max is opened with O_NONBLOCK, then the synchronous
  1062. reclaim and oom-kill are bypassed. This is useful for admin
  1063. processes that need to dynamically adjust the job's memory limits
  1064. without expending their own CPU resources on memory reclamation.
  1065. The job will trigger the reclaim and/or oom-kill on its next
  1066. charge request.
  1067. Please note that with O_NONBLOCK, there is a chance that the
  1068. target memory cgroup may take indefinite amount of time to
  1069. reduce usage below the limit due to delayed charge request or
  1070. busy-hitting its memory to slow down reclaim.
  1071. memory.reclaim
  1072. A write-only nested-keyed file which exists for all cgroups.
  1073. This is a simple interface to trigger memory reclaim in the
  1074. target cgroup.
  1075. Example::
  1076. echo "1G" > memory.reclaim
  1077. Please note that the kernel can over or under reclaim from
  1078. the target cgroup. If less bytes are reclaimed than the
  1079. specified amount, -EAGAIN is returned.
  1080. Please note that the proactive reclaim (triggered by this
  1081. interface) is not meant to indicate memory pressure on the
  1082. memory cgroup. Therefore socket memory balancing triggered by
  1083. the memory reclaim normally is not exercised in this case.
  1084. This means that the networking layer will not adapt based on
  1085. reclaim induced by memory.reclaim.
  1086. The following nested keys are defined.
  1087. ========== ================================
  1088. swappiness Swappiness value to reclaim with
  1089. ========== ================================
  1090. Specifying a swappiness value instructs the kernel to perform
  1091. the reclaim with that swappiness value. Note that this has the
  1092. same semantics as vm.swappiness applied to memcg reclaim with
  1093. all the existing limitations and potential future extensions.
  1094. The valid range for swappiness is [0-200, max], setting
  1095. swappiness=max exclusively reclaims anonymous memory.
  1096. memory.peak
  1097. A read-write single value file which exists on non-root cgroups.
  1098. The max memory usage recorded for the cgroup and its descendants since
  1099. either the creation of the cgroup or the most recent reset for that FD.
  1100. A write of any non-empty string to this file resets it to the
  1101. current memory usage for subsequent reads through the same
  1102. file descriptor.
  1103. memory.oom.group
  1104. A read-write single value file which exists on non-root
  1105. cgroups. The default value is "0".
  1106. Determines whether the cgroup should be treated as
  1107. an indivisible workload by the OOM killer. If set,
  1108. all tasks belonging to the cgroup or to its descendants
  1109. (if the memory cgroup is not a leaf cgroup) are killed
  1110. together or not at all. This can be used to avoid
  1111. partial kills to guarantee workload integrity.
  1112. Tasks with the OOM protection (oom_score_adj set to -1000)
  1113. are treated as an exception and are never killed.
  1114. If the OOM killer is invoked in a cgroup, it's not going
  1115. to kill any tasks outside of this cgroup, regardless
  1116. memory.oom.group values of ancestor cgroups.
  1117. memory.events
  1118. A read-only flat-keyed file which exists on non-root cgroups.
  1119. The following entries are defined. Unless specified
  1120. otherwise, a value change in this file generates a file
  1121. modified event.
  1122. Note that all fields in this file are hierarchical and the
  1123. file modified event can be generated due to an event down the
  1124. hierarchy. For the local events at the cgroup level see
  1125. memory.events.local.
  1126. low
  1127. The number of times the cgroup is reclaimed due to
  1128. high memory pressure even though its usage is under
  1129. the low boundary. This usually indicates that the low
  1130. boundary is over-committed.
  1131. high
  1132. The number of times processes of the cgroup are
  1133. throttled and routed to perform direct memory reclaim
  1134. because the high memory boundary was exceeded. For a
  1135. cgroup whose memory usage is capped by the high limit
  1136. rather than global memory pressure, this event's
  1137. occurrences are expected.
  1138. max
  1139. The number of times the cgroup's memory usage was
  1140. about to go over the max boundary. If direct reclaim
  1141. fails to bring it down, the cgroup goes to OOM state.
  1142. oom
  1143. The number of time the cgroup's memory usage was
  1144. reached the limit and allocation was about to fail.
  1145. This event is not raised if the OOM killer is not
  1146. considered as an option, e.g. for failed high-order
  1147. allocations or if caller asked to not retry attempts.
  1148. oom_kill
  1149. The number of processes belonging to this cgroup
  1150. killed by any kind of OOM killer.
  1151. oom_group_kill
  1152. The number of times a group OOM has occurred.
  1153. sock_throttled
  1154. The number of times network sockets associated with
  1155. this cgroup are throttled.
  1156. memory.events.local
  1157. Similar to memory.events but the fields in the file are local
  1158. to the cgroup i.e. not hierarchical. The file modified event
  1159. generated on this file reflects only the local events.
  1160. memory.stat
  1161. A read-only flat-keyed file which exists on non-root cgroups.
  1162. This breaks down the cgroup's memory footprint into different
  1163. types of memory, type-specific details, and other information
  1164. on the state and past events of the memory management system.
  1165. All memory amounts are in bytes.
  1166. The entries are ordered to be human readable, and new entries
  1167. can show up in the middle. Don't rely on items remaining in a
  1168. fixed position; use the keys to look up specific values!
  1169. If the entry has no per-node counter (or not show in the
  1170. memory.numa_stat). We use 'npn' (non-per-node) as the tag
  1171. to indicate that it will not show in the memory.numa_stat.
  1172. anon
  1173. Amount of memory used in anonymous mappings such as
  1174. brk(), sbrk(), and mmap(MAP_ANONYMOUS). Note that
  1175. some kernel configurations might account complete larger
  1176. allocations (e.g., THP) if only some, but not all the
  1177. memory of such an allocation is mapped anymore.
  1178. file
  1179. Amount of memory used to cache filesystem data,
  1180. including tmpfs and shared memory.
  1181. kernel (npn)
  1182. Amount of total kernel memory, including
  1183. (kernel_stack, pagetables, percpu, vmalloc, slab) in
  1184. addition to other kernel memory use cases.
  1185. kernel_stack
  1186. Amount of memory allocated to kernel stacks.
  1187. pagetables
  1188. Amount of memory allocated for page tables.
  1189. sec_pagetables
  1190. Amount of memory allocated for secondary page tables,
  1191. this currently includes KVM mmu allocations on x86
  1192. and arm64 and IOMMU page tables.
  1193. percpu (npn)
  1194. Amount of memory used for storing per-cpu kernel
  1195. data structures.
  1196. sock (npn)
  1197. Amount of memory used in network transmission buffers
  1198. vmalloc (npn)
  1199. Amount of memory used for vmap backed memory.
  1200. shmem
  1201. Amount of cached filesystem data that is swap-backed,
  1202. such as tmpfs, shm segments, shared anonymous mmap()s
  1203. zswap
  1204. Amount of memory consumed by the zswap compression backend.
  1205. zswapped
  1206. Amount of application memory swapped out to zswap.
  1207. file_mapped
  1208. Amount of cached filesystem data mapped with mmap(). Note
  1209. that some kernel configurations might account complete
  1210. larger allocations (e.g., THP) if only some, but not
  1211. not all the memory of such an allocation is mapped.
  1212. file_dirty
  1213. Amount of cached filesystem data that was modified but
  1214. not yet written back to disk
  1215. file_writeback
  1216. Amount of cached filesystem data that was modified and
  1217. is currently being written back to disk
  1218. swapcached
  1219. Amount of swap cached in memory. The swapcache is accounted
  1220. against both memory and swap usage.
  1221. anon_thp
  1222. Amount of memory used in anonymous mappings backed by
  1223. transparent hugepages
  1224. file_thp
  1225. Amount of cached filesystem data backed by transparent
  1226. hugepages
  1227. shmem_thp
  1228. Amount of shm, tmpfs, shared anonymous mmap()s backed by
  1229. transparent hugepages
  1230. inactive_anon, active_anon, inactive_file, active_file, unevictable
  1231. Amount of memory, swap-backed and filesystem-backed,
  1232. on the internal memory management lists used by the
  1233. page reclaim algorithm.
  1234. As these represent internal list state (eg. shmem pages are on anon
  1235. memory management lists), inactive_foo + active_foo may not be equal to
  1236. the value for the foo counter, since the foo counter is type-based, not
  1237. list-based.
  1238. slab_reclaimable
  1239. Part of "slab" that might be reclaimed, such as
  1240. dentries and inodes.
  1241. slab_unreclaimable
  1242. Part of "slab" that cannot be reclaimed on memory
  1243. pressure.
  1244. slab (npn)
  1245. Amount of memory used for storing in-kernel data
  1246. structures.
  1247. workingset_refault_anon
  1248. Number of refaults of previously evicted anonymous pages.
  1249. workingset_refault_file
  1250. Number of refaults of previously evicted file pages.
  1251. workingset_activate_anon
  1252. Number of refaulted anonymous pages that were immediately
  1253. activated.
  1254. workingset_activate_file
  1255. Number of refaulted file pages that were immediately activated.
  1256. workingset_restore_anon
  1257. Number of restored anonymous pages which have been detected as
  1258. an active workingset before they got reclaimed.
  1259. workingset_restore_file
  1260. Number of restored file pages which have been detected as an
  1261. active workingset before they got reclaimed.
  1262. workingset_nodereclaim
  1263. Number of times a shadow node has been reclaimed
  1264. pswpin (npn)
  1265. Number of pages swapped into memory
  1266. pswpout (npn)
  1267. Number of pages swapped out of memory
  1268. pgscan (npn)
  1269. Amount of scanned pages (in an inactive LRU list)
  1270. pgsteal (npn)
  1271. Amount of reclaimed pages
  1272. pgscan_kswapd (npn)
  1273. Amount of scanned pages by kswapd (in an inactive LRU list)
  1274. pgscan_direct (npn)
  1275. Amount of scanned pages directly (in an inactive LRU list)
  1276. pgscan_khugepaged (npn)
  1277. Amount of scanned pages by khugepaged (in an inactive LRU list)
  1278. pgscan_proactive (npn)
  1279. Amount of scanned pages proactively (in an inactive LRU list)
  1280. pgsteal_kswapd (npn)
  1281. Amount of reclaimed pages by kswapd
  1282. pgsteal_direct (npn)
  1283. Amount of reclaimed pages directly
  1284. pgsteal_khugepaged (npn)
  1285. Amount of reclaimed pages by khugepaged
  1286. pgsteal_proactive (npn)
  1287. Amount of reclaimed pages proactively
  1288. pgfault (npn)
  1289. Total number of page faults incurred
  1290. pgmajfault (npn)
  1291. Number of major page faults incurred
  1292. pgrefill (npn)
  1293. Amount of scanned pages (in an active LRU list)
  1294. pgactivate (npn)
  1295. Amount of pages moved to the active LRU list
  1296. pgdeactivate (npn)
  1297. Amount of pages moved to the inactive LRU list
  1298. pglazyfree (npn)
  1299. Amount of pages postponed to be freed under memory pressure
  1300. pglazyfreed (npn)
  1301. Amount of reclaimed lazyfree pages
  1302. swpin_zero
  1303. Number of pages swapped into memory and filled with zero, where I/O
  1304. was optimized out because the page content was detected to be zero
  1305. during swapout.
  1306. swpout_zero
  1307. Number of zero-filled pages swapped out with I/O skipped due to the
  1308. content being detected as zero.
  1309. zswpin
  1310. Number of pages moved in to memory from zswap.
  1311. zswpout
  1312. Number of pages moved out of memory to zswap.
  1313. zswpwb
  1314. Number of pages written from zswap to swap.
  1315. thp_fault_alloc (npn)
  1316. Number of transparent hugepages which were allocated to satisfy
  1317. a page fault. This counter is not present when CONFIG_TRANSPARENT_HUGEPAGE
  1318. is not set.
  1319. thp_collapse_alloc (npn)
  1320. Number of transparent hugepages which were allocated to allow
  1321. collapsing an existing range of pages. This counter is not
  1322. present when CONFIG_TRANSPARENT_HUGEPAGE is not set.
  1323. thp_swpout (npn)
  1324. Number of transparent hugepages which are swapout in one piece
  1325. without splitting.
  1326. thp_swpout_fallback (npn)
  1327. Number of transparent hugepages which were split before swapout.
  1328. Usually because failed to allocate some continuous swap space
  1329. for the huge page.
  1330. numa_pages_migrated (npn)
  1331. Number of pages migrated by NUMA balancing.
  1332. numa_pte_updates (npn)
  1333. Number of pages whose page table entries are modified by
  1334. NUMA balancing to produce NUMA hinting faults on access.
  1335. numa_hint_faults (npn)
  1336. Number of NUMA hinting faults.
  1337. pgdemote_kswapd
  1338. Number of pages demoted by kswapd.
  1339. pgdemote_direct
  1340. Number of pages demoted directly.
  1341. pgdemote_khugepaged
  1342. Number of pages demoted by khugepaged.
  1343. pgdemote_proactive
  1344. Number of pages demoted by proactively.
  1345. hugetlb
  1346. Amount of memory used by hugetlb pages. This metric only shows
  1347. up if hugetlb usage is accounted for in memory.current (i.e.
  1348. cgroup is mounted with the memory_hugetlb_accounting option).
  1349. memory.numa_stat
  1350. A read-only nested-keyed file which exists on non-root cgroups.
  1351. This breaks down the cgroup's memory footprint into different
  1352. types of memory, type-specific details, and other information
  1353. per node on the state of the memory management system.
  1354. This is useful for providing visibility into the NUMA locality
  1355. information within an memcg since the pages are allowed to be
  1356. allocated from any physical node. One of the use case is evaluating
  1357. application performance by combining this information with the
  1358. application's CPU allocation.
  1359. All memory amounts are in bytes.
  1360. The output format of memory.numa_stat is::
  1361. type N0=<bytes in node 0> N1=<bytes in node 1> ...
  1362. The entries are ordered to be human readable, and new entries
  1363. can show up in the middle. Don't rely on items remaining in a
  1364. fixed position; use the keys to look up specific values!
  1365. The entries can refer to the memory.stat.
  1366. memory.swap.current
  1367. A read-only single value file which exists on non-root
  1368. cgroups.
  1369. The total amount of swap currently being used by the cgroup
  1370. and its descendants.
  1371. memory.swap.high
  1372. A read-write single value file which exists on non-root
  1373. cgroups. The default is "max".
  1374. Swap usage throttle limit. If a cgroup's swap usage exceeds
  1375. this limit, all its further allocations will be throttled to
  1376. allow userspace to implement custom out-of-memory procedures.
  1377. This limit marks a point of no return for the cgroup. It is NOT
  1378. designed to manage the amount of swapping a workload does
  1379. during regular operation. Compare to memory.swap.max, which
  1380. prohibits swapping past a set amount, but lets the cgroup
  1381. continue unimpeded as long as other memory can be reclaimed.
  1382. Healthy workloads are not expected to reach this limit.
  1383. memory.swap.peak
  1384. A read-write single value file which exists on non-root cgroups.
  1385. The max swap usage recorded for the cgroup and its descendants since
  1386. the creation of the cgroup or the most recent reset for that FD.
  1387. A write of any non-empty string to this file resets it to the
  1388. current memory usage for subsequent reads through the same
  1389. file descriptor.
  1390. memory.swap.max
  1391. A read-write single value file which exists on non-root
  1392. cgroups. The default is "max".
  1393. Swap usage hard limit. If a cgroup's swap usage reaches this
  1394. limit, anonymous memory of the cgroup will not be swapped out.
  1395. memory.swap.events
  1396. A read-only flat-keyed file which exists on non-root cgroups.
  1397. The following entries are defined. Unless specified
  1398. otherwise, a value change in this file generates a file
  1399. modified event.
  1400. high
  1401. The number of times the cgroup's swap usage was over
  1402. the high threshold.
  1403. max
  1404. The number of times the cgroup's swap usage was about
  1405. to go over the max boundary and swap allocation
  1406. failed.
  1407. fail
  1408. The number of times swap allocation failed either
  1409. because of running out of swap system-wide or max
  1410. limit.
  1411. When reduced under the current usage, the existing swap
  1412. entries are reclaimed gradually and the swap usage may stay
  1413. higher than the limit for an extended period of time. This
  1414. reduces the impact on the workload and memory management.
  1415. memory.zswap.current
  1416. A read-only single value file which exists on non-root
  1417. cgroups.
  1418. The total amount of memory consumed by the zswap compression
  1419. backend.
  1420. memory.zswap.max
  1421. A read-write single value file which exists on non-root
  1422. cgroups. The default is "max".
  1423. Zswap usage hard limit. If a cgroup's zswap pool reaches this
  1424. limit, it will refuse to take any more stores before existing
  1425. entries fault back in or are written out to disk.
  1426. memory.zswap.writeback
  1427. A read-write single value file. The default value is "1".
  1428. Note that this setting is hierarchical, i.e. the writeback would be
  1429. implicitly disabled for child cgroups if the upper hierarchy
  1430. does so.
  1431. When this is set to 0, all swapping attempts to swapping devices
  1432. are disabled. This included both zswap writebacks, and swapping due
  1433. to zswap store failures. If the zswap store failures are recurring
  1434. (for e.g if the pages are incompressible), users can observe
  1435. reclaim inefficiency after disabling writeback (because the same
  1436. pages might be rejected again and again).
  1437. Note that this is subtly different from setting memory.swap.max to
  1438. 0, as it still allows for pages to be written to the zswap pool.
  1439. This setting has no effect if zswap is disabled, and swapping
  1440. is allowed unless memory.swap.max is set to 0.
  1441. memory.pressure
  1442. A read-only nested-keyed file.
  1443. Shows pressure stall information for memory. See
  1444. :ref:`Documentation/accounting/psi.rst <psi>` for details.
  1445. Usage Guidelines
  1446. ~~~~~~~~~~~~~~~~
  1447. "memory.high" is the main mechanism to control memory usage.
  1448. Over-committing on high limit (sum of high limits > available memory)
  1449. and letting global memory pressure to distribute memory according to
  1450. usage is a viable strategy.
  1451. Because breach of the high limit doesn't trigger the OOM killer but
  1452. throttles the offending cgroup, a management agent has ample
  1453. opportunities to monitor and take appropriate actions such as granting
  1454. more memory or terminating the workload.
  1455. Determining whether a cgroup has enough memory is not trivial as
  1456. memory usage doesn't indicate whether the workload can benefit from
  1457. more memory. For example, a workload which writes data received from
  1458. network to a file can use all available memory but can also operate as
  1459. performant with a small amount of memory. A measure of memory
  1460. pressure - how much the workload is being impacted due to lack of
  1461. memory - is necessary to determine whether a workload needs more
  1462. memory; unfortunately, memory pressure monitoring mechanism isn't
  1463. implemented yet.
  1464. Reclaim Protection
  1465. ~~~~~~~~~~~~~~~~~~
  1466. The protection configured with "memory.low" or "memory.min" applies relatively
  1467. to the target of the reclaim (i.e. any of memory cgroup limits, proactive
  1468. memory.reclaim or global reclaim apparently located in the root cgroup).
  1469. The protection value configured for B applies unchanged to the reclaim
  1470. targeting A (i.e. caused by competition with the sibling E)::
  1471. root - ... - A - B - C
  1472. \ ` D
  1473. ` E
  1474. When the reclaim targets ancestors of A, the effective protection of B is
  1475. capped by the protection value configured for A (and any other intermediate
  1476. ancestors between A and the target).
  1477. To express indifference about relative sibling protection, it is suggested to
  1478. use memory_recursiveprot. Configuring all descendants of a parent with finite
  1479. protection to "max" works but it may unnecessarily skew memory.events:low
  1480. field.
  1481. Memory Ownership
  1482. ~~~~~~~~~~~~~~~~
  1483. A memory area is charged to the cgroup which instantiated it and stays
  1484. charged to the cgroup until the area is released. Migrating a process
  1485. to a different cgroup doesn't move the memory usages that it
  1486. instantiated while in the previous cgroup to the new cgroup.
  1487. A memory area may be used by processes belonging to different cgroups.
  1488. To which cgroup the area will be charged is in-deterministic; however,
  1489. over time, the memory area is likely to end up in a cgroup which has
  1490. enough memory allowance to avoid high reclaim pressure.
  1491. If a cgroup sweeps a considerable amount of memory which is expected
  1492. to be accessed repeatedly by other cgroups, it may make sense to use
  1493. POSIX_FADV_DONTNEED to relinquish the ownership of memory areas
  1494. belonging to the affected files to ensure correct memory ownership.
  1495. IO
  1496. --
  1497. The "io" controller regulates the distribution of IO resources. This
  1498. controller implements both weight based and absolute bandwidth or IOPS
  1499. limit distribution; however, weight based distribution is available
  1500. only if cfq-iosched is in use and neither scheme is available for
  1501. blk-mq devices.
  1502. IO Interface Files
  1503. ~~~~~~~~~~~~~~~~~~
  1504. io.stat
  1505. A read-only nested-keyed file.
  1506. Lines are keyed by $MAJ:$MIN device numbers and not ordered.
  1507. The following nested keys are defined.
  1508. ====== =====================
  1509. rbytes Bytes read
  1510. wbytes Bytes written
  1511. rios Number of read IOs
  1512. wios Number of write IOs
  1513. dbytes Bytes discarded
  1514. dios Number of discard IOs
  1515. ====== =====================
  1516. An example read output follows::
  1517. 8:16 rbytes=1459200 wbytes=314773504 rios=192 wios=353 dbytes=0 dios=0
  1518. 8:0 rbytes=90430464 wbytes=299008000 rios=8950 wios=1252 dbytes=50331648 dios=3021
  1519. io.cost.qos
  1520. A read-write nested-keyed file which exists only on the root
  1521. cgroup.
  1522. This file configures the Quality of Service of the IO cost
  1523. model based controller (CONFIG_BLK_CGROUP_IOCOST) which
  1524. currently implements "io.weight" proportional control. Lines
  1525. are keyed by $MAJ:$MIN device numbers and not ordered. The
  1526. line for a given device is populated on the first write for
  1527. the device on "io.cost.qos" or "io.cost.model". The following
  1528. nested keys are defined.
  1529. ====== =====================================
  1530. enable Weight-based control enable
  1531. ctrl "auto" or "user"
  1532. rpct Read latency percentile [0, 100]
  1533. rlat Read latency threshold
  1534. wpct Write latency percentile [0, 100]
  1535. wlat Write latency threshold
  1536. min Minimum scaling percentage [1, 10000]
  1537. max Maximum scaling percentage [1, 10000]
  1538. ====== =====================================
  1539. The controller is disabled by default and can be enabled by
  1540. setting "enable" to 1. "rpct" and "wpct" parameters default
  1541. to zero and the controller uses internal device saturation
  1542. state to adjust the overall IO rate between "min" and "max".
  1543. When a better control quality is needed, latency QoS
  1544. parameters can be configured. For example::
  1545. 8:16 enable=1 ctrl=auto rpct=95.00 rlat=75000 wpct=95.00 wlat=150000 min=50.00 max=150.0
  1546. shows that on sdb, the controller is enabled, will consider
  1547. the device saturated if the 95th percentile of read completion
  1548. latencies is above 75ms or write 150ms, and adjust the overall
  1549. IO issue rate between 50% and 150% accordingly.
  1550. The lower the saturation point, the better the latency QoS at
  1551. the cost of aggregate bandwidth. The narrower the allowed
  1552. adjustment range between "min" and "max", the more conformant
  1553. to the cost model the IO behavior. Note that the IO issue
  1554. base rate may be far off from 100% and setting "min" and "max"
  1555. blindly can lead to a significant loss of device capacity or
  1556. control quality. "min" and "max" are useful for regulating
  1557. devices which show wide temporary behavior changes - e.g. a
  1558. ssd which accepts writes at the line speed for a while and
  1559. then completely stalls for multiple seconds.
  1560. When "ctrl" is "auto", the parameters are controlled by the
  1561. kernel and may change automatically. Setting "ctrl" to "user"
  1562. or setting any of the percentile and latency parameters puts
  1563. it into "user" mode and disables the automatic changes. The
  1564. automatic mode can be restored by setting "ctrl" to "auto".
  1565. io.cost.model
  1566. A read-write nested-keyed file which exists only on the root
  1567. cgroup.
  1568. This file configures the cost model of the IO cost model based
  1569. controller (CONFIG_BLK_CGROUP_IOCOST) which currently
  1570. implements "io.weight" proportional control. Lines are keyed
  1571. by $MAJ:$MIN device numbers and not ordered. The line for a
  1572. given device is populated on the first write for the device on
  1573. "io.cost.qos" or "io.cost.model". The following nested keys
  1574. are defined.
  1575. ===== ================================
  1576. ctrl "auto" or "user"
  1577. model The cost model in use - "linear"
  1578. ===== ================================
  1579. When "ctrl" is "auto", the kernel may change all parameters
  1580. dynamically. When "ctrl" is set to "user" or any other
  1581. parameters are written to, "ctrl" become "user" and the
  1582. automatic changes are disabled.
  1583. When "model" is "linear", the following model parameters are
  1584. defined.
  1585. ============= ========================================
  1586. [r|w]bps The maximum sequential IO throughput
  1587. [r|w]seqiops The maximum 4k sequential IOs per second
  1588. [r|w]randiops The maximum 4k random IOs per second
  1589. ============= ========================================
  1590. From the above, the builtin linear model determines the base
  1591. costs of a sequential and random IO and the cost coefficient
  1592. for the IO size. While simple, this model can cover most
  1593. common device classes acceptably.
  1594. The IO cost model isn't expected to be accurate in absolute
  1595. sense and is scaled to the device behavior dynamically.
  1596. If needed, tools/cgroup/iocost_coef_gen.py can be used to
  1597. generate device-specific coefficients.
  1598. io.weight
  1599. A read-write flat-keyed file which exists on non-root cgroups.
  1600. The default is "default 100".
  1601. The first line is the default weight applied to devices
  1602. without specific override. The rest are overrides keyed by
  1603. $MAJ:$MIN device numbers and not ordered. The weights are in
  1604. the range [1, 10000] and specifies the relative amount IO time
  1605. the cgroup can use in relation to its siblings.
  1606. The default weight can be updated by writing either "default
  1607. $WEIGHT" or simply "$WEIGHT". Overrides can be set by writing
  1608. "$MAJ:$MIN $WEIGHT" and unset by writing "$MAJ:$MIN default".
  1609. An example read output follows::
  1610. default 100
  1611. 8:16 200
  1612. 8:0 50
  1613. io.max
  1614. A read-write nested-keyed file which exists on non-root
  1615. cgroups.
  1616. BPS and IOPS based IO limit. Lines are keyed by $MAJ:$MIN
  1617. device numbers and not ordered. The following nested keys are
  1618. defined.
  1619. ===== ==================================
  1620. rbps Max read bytes per second
  1621. wbps Max write bytes per second
  1622. riops Max read IO operations per second
  1623. wiops Max write IO operations per second
  1624. ===== ==================================
  1625. When writing, any number of nested key-value pairs can be
  1626. specified in any order. "max" can be specified as the value
  1627. to remove a specific limit. If the same key is specified
  1628. multiple times, the outcome is undefined.
  1629. BPS and IOPS are measured in each IO direction and IOs are
  1630. delayed if limit is reached. Temporary bursts are allowed.
  1631. Setting read limit at 2M BPS and write at 120 IOPS for 8:16::
  1632. echo "8:16 rbps=2097152 wiops=120" > io.max
  1633. Reading returns the following::
  1634. 8:16 rbps=2097152 wbps=max riops=max wiops=120
  1635. Write IOPS limit can be removed by writing the following::
  1636. echo "8:16 wiops=max" > io.max
  1637. Reading now returns the following::
  1638. 8:16 rbps=2097152 wbps=max riops=max wiops=max
  1639. io.pressure
  1640. A read-only nested-keyed file.
  1641. Shows pressure stall information for IO. See
  1642. :ref:`Documentation/accounting/psi.rst <psi>` for details.
  1643. Writeback
  1644. ~~~~~~~~~
  1645. Page cache is dirtied through buffered writes and shared mmaps and
  1646. written asynchronously to the backing filesystem by the writeback
  1647. mechanism. Writeback sits between the memory and IO domains and
  1648. regulates the proportion of dirty memory by balancing dirtying and
  1649. write IOs.
  1650. The io controller, in conjunction with the memory controller,
  1651. implements control of page cache writeback IOs. The memory controller
  1652. defines the memory domain that dirty memory ratio is calculated and
  1653. maintained for and the io controller defines the io domain which
  1654. writes out dirty pages for the memory domain. Both system-wide and
  1655. per-cgroup dirty memory states are examined and the more restrictive
  1656. of the two is enforced.
  1657. cgroup writeback requires explicit support from the underlying
  1658. filesystem. Currently, cgroup writeback is implemented on ext2, ext4,
  1659. btrfs, f2fs, and xfs. On other filesystems, all writeback IOs are
  1660. attributed to the root cgroup.
  1661. There are inherent differences in memory and writeback management
  1662. which affects how cgroup ownership is tracked. Memory is tracked per
  1663. page while writeback per inode. For the purpose of writeback, an
  1664. inode is assigned to a cgroup and all IO requests to write dirty pages
  1665. from the inode are attributed to that cgroup.
  1666. As cgroup ownership for memory is tracked per page, there can be pages
  1667. which are associated with different cgroups than the one the inode is
  1668. associated with. These are called foreign pages. The writeback
  1669. constantly keeps track of foreign pages and, if a particular foreign
  1670. cgroup becomes the majority over a certain period of time, switches
  1671. the ownership of the inode to that cgroup.
  1672. While this model is enough for most use cases where a given inode is
  1673. mostly dirtied by a single cgroup even when the main writing cgroup
  1674. changes over time, use cases where multiple cgroups write to a single
  1675. inode simultaneously are not supported well. In such circumstances, a
  1676. significant portion of IOs are likely to be attributed incorrectly.
  1677. As memory controller assigns page ownership on the first use and
  1678. doesn't update it until the page is released, even if writeback
  1679. strictly follows page ownership, multiple cgroups dirtying overlapping
  1680. areas wouldn't work as expected. It's recommended to avoid such usage
  1681. patterns.
  1682. The sysctl knobs which affect writeback behavior are applied to cgroup
  1683. writeback as follows.
  1684. vm.dirty_background_ratio, vm.dirty_ratio
  1685. These ratios apply the same to cgroup writeback with the
  1686. amount of available memory capped by limits imposed by the
  1687. memory controller and system-wide clean memory.
  1688. vm.dirty_background_bytes, vm.dirty_bytes
  1689. For cgroup writeback, this is calculated into ratio against
  1690. total available memory and applied the same way as
  1691. vm.dirty[_background]_ratio.
  1692. IO Latency
  1693. ~~~~~~~~~~
  1694. This is a cgroup v2 controller for IO workload protection. You provide a group
  1695. with a latency target, and if the average latency exceeds that target the
  1696. controller will throttle any peers that have a lower latency target than the
  1697. protected workload.
  1698. The limits are only applied at the peer level in the hierarchy. This means that
  1699. in the diagram below, only groups A, B, and C will influence each other, and
  1700. groups D and F will influence each other. Group G will influence nobody::
  1701. [root]
  1702. / | \
  1703. A B C
  1704. / \ |
  1705. D F G
  1706. So the ideal way to configure this is to set io.latency in groups A, B, and C.
  1707. Generally you do not want to set a value lower than the latency your device
  1708. supports. Experiment to find the value that works best for your workload.
  1709. Start at higher than the expected latency for your device and watch the
  1710. avg_lat value in io.stat for your workload group to get an idea of the
  1711. latency you see during normal operation. Use the avg_lat value as a basis for
  1712. your real setting, setting at 10-15% higher than the value in io.stat.
  1713. How IO Latency Throttling Works
  1714. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1715. io.latency is work conserving; so as long as everybody is meeting their latency
  1716. target the controller doesn't do anything. Once a group starts missing its
  1717. target it begins throttling any peer group that has a higher target than itself.
  1718. This throttling takes 2 forms:
  1719. - Queue depth throttling. This is the number of outstanding IO's a group is
  1720. allowed to have. We will clamp down relatively quickly, starting at no limit
  1721. and going all the way down to 1 IO at a time.
  1722. - Artificial delay induction. There are certain types of IO that cannot be
  1723. throttled without possibly adversely affecting higher priority groups. This
  1724. includes swapping and metadata IO. These types of IO are allowed to occur
  1725. normally, however they are "charged" to the originating group. If the
  1726. originating group is being throttled you will see the use_delay and delay
  1727. fields in io.stat increase. The delay value is how many microseconds that are
  1728. being added to any process that runs in this group. Because this number can
  1729. grow quite large if there is a lot of swapping or metadata IO occurring we
  1730. limit the individual delay events to 1 second at a time.
  1731. Once the victimized group starts meeting its latency target again it will start
  1732. unthrottling any peer groups that were throttled previously. If the victimized
  1733. group simply stops doing IO the global counter will unthrottle appropriately.
  1734. IO Latency Interface Files
  1735. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1736. io.latency
  1737. This takes a similar format as the other controllers.
  1738. "MAJOR:MINOR target=<target time in microseconds>"
  1739. io.stat
  1740. If the controller is enabled you will see extra stats in io.stat in
  1741. addition to the normal ones.
  1742. depth
  1743. This is the current queue depth for the group.
  1744. avg_lat
  1745. This is an exponential moving average with a decay rate of 1/exp
  1746. bound by the sampling interval. The decay rate interval can be
  1747. calculated by multiplying the win value in io.stat by the
  1748. corresponding number of samples based on the win value.
  1749. win
  1750. The sampling window size in milliseconds. This is the minimum
  1751. duration of time between evaluation events. Windows only elapse
  1752. with IO activity. Idle periods extend the most recent window.
  1753. IO Priority
  1754. ~~~~~~~~~~~
  1755. A single attribute controls the behavior of the I/O priority cgroup policy,
  1756. namely the io.prio.class attribute. The following values are accepted for
  1757. that attribute:
  1758. no-change
  1759. Do not modify the I/O priority class.
  1760. promote-to-rt
  1761. For requests that have a non-RT I/O priority class, change it into RT.
  1762. Also change the priority level of these requests to 4. Do not modify
  1763. the I/O priority of requests that have priority class RT.
  1764. restrict-to-be
  1765. For requests that do not have an I/O priority class or that have I/O
  1766. priority class RT, change it into BE. Also change the priority level
  1767. of these requests to 0. Do not modify the I/O priority class of
  1768. requests that have priority class IDLE.
  1769. idle
  1770. Change the I/O priority class of all requests into IDLE, the lowest
  1771. I/O priority class.
  1772. none-to-rt
  1773. Deprecated. Just an alias for promote-to-rt.
  1774. The following numerical values are associated with the I/O priority policies:
  1775. +----------------+---+
  1776. | no-change | 0 |
  1777. +----------------+---+
  1778. | promote-to-rt | 1 |
  1779. +----------------+---+
  1780. | restrict-to-be | 2 |
  1781. +----------------+---+
  1782. | idle | 3 |
  1783. +----------------+---+
  1784. The numerical value that corresponds to each I/O priority class is as follows:
  1785. +-------------------------------+---+
  1786. | IOPRIO_CLASS_NONE | 0 |
  1787. +-------------------------------+---+
  1788. | IOPRIO_CLASS_RT (real-time) | 1 |
  1789. +-------------------------------+---+
  1790. | IOPRIO_CLASS_BE (best effort) | 2 |
  1791. +-------------------------------+---+
  1792. | IOPRIO_CLASS_IDLE | 3 |
  1793. +-------------------------------+---+
  1794. The algorithm to set the I/O priority class for a request is as follows:
  1795. - If I/O priority class policy is promote-to-rt, change the request I/O
  1796. priority class to IOPRIO_CLASS_RT and change the request I/O priority
  1797. level to 4.
  1798. - If I/O priority class policy is not promote-to-rt, translate the I/O priority
  1799. class policy into a number, then change the request I/O priority class
  1800. into the maximum of the I/O priority class policy number and the numerical
  1801. I/O priority class.
  1802. PID
  1803. ---
  1804. The process number controller is used to allow a cgroup to stop any
  1805. new tasks from being fork()'d or clone()'d after a specified limit is
  1806. reached.
  1807. The number of tasks in a cgroup can be exhausted in ways which other
  1808. controllers cannot prevent, thus warranting its own controller. For
  1809. example, a fork bomb is likely to exhaust the number of tasks before
  1810. hitting memory restrictions.
  1811. Note that PIDs used in this controller refer to TIDs, process IDs as
  1812. used by the kernel.
  1813. PID Interface Files
  1814. ~~~~~~~~~~~~~~~~~~~
  1815. pids.max
  1816. A read-write single value file which exists on non-root
  1817. cgroups. The default is "max".
  1818. Hard limit of number of processes.
  1819. pids.current
  1820. A read-only single value file which exists on non-root cgroups.
  1821. The number of processes currently in the cgroup and its
  1822. descendants.
  1823. pids.peak
  1824. A read-only single value file which exists on non-root cgroups.
  1825. The maximum value that the number of processes in the cgroup and its
  1826. descendants has ever reached.
  1827. pids.events
  1828. A read-only flat-keyed file which exists on non-root cgroups. Unless
  1829. specified otherwise, a value change in this file generates a file
  1830. modified event. The following entries are defined.
  1831. max
  1832. The number of times the cgroup's total number of processes hit the pids.max
  1833. limit (see also pids_localevents).
  1834. pids.events.local
  1835. Similar to pids.events but the fields in the file are local
  1836. to the cgroup i.e. not hierarchical. The file modified event
  1837. generated on this file reflects only the local events.
  1838. Organisational operations are not blocked by cgroup policies, so it is
  1839. possible to have pids.current > pids.max. This can be done by either
  1840. setting the limit to be smaller than pids.current, or attaching enough
  1841. processes to the cgroup such that pids.current is larger than
  1842. pids.max. However, it is not possible to violate a cgroup PID policy
  1843. through fork() or clone(). These will return -EAGAIN if the creation
  1844. of a new process would cause a cgroup policy to be violated.
  1845. Cpuset
  1846. ------
  1847. The "cpuset" controller provides a mechanism for constraining
  1848. the CPU and memory node placement of tasks to only the resources
  1849. specified in the cpuset interface files in a task's current cgroup.
  1850. This is especially valuable on large NUMA systems where placing jobs
  1851. on properly sized subsets of the systems with careful processor and
  1852. memory placement to reduce cross-node memory access and contention
  1853. can improve overall system performance.
  1854. The "cpuset" controller is hierarchical. That means the controller
  1855. cannot use CPUs or memory nodes not allowed in its parent.
  1856. Cpuset Interface Files
  1857. ~~~~~~~~~~~~~~~~~~~~~~
  1858. cpuset.cpus
  1859. A read-write multiple values file which exists on non-root
  1860. cpuset-enabled cgroups.
  1861. It lists the requested CPUs to be used by tasks within this
  1862. cgroup. The actual list of CPUs to be granted, however, is
  1863. subjected to constraints imposed by its parent and can differ
  1864. from the requested CPUs.
  1865. The CPU numbers are comma-separated numbers or ranges.
  1866. For example::
  1867. # cat cpuset.cpus
  1868. 0-4,6,8-10
  1869. An empty value indicates that the cgroup is using the same
  1870. setting as the nearest cgroup ancestor with a non-empty
  1871. "cpuset.cpus" or all the available CPUs if none is found.
  1872. The value of "cpuset.cpus" stays constant until the next update
  1873. and won't be affected by any CPU hotplug events.
  1874. cpuset.cpus.effective
  1875. A read-only multiple values file which exists on all
  1876. cpuset-enabled cgroups.
  1877. It lists the onlined CPUs that are actually granted to this
  1878. cgroup by its parent. These CPUs are allowed to be used by
  1879. tasks within the current cgroup.
  1880. If "cpuset.cpus" is empty, the "cpuset.cpus.effective" file shows
  1881. all the CPUs from the parent cgroup that can be available to
  1882. be used by this cgroup. Otherwise, it should be a subset of
  1883. "cpuset.cpus" unless none of the CPUs listed in "cpuset.cpus"
  1884. can be granted. In this case, it will be treated just like an
  1885. empty "cpuset.cpus".
  1886. Its value will be affected by CPU hotplug events.
  1887. cpuset.mems
  1888. A read-write multiple values file which exists on non-root
  1889. cpuset-enabled cgroups.
  1890. It lists the requested memory nodes to be used by tasks within
  1891. this cgroup. The actual list of memory nodes granted, however,
  1892. is subjected to constraints imposed by its parent and can differ
  1893. from the requested memory nodes.
  1894. The memory node numbers are comma-separated numbers or ranges.
  1895. For example::
  1896. # cat cpuset.mems
  1897. 0-1,3
  1898. An empty value indicates that the cgroup is using the same
  1899. setting as the nearest cgroup ancestor with a non-empty
  1900. "cpuset.mems" or all the available memory nodes if none
  1901. is found.
  1902. The value of "cpuset.mems" stays constant until the next update
  1903. and won't be affected by any memory nodes hotplug events.
  1904. Setting a non-empty value to "cpuset.mems" causes memory of
  1905. tasks within the cgroup to be migrated to the designated nodes if
  1906. they are currently using memory outside of the designated nodes.
  1907. There is a cost for this memory migration. The migration
  1908. may not be complete and some memory pages may be left behind.
  1909. So it is recommended that "cpuset.mems" should be set properly
  1910. before spawning new tasks into the cpuset. Even if there is
  1911. a need to change "cpuset.mems" with active tasks, it shouldn't
  1912. be done frequently.
  1913. cpuset.mems.effective
  1914. A read-only multiple values file which exists on all
  1915. cpuset-enabled cgroups.
  1916. It lists the onlined memory nodes that are actually granted to
  1917. this cgroup by its parent. These memory nodes are allowed to
  1918. be used by tasks within the current cgroup.
  1919. If "cpuset.mems" is empty, it shows all the memory nodes from the
  1920. parent cgroup that will be available to be used by this cgroup.
  1921. Otherwise, it should be a subset of "cpuset.mems" unless none of
  1922. the memory nodes listed in "cpuset.mems" can be granted. In this
  1923. case, it will be treated just like an empty "cpuset.mems".
  1924. Its value will be affected by memory nodes hotplug events.
  1925. cpuset.cpus.exclusive
  1926. A read-write multiple values file which exists on non-root
  1927. cpuset-enabled cgroups.
  1928. It lists all the exclusive CPUs that are allowed to be used
  1929. to create a new cpuset partition. Its value is not used
  1930. unless the cgroup becomes a valid partition root. See the
  1931. "cpuset.cpus.partition" section below for a description of what
  1932. a cpuset partition is.
  1933. When the cgroup becomes a partition root, the actual exclusive
  1934. CPUs that are allocated to that partition are listed in
  1935. "cpuset.cpus.exclusive.effective" which may be different
  1936. from "cpuset.cpus.exclusive". If "cpuset.cpus.exclusive"
  1937. has previously been set, "cpuset.cpus.exclusive.effective"
  1938. is always a subset of it.
  1939. Users can manually set it to a value that is different from
  1940. "cpuset.cpus". One constraint in setting it is that the list of
  1941. CPUs must be exclusive with respect to "cpuset.cpus.exclusive"
  1942. and "cpuset.cpus.exclusive.effective" of its siblings. Another
  1943. constraint is that it cannot be a superset of "cpuset.cpus"
  1944. of its sibling in order to leave at least one CPU available to
  1945. that sibling when the exclusive CPUs are taken away.
  1946. For a parent cgroup, any one of its exclusive CPUs can only
  1947. be distributed to at most one of its child cgroups. Having an
  1948. exclusive CPU appearing in two or more of its child cgroups is
  1949. not allowed (the exclusivity rule). A value that violates the
  1950. exclusivity rule will be rejected with a write error.
  1951. The root cgroup is a partition root and all its available CPUs
  1952. are in its exclusive CPU set.
  1953. cpuset.cpus.exclusive.effective
  1954. A read-only multiple values file which exists on all non-root
  1955. cpuset-enabled cgroups.
  1956. This file shows the effective set of exclusive CPUs that
  1957. can be used to create a partition root. The content
  1958. of this file will always be a subset of its parent's
  1959. "cpuset.cpus.exclusive.effective" if its parent is not the root
  1960. cgroup. It will also be a subset of "cpuset.cpus.exclusive"
  1961. if it is set. This file should only be non-empty if either
  1962. "cpuset.cpus.exclusive" is set or when the current cpuset is
  1963. a valid partition root.
  1964. cpuset.cpus.isolated
  1965. A read-only and root cgroup only multiple values file.
  1966. This file shows the set of all isolated CPUs used in existing
  1967. isolated partitions. It will be empty if no isolated partition
  1968. is created.
  1969. cpuset.cpus.partition
  1970. A read-write single value file which exists on non-root
  1971. cpuset-enabled cgroups. This flag is owned by the parent cgroup
  1972. and is not delegatable.
  1973. It accepts only the following input values when written to.
  1974. ========== =====================================
  1975. "member" Non-root member of a partition
  1976. "root" Partition root
  1977. "isolated" Partition root without load balancing
  1978. ========== =====================================
  1979. A cpuset partition is a collection of cpuset-enabled cgroups with
  1980. a partition root at the top of the hierarchy and its descendants
  1981. except those that are separate partition roots themselves and
  1982. their descendants. A partition has exclusive access to the
  1983. set of exclusive CPUs allocated to it. Other cgroups outside
  1984. of that partition cannot use any CPUs in that set.
  1985. There are two types of partitions - local and remote. A local
  1986. partition is one whose parent cgroup is also a valid partition
  1987. root. A remote partition is one whose parent cgroup is not a
  1988. valid partition root itself.
  1989. Writing to "cpuset.cpus.exclusive" is optional for the creation
  1990. of a local partition as its "cpuset.cpus.exclusive" file will
  1991. assume an implicit value that is the same as "cpuset.cpus" if it
  1992. is not set. Writing the proper "cpuset.cpus.exclusive" values
  1993. down the cgroup hierarchy before the target partition root is
  1994. mandatory for the creation of a remote partition.
  1995. Not all the CPUs requested in "cpuset.cpus.exclusive" can be
  1996. used to form a new partition. Only those that were present
  1997. in its parent's "cpuset.cpus.exclusive.effective" control
  1998. file can be used. For partitions created without setting
  1999. "cpuset.cpus.exclusive", exclusive CPUs specified in sibling's
  2000. "cpuset.cpus.exclusive" or "cpuset.cpus.exclusive.effective"
  2001. also cannot be used.
  2002. Currently, a remote partition cannot be created under a local
  2003. partition. All the ancestors of a remote partition root except
  2004. the root cgroup cannot be a partition root.
  2005. The root cgroup is always a partition root and its state cannot
  2006. be changed. All other non-root cgroups start out as "member".
  2007. Even though the "cpuset.cpus.exclusive*" and "cpuset.cpus"
  2008. control files are not present in the root cgroup, they are
  2009. implicitly the same as the "/sys/devices/system/cpu/possible"
  2010. sysfs file.
  2011. When set to "root", the current cgroup is the root of a new
  2012. partition or scheduling domain. The set of exclusive CPUs is
  2013. determined by the value of its "cpuset.cpus.exclusive.effective".
  2014. When set to "isolated", the CPUs in that partition will be in
  2015. an isolated state without any load balancing from the scheduler
  2016. and excluded from the unbound workqueues. Tasks placed in such
  2017. a partition with multiple CPUs should be carefully distributed
  2018. and bound to each of the individual CPUs for optimal performance.
  2019. A partition root ("root" or "isolated") can be in one of the
  2020. two possible states - valid or invalid. An invalid partition
  2021. root is in a degraded state where some state information may
  2022. be retained, but behaves more like a "member".
  2023. All possible state transitions among "member", "root" and
  2024. "isolated" are allowed.
  2025. On read, the "cpuset.cpus.partition" file can show the following
  2026. values.
  2027. ============================= =====================================
  2028. "member" Non-root member of a partition
  2029. "root" Partition root
  2030. "isolated" Partition root without load balancing
  2031. "root invalid (<reason>)" Invalid partition root
  2032. "isolated invalid (<reason>)" Invalid isolated partition root
  2033. ============================= =====================================
  2034. In the case of an invalid partition root, a descriptive string on
  2035. why the partition is invalid is included within parentheses.
  2036. For a local partition root to be valid, the following conditions
  2037. must be met.
  2038. 1) The parent cgroup is a valid partition root.
  2039. 2) The "cpuset.cpus.exclusive.effective" file cannot be empty,
  2040. though it may contain offline CPUs.
  2041. 3) The "cpuset.cpus.effective" cannot be empty unless there is
  2042. no task associated with this partition.
  2043. For a remote partition root to be valid, all the above conditions
  2044. except the first one must be met.
  2045. External events like hotplug or changes to "cpuset.cpus" or
  2046. "cpuset.cpus.exclusive" can cause a valid partition root to
  2047. become invalid and vice versa. Note that a task cannot be
  2048. moved to a cgroup with empty "cpuset.cpus.effective".
  2049. A valid non-root parent partition may distribute out all its CPUs
  2050. to its child local partitions when there is no task associated
  2051. with it.
  2052. Care must be taken to change a valid partition root to "member"
  2053. as all its child local partitions, if present, will become
  2054. invalid causing disruption to tasks running in those child
  2055. partitions. These inactivated partitions could be recovered if
  2056. their parent is switched back to a partition root with a proper
  2057. value in "cpuset.cpus" or "cpuset.cpus.exclusive".
  2058. Poll and inotify events are triggered whenever the state of
  2059. "cpuset.cpus.partition" changes. That includes changes caused
  2060. by write to "cpuset.cpus.partition", cpu hotplug or other
  2061. changes that modify the validity status of the partition.
  2062. This will allow user space agents to monitor unexpected changes
  2063. to "cpuset.cpus.partition" without the need to do continuous
  2064. polling.
  2065. A user can pre-configure certain CPUs to an isolated state
  2066. with load balancing disabled at boot time with the "isolcpus"
  2067. kernel boot command line option. If those CPUs are to be put
  2068. into a partition, they have to be used in an isolated partition.
  2069. Device controller
  2070. -----------------
  2071. Device controller manages access to device files. It includes both
  2072. creation of new device files (using mknod), and access to the
  2073. existing device files.
  2074. Cgroup v2 device controller has no interface files and is implemented
  2075. on top of cgroup BPF. To control access to device files, a user may
  2076. create bpf programs of type BPF_PROG_TYPE_CGROUP_DEVICE and attach
  2077. them to cgroups with BPF_CGROUP_DEVICE flag. On an attempt to access a
  2078. device file, corresponding BPF programs will be executed, and depending
  2079. on the return value the attempt will succeed or fail with -EPERM.
  2080. A BPF_PROG_TYPE_CGROUP_DEVICE program takes a pointer to the
  2081. bpf_cgroup_dev_ctx structure, which describes the device access attempt:
  2082. access type (mknod/read/write) and device (type, major and minor numbers).
  2083. If the program returns 0, the attempt fails with -EPERM, otherwise it
  2084. succeeds.
  2085. An example of BPF_PROG_TYPE_CGROUP_DEVICE program may be found in
  2086. tools/testing/selftests/bpf/progs/dev_cgroup.c in the kernel source tree.
  2087. RDMA
  2088. ----
  2089. The "rdma" controller regulates the distribution and accounting of
  2090. RDMA resources.
  2091. RDMA Interface Files
  2092. ~~~~~~~~~~~~~~~~~~~~
  2093. rdma.max
  2094. A readwrite nested-keyed file that exists for all the cgroups
  2095. except root that describes current configured resource limit
  2096. for a RDMA/IB device.
  2097. Lines are keyed by device name and are not ordered.
  2098. Each line contains space separated resource name and its configured
  2099. limit that can be distributed.
  2100. The following nested keys are defined.
  2101. ========== =============================
  2102. hca_handle Maximum number of HCA Handles
  2103. hca_object Maximum number of HCA Objects
  2104. ========== =============================
  2105. An example for mlx4 and ocrdma device follows::
  2106. mlx4_0 hca_handle=2 hca_object=2000
  2107. ocrdma1 hca_handle=3 hca_object=max
  2108. rdma.current
  2109. A read-only file that describes current resource usage.
  2110. It exists for all the cgroup except root.
  2111. An example for mlx4 and ocrdma device follows::
  2112. mlx4_0 hca_handle=1 hca_object=20
  2113. ocrdma1 hca_handle=1 hca_object=23
  2114. DMEM
  2115. ----
  2116. The "dmem" controller regulates the distribution and accounting of
  2117. device memory regions. Because each memory region may have its own page size,
  2118. which does not have to be equal to the system page size, the units are always bytes.
  2119. DMEM Interface Files
  2120. ~~~~~~~~~~~~~~~~~~~~
  2121. dmem.max, dmem.min, dmem.low
  2122. A readwrite nested-keyed file that exists for all the cgroups
  2123. except root that describes current configured resource limit
  2124. for a region.
  2125. An example for xe follows::
  2126. drm/0000:03:00.0/vram0 1073741824
  2127. drm/0000:03:00.0/stolen max
  2128. The semantics are the same as for the memory cgroup controller, and are
  2129. calculated in the same way.
  2130. dmem.capacity
  2131. A read-only file that describes maximum region capacity.
  2132. It only exists on the root cgroup. Not all memory can be
  2133. allocated by cgroups, as the kernel reserves some for
  2134. internal use.
  2135. An example for xe follows::
  2136. drm/0000:03:00.0/vram0 8514437120
  2137. drm/0000:03:00.0/stolen 67108864
  2138. dmem.current
  2139. A read-only file that describes current resource usage.
  2140. It exists for all the cgroup except root.
  2141. An example for xe follows::
  2142. drm/0000:03:00.0/vram0 12550144
  2143. drm/0000:03:00.0/stolen 8650752
  2144. HugeTLB
  2145. -------
  2146. The HugeTLB controller allows limiting the HugeTLB usage per control group and
  2147. enforces the controller limit during page fault.
  2148. HugeTLB Interface Files
  2149. ~~~~~~~~~~~~~~~~~~~~~~~
  2150. hugetlb.<hugepagesize>.current
  2151. Show current usage for "hugepagesize" hugetlb. It exists for all
  2152. the cgroup except root.
  2153. hugetlb.<hugepagesize>.max
  2154. Set/show the hard limit of "hugepagesize" hugetlb usage.
  2155. The default value is "max". It exists for all the cgroup except root.
  2156. hugetlb.<hugepagesize>.events
  2157. A read-only flat-keyed file which exists on non-root cgroups.
  2158. max
  2159. The number of allocation failure due to HugeTLB limit
  2160. hugetlb.<hugepagesize>.events.local
  2161. Similar to hugetlb.<hugepagesize>.events but the fields in the file
  2162. are local to the cgroup i.e. not hierarchical. The file modified event
  2163. generated on this file reflects only the local events.
  2164. hugetlb.<hugepagesize>.numa_stat
  2165. Similar to memory.numa_stat, it shows the numa information of the
  2166. hugetlb pages of <hugepagesize> in this cgroup. Only active in
  2167. use hugetlb pages are included. The per-node values are in bytes.
  2168. Misc
  2169. ----
  2170. The Miscellaneous cgroup provides the resource limiting and tracking
  2171. mechanism for the scalar resources which cannot be abstracted like the other
  2172. cgroup resources. Controller is enabled by the CONFIG_CGROUP_MISC config
  2173. option.
  2174. A resource can be added to the controller via enum misc_res_type{} in the
  2175. include/linux/misc_cgroup.h file and the corresponding name via misc_res_name[]
  2176. in the kernel/cgroup/misc.c file. Provider of the resource must set its
  2177. capacity prior to using the resource by calling misc_cg_set_capacity().
  2178. Once a capacity is set then the resource usage can be updated using charge and
  2179. uncharge APIs. All of the APIs to interact with misc controller are in
  2180. include/linux/misc_cgroup.h.
  2181. Misc Interface Files
  2182. ~~~~~~~~~~~~~~~~~~~~
  2183. Miscellaneous controller provides 3 interface files. If two misc resources (res_a and res_b) are registered then:
  2184. misc.capacity
  2185. A read-only flat-keyed file shown only in the root cgroup. It shows
  2186. miscellaneous scalar resources available on the platform along with
  2187. their quantities::
  2188. $ cat misc.capacity
  2189. res_a 50
  2190. res_b 10
  2191. misc.current
  2192. A read-only flat-keyed file shown in the all cgroups. It shows
  2193. the current usage of the resources in the cgroup and its children.::
  2194. $ cat misc.current
  2195. res_a 3
  2196. res_b 0
  2197. misc.peak
  2198. A read-only flat-keyed file shown in all cgroups. It shows the
  2199. historical maximum usage of the resources in the cgroup and its
  2200. children.::
  2201. $ cat misc.peak
  2202. res_a 10
  2203. res_b 8
  2204. misc.max
  2205. A read-write flat-keyed file shown in the non root cgroups. Allowed
  2206. maximum usage of the resources in the cgroup and its children.::
  2207. $ cat misc.max
  2208. res_a max
  2209. res_b 4
  2210. Limit can be set by::
  2211. # echo res_a 1 > misc.max
  2212. Limit can be set to max by::
  2213. # echo res_a max > misc.max
  2214. Limits can be set higher than the capacity value in the misc.capacity
  2215. file.
  2216. misc.events
  2217. A read-only flat-keyed file which exists on non-root cgroups. The
  2218. following entries are defined. Unless specified otherwise, a value
  2219. change in this file generates a file modified event. All fields in
  2220. this file are hierarchical.
  2221. max
  2222. The number of times the cgroup's resource usage was
  2223. about to go over the max boundary.
  2224. misc.events.local
  2225. Similar to misc.events but the fields in the file are local to the
  2226. cgroup i.e. not hierarchical. The file modified event generated on
  2227. this file reflects only the local events.
  2228. Migration and Ownership
  2229. ~~~~~~~~~~~~~~~~~~~~~~~
  2230. A miscellaneous scalar resource is charged to the cgroup in which it is used
  2231. first, and stays charged to that cgroup until that resource is freed. Migrating
  2232. a process to a different cgroup does not move the charge to the destination
  2233. cgroup where the process has moved.
  2234. Others
  2235. ------
  2236. perf_event
  2237. ~~~~~~~~~~
  2238. perf_event controller, if not mounted on a legacy hierarchy, is
  2239. automatically enabled on the v2 hierarchy so that perf events can
  2240. always be filtered by cgroup v2 path. The controller can still be
  2241. moved to a legacy hierarchy after v2 hierarchy is populated.
  2242. Non-normative information
  2243. -------------------------
  2244. This section contains information that isn't considered to be a part of
  2245. the stable kernel API and so is subject to change.
  2246. CPU controller root cgroup process behaviour
  2247. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2248. When distributing CPU cycles in the root cgroup each thread in this
  2249. cgroup is treated as if it was hosted in a separate child cgroup of the
  2250. root cgroup. This child cgroup weight is dependent on its thread nice
  2251. level.
  2252. For details of this mapping see sched_prio_to_weight array in
  2253. kernel/sched/core.c file (values from this array should be scaled
  2254. appropriately so the neutral - nice 0 - value is 100 instead of 1024).
  2255. IO controller root cgroup process behaviour
  2256. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2257. Root cgroup processes are hosted in an implicit leaf child node.
  2258. When distributing IO resources this implicit child node is taken into
  2259. account as if it was a normal child cgroup of the root cgroup with a
  2260. weight value of 200.
  2261. Namespace
  2262. =========
  2263. Basics
  2264. ------
  2265. cgroup namespace provides a mechanism to virtualize the view of the
  2266. "/proc/$PID/cgroup" file and cgroup mounts. The CLONE_NEWCGROUP clone
  2267. flag can be used with clone(2) and unshare(2) to create a new cgroup
  2268. namespace. The process running inside the cgroup namespace will have
  2269. its "/proc/$PID/cgroup" output restricted to cgroupns root. The
  2270. cgroupns root is the cgroup of the process at the time of creation of
  2271. the cgroup namespace.
  2272. Without cgroup namespace, the "/proc/$PID/cgroup" file shows the
  2273. complete path of the cgroup of a process. In a container setup where
  2274. a set of cgroups and namespaces are intended to isolate processes the
  2275. "/proc/$PID/cgroup" file may leak potential system level information
  2276. to the isolated processes. For example::
  2277. # cat /proc/self/cgroup
  2278. 0::/batchjobs/container_id1
  2279. The path '/batchjobs/container_id1' can be considered as system-data
  2280. and undesirable to expose to the isolated processes. cgroup namespace
  2281. can be used to restrict visibility of this path. For example, before
  2282. creating a cgroup namespace, one would see::
  2283. # ls -l /proc/self/ns/cgroup
  2284. lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835]
  2285. # cat /proc/self/cgroup
  2286. 0::/batchjobs/container_id1
  2287. After unsharing a new namespace, the view changes::
  2288. # ls -l /proc/self/ns/cgroup
  2289. lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183]
  2290. # cat /proc/self/cgroup
  2291. 0::/
  2292. When some thread from a multi-threaded process unshares its cgroup
  2293. namespace, the new cgroupns gets applied to the entire process (all
  2294. the threads). This is natural for the v2 hierarchy; however, for the
  2295. legacy hierarchies, this may be unexpected.
  2296. A cgroup namespace is alive as long as there are processes inside or
  2297. mounts pinning it. When the last usage goes away, the cgroup
  2298. namespace is destroyed. The cgroupns root and the actual cgroups
  2299. remain.
  2300. The Root and Views
  2301. ------------------
  2302. The 'cgroupns root' for a cgroup namespace is the cgroup in which the
  2303. process calling unshare(2) is running. For example, if a process in
  2304. /batchjobs/container_id1 cgroup calls unshare, cgroup
  2305. /batchjobs/container_id1 becomes the cgroupns root. For the
  2306. init_cgroup_ns, this is the real root ('/') cgroup.
  2307. The cgroupns root cgroup does not change even if the namespace creator
  2308. process later moves to a different cgroup::
  2309. # ~/unshare -c # unshare cgroupns in some cgroup
  2310. # cat /proc/self/cgroup
  2311. 0::/
  2312. # mkdir sub_cgrp_1
  2313. # echo 0 > sub_cgrp_1/cgroup.procs
  2314. # cat /proc/self/cgroup
  2315. 0::/sub_cgrp_1
  2316. Each process gets its namespace-specific view of "/proc/$PID/cgroup"
  2317. Processes running inside the cgroup namespace will be able to see
  2318. cgroup paths (in /proc/self/cgroup) only inside their root cgroup.
  2319. From within an unshared cgroupns::
  2320. # sleep 100000 &
  2321. [1] 7353
  2322. # echo 7353 > sub_cgrp_1/cgroup.procs
  2323. # cat /proc/7353/cgroup
  2324. 0::/sub_cgrp_1
  2325. From the initial cgroup namespace, the real cgroup path will be
  2326. visible::
  2327. $ cat /proc/7353/cgroup
  2328. 0::/batchjobs/container_id1/sub_cgrp_1
  2329. From a sibling cgroup namespace (that is, a namespace rooted at a
  2330. different cgroup), the cgroup path relative to its own cgroup
  2331. namespace root will be shown. For instance, if PID 7353's cgroup
  2332. namespace root is at '/batchjobs/container_id2', then it will see::
  2333. # cat /proc/7353/cgroup
  2334. 0::/../container_id2/sub_cgrp_1
  2335. Note that the relative path always starts with '/' to indicate that
  2336. its relative to the cgroup namespace root of the caller.
  2337. Migration and setns(2)
  2338. ----------------------
  2339. Processes inside a cgroup namespace can move into and out of the
  2340. namespace root if they have proper access to external cgroups. For
  2341. example, from inside a namespace with cgroupns root at
  2342. /batchjobs/container_id1, and assuming that the global hierarchy is
  2343. still accessible inside cgroupns::
  2344. # cat /proc/7353/cgroup
  2345. 0::/sub_cgrp_1
  2346. # echo 7353 > batchjobs/container_id2/cgroup.procs
  2347. # cat /proc/7353/cgroup
  2348. 0::/../container_id2
  2349. Note that this kind of setup is not encouraged. A task inside cgroup
  2350. namespace should only be exposed to its own cgroupns hierarchy.
  2351. setns(2) to another cgroup namespace is allowed when:
  2352. (a) the process has CAP_SYS_ADMIN against its current user namespace
  2353. (b) the process has CAP_SYS_ADMIN against the target cgroup
  2354. namespace's userns
  2355. No implicit cgroup changes happen with attaching to another cgroup
  2356. namespace. It is expected that the someone moves the attaching
  2357. process under the target cgroup namespace root.
  2358. Interaction with Other Namespaces
  2359. ---------------------------------
  2360. Namespace specific cgroup hierarchy can be mounted by a process
  2361. running inside a non-init cgroup namespace::
  2362. # mount -t cgroup2 none $MOUNT_POINT
  2363. This will mount the unified cgroup hierarchy with cgroupns root as the
  2364. filesystem root. The process needs CAP_SYS_ADMIN against its user and
  2365. mount namespaces.
  2366. The virtualization of /proc/self/cgroup file combined with restricting
  2367. the view of cgroup hierarchy by namespace-private cgroupfs mount
  2368. provides a properly isolated cgroup view inside the container.
  2369. Information on Kernel Programming
  2370. =================================
  2371. This section contains kernel programming information in the areas
  2372. where interacting with cgroup is necessary. cgroup core and
  2373. controllers are not covered.
  2374. Filesystem Support for Writeback
  2375. --------------------------------
  2376. A filesystem can support cgroup writeback by updating
  2377. address_space_operations->writepages() to annotate bio's using the
  2378. following two functions.
  2379. wbc_init_bio(@wbc, @bio)
  2380. Should be called for each bio carrying writeback data and
  2381. associates the bio with the inode's owner cgroup and the
  2382. corresponding request queue. This must be called after
  2383. a queue (device) has been associated with the bio and
  2384. before submission.
  2385. wbc_account_cgroup_owner(@wbc, @folio, @bytes)
  2386. Should be called for each data segment being written out.
  2387. While this function doesn't care exactly when it's called
  2388. during the writeback session, it's the easiest and most
  2389. natural to call it as data segments are added to a bio.
  2390. With writeback bio's annotated, cgroup support can be enabled per
  2391. super_block by setting SB_I_CGROUPWB in ->s_iflags. This allows for
  2392. selective disabling of cgroup writeback support which is helpful when
  2393. certain filesystem features, e.g. journaled data mode, are
  2394. incompatible.
  2395. wbc_init_bio() binds the specified bio to its cgroup. Depending on
  2396. the configuration, the bio may be executed at a lower priority and if
  2397. the writeback session is holding shared resources, e.g. a journal
  2398. entry, may lead to priority inversion. There is no one easy solution
  2399. for the problem. Filesystems can try to work around specific problem
  2400. cases by skipping wbc_init_bio() and using bio_associate_blkg()
  2401. directly.
  2402. Deprecated v1 Core Features
  2403. ===========================
  2404. - Multiple hierarchies including named ones are not supported.
  2405. - All v1 mount options are not supported.
  2406. - The "tasks" file is removed and "cgroup.procs" is not sorted.
  2407. - "cgroup.clone_children" is removed.
  2408. - /proc/cgroups is meaningless for v2. Use "cgroup.controllers" or
  2409. "cgroup.stat" files at the root instead.
  2410. Issues with v1 and Rationales for v2
  2411. ====================================
  2412. Multiple Hierarchies
  2413. --------------------
  2414. cgroup v1 allowed an arbitrary number of hierarchies and each
  2415. hierarchy could host any number of controllers. While this seemed to
  2416. provide a high level of flexibility, it wasn't useful in practice.
  2417. For example, as there is only one instance of each controller, utility
  2418. type controllers such as freezer which can be useful in all
  2419. hierarchies could only be used in one. The issue is exacerbated by
  2420. the fact that controllers couldn't be moved to another hierarchy once
  2421. hierarchies were populated. Another issue was that all controllers
  2422. bound to a hierarchy were forced to have exactly the same view of the
  2423. hierarchy. It wasn't possible to vary the granularity depending on
  2424. the specific controller.
  2425. In practice, these issues heavily limited which controllers could be
  2426. put on the same hierarchy and most configurations resorted to putting
  2427. each controller on its own hierarchy. Only closely related ones, such
  2428. as the cpu and cpuacct controllers, made sense to be put on the same
  2429. hierarchy. This often meant that userland ended up managing multiple
  2430. similar hierarchies repeating the same steps on each hierarchy
  2431. whenever a hierarchy management operation was necessary.
  2432. Furthermore, support for multiple hierarchies came at a steep cost.
  2433. It greatly complicated cgroup core implementation but more importantly
  2434. the support for multiple hierarchies restricted how cgroup could be
  2435. used in general and what controllers was able to do.
  2436. There was no limit on how many hierarchies there might be, which meant
  2437. that a thread's cgroup membership couldn't be described in finite
  2438. length. The key might contain any number of entries and was unlimited
  2439. in length, which made it highly awkward to manipulate and led to
  2440. addition of controllers which existed only to identify membership,
  2441. which in turn exacerbated the original problem of proliferating number
  2442. of hierarchies.
  2443. Also, as a controller couldn't have any expectation regarding the
  2444. topologies of hierarchies other controllers might be on, each
  2445. controller had to assume that all other controllers were attached to
  2446. completely orthogonal hierarchies. This made it impossible, or at
  2447. least very cumbersome, for controllers to cooperate with each other.
  2448. In most use cases, putting controllers on hierarchies which are
  2449. completely orthogonal to each other isn't necessary. What usually is
  2450. called for is the ability to have differing levels of granularity
  2451. depending on the specific controller. In other words, hierarchy may
  2452. be collapsed from leaf towards root when viewed from specific
  2453. controllers. For example, a given configuration might not care about
  2454. how memory is distributed beyond a certain level while still wanting
  2455. to control how CPU cycles are distributed.
  2456. Thread Granularity
  2457. ------------------
  2458. cgroup v1 allowed threads of a process to belong to different cgroups.
  2459. This didn't make sense for some controllers and those controllers
  2460. ended up implementing different ways to ignore such situations but
  2461. much more importantly it blurred the line between API exposed to
  2462. individual applications and system management interface.
  2463. Generally, in-process knowledge is available only to the process
  2464. itself; thus, unlike service-level organization of processes,
  2465. categorizing threads of a process requires active participation from
  2466. the application which owns the target process.
  2467. cgroup v1 had an ambiguously defined delegation model which got abused
  2468. in combination with thread granularity. cgroups were delegated to
  2469. individual applications so that they can create and manage their own
  2470. sub-hierarchies and control resource distributions along them. This
  2471. effectively raised cgroup to the status of a syscall-like API exposed
  2472. to lay programs.
  2473. First of all, cgroup has a fundamentally inadequate interface to be
  2474. exposed this way. For a process to access its own knobs, it has to
  2475. extract the path on the target hierarchy from /proc/self/cgroup,
  2476. construct the path by appending the name of the knob to the path, open
  2477. and then read and/or write to it. This is not only extremely clunky
  2478. and unusual but also inherently racy. There is no conventional way to
  2479. define transaction across the required steps and nothing can guarantee
  2480. that the process would actually be operating on its own sub-hierarchy.
  2481. cgroup controllers implemented a number of knobs which would never be
  2482. accepted as public APIs because they were just adding control knobs to
  2483. system-management pseudo filesystem. cgroup ended up with interface
  2484. knobs which were not properly abstracted or refined and directly
  2485. revealed kernel internal details. These knobs got exposed to
  2486. individual applications through the ill-defined delegation mechanism
  2487. effectively abusing cgroup as a shortcut to implementing public APIs
  2488. without going through the required scrutiny.
  2489. This was painful for both userland and kernel. Userland ended up with
  2490. misbehaving and poorly abstracted interfaces and kernel exposing and
  2491. locked into constructs inadvertently.
  2492. Competition Between Inner Nodes and Threads
  2493. -------------------------------------------
  2494. cgroup v1 allowed threads to be in any cgroups which created an
  2495. interesting problem where threads belonging to a parent cgroup and its
  2496. children cgroups competed for resources. This was nasty as two
  2497. different types of entities competed and there was no obvious way to
  2498. settle it. Different controllers did different things.
  2499. The cpu controller considered threads and cgroups as equivalents and
  2500. mapped nice levels to cgroup weights. This worked for some cases but
  2501. fell flat when children wanted to be allocated specific ratios of CPU
  2502. cycles and the number of internal threads fluctuated - the ratios
  2503. constantly changed as the number of competing entities fluctuated.
  2504. There also were other issues. The mapping from nice level to weight
  2505. wasn't obvious or universal, and there were various other knobs which
  2506. simply weren't available for threads.
  2507. The io controller implicitly created a hidden leaf node for each
  2508. cgroup to host the threads. The hidden leaf had its own copies of all
  2509. the knobs with ``leaf_`` prefixed. While this allowed equivalent
  2510. control over internal threads, it was with serious drawbacks. It
  2511. always added an extra layer of nesting which wouldn't be necessary
  2512. otherwise, made the interface messy and significantly complicated the
  2513. implementation.
  2514. The memory controller didn't have a way to control what happened
  2515. between internal tasks and child cgroups and the behavior was not
  2516. clearly defined. There were attempts to add ad-hoc behaviors and
  2517. knobs to tailor the behavior to specific workloads which would have
  2518. led to problems extremely difficult to resolve in the long term.
  2519. Multiple controllers struggled with internal tasks and came up with
  2520. different ways to deal with it; unfortunately, all the approaches were
  2521. severely flawed and, furthermore, the widely different behaviors
  2522. made cgroup as a whole highly inconsistent.
  2523. This clearly is a problem which needs to be addressed from cgroup core
  2524. in a uniform way.
  2525. Other Interface Issues
  2526. ----------------------
  2527. cgroup v1 grew without oversight and developed a large number of
  2528. idiosyncrasies and inconsistencies. One issue on the cgroup core side
  2529. was how an empty cgroup was notified - a userland helper binary was
  2530. forked and executed for each event. The event delivery wasn't
  2531. recursive or delegatable. The limitations of the mechanism also led
  2532. to in-kernel event delivery filtering mechanism further complicating
  2533. the interface.
  2534. Controller interfaces were problematic too. An extreme example is
  2535. controllers completely ignoring hierarchical organization and treating
  2536. all cgroups as if they were all located directly under the root
  2537. cgroup. Some controllers exposed a large amount of inconsistent
  2538. implementation details to userland.
  2539. There also was no consistency across controllers. When a new cgroup
  2540. was created, some controllers defaulted to not imposing extra
  2541. restrictions while others disallowed any resource usage until
  2542. explicitly configured. Configuration knobs for the same type of
  2543. control used widely differing naming schemes and formats. Statistics
  2544. and information knobs were named arbitrarily and used different
  2545. formats and units even in the same controller.
  2546. cgroup v2 establishes common conventions where appropriate and updates
  2547. controllers so that they expose minimal and consistent interfaces.
  2548. Controller Issues and Remedies
  2549. ------------------------------
  2550. Memory
  2551. ~~~~~~
  2552. The original lower boundary, the soft limit, is defined as a limit
  2553. that is per default unset. As a result, the set of cgroups that
  2554. global reclaim prefers is opt-in, rather than opt-out. The costs for
  2555. optimizing these mostly negative lookups are so high that the
  2556. implementation, despite its enormous size, does not even provide the
  2557. basic desirable behavior. First off, the soft limit has no
  2558. hierarchical meaning. All configured groups are organized in a global
  2559. rbtree and treated like equal peers, regardless where they are located
  2560. in the hierarchy. This makes subtree delegation impossible. Second,
  2561. the soft limit reclaim pass is so aggressive that it not just
  2562. introduces high allocation latencies into the system, but also impacts
  2563. system performance due to overreclaim, to the point where the feature
  2564. becomes self-defeating.
  2565. The memory.low boundary on the other hand is a top-down allocated
  2566. reserve. A cgroup enjoys reclaim protection when it's within its
  2567. effective low, which makes delegation of subtrees possible. It also
  2568. enjoys having reclaim pressure proportional to its overage when
  2569. above its effective low.
  2570. The original high boundary, the hard limit, is defined as a strict
  2571. limit that can not budge, even if the OOM killer has to be called.
  2572. But this generally goes against the goal of making the most out of the
  2573. available memory. The memory consumption of workloads varies during
  2574. runtime, and that requires users to overcommit. But doing that with a
  2575. strict upper limit requires either a fairly accurate prediction of the
  2576. working set size or adding slack to the limit. Since working set size
  2577. estimation is hard and error prone, and getting it wrong results in
  2578. OOM kills, most users tend to err on the side of a looser limit and
  2579. end up wasting precious resources.
  2580. The memory.high boundary on the other hand can be set much more
  2581. conservatively. When hit, it throttles allocations by forcing them
  2582. into direct reclaim to work off the excess, but it never invokes the
  2583. OOM killer. As a result, a high boundary that is chosen too
  2584. aggressively will not terminate the processes, but instead it will
  2585. lead to gradual performance degradation. The user can monitor this
  2586. and make corrections until the minimal memory footprint that still
  2587. gives acceptable performance is found.
  2588. In extreme cases, with many concurrent allocations and a complete
  2589. breakdown of reclaim progress within the group, the high boundary can
  2590. be exceeded. But even then it's mostly better to satisfy the
  2591. allocation from the slack available in other groups or the rest of the
  2592. system than killing the group. Otherwise, memory.max is there to
  2593. limit this type of spillover and ultimately contain buggy or even
  2594. malicious applications.
  2595. Setting the original memory.limit_in_bytes below the current usage was
  2596. subject to a race condition, where concurrent charges could cause the
  2597. limit setting to fail. memory.max on the other hand will first set the
  2598. limit to prevent new charges, and then reclaim and OOM kill until the
  2599. new limit is met - or the task writing to memory.max is killed.
  2600. The combined memory+swap accounting and limiting is replaced by real
  2601. control over swap space.
  2602. The main argument for a combined memory+swap facility in the original
  2603. cgroup design was that global or parental pressure would always be
  2604. able to swap all anonymous memory of a child group, regardless of the
  2605. child's own (possibly untrusted) configuration. However, untrusted
  2606. groups can sabotage swapping by other means - such as referencing its
  2607. anonymous memory in a tight loop - and an admin can not assume full
  2608. swappability when overcommitting untrusted jobs.
  2609. For trusted jobs, on the other hand, a combined counter is not an
  2610. intuitive userspace interface, and it flies in the face of the idea
  2611. that cgroup controllers should account and limit specific physical
  2612. resources. Swap space is a resource like all others in the system,
  2613. and that's why unified hierarchy allows distributing it separately.