blob: c1f0e8780960a56c13e36a914d26c86a5a4a43de [file] [log] [blame]
Tejun Heo65731572014-04-25 18:28:02 -04001
2Cgroup unified hierarchy
3
4April, 2014 Tejun Heo <tj@kernel.org>
5
6This document describes the changes made by unified hierarchy and
7their rationales. It will eventually be merged into the main cgroup
8documentation.
9
10CONTENTS
11
121. Background
132. Basic Operation
14 2-1. Mounting
15 2-2. cgroup.subtree_control
16 2-3. cgroup.controllers
173. Structural Constraints
18 3-1. Top-down
19 3-2. No internal tasks
Tejun Heo8a0792e2015-06-18 16:54:28 -0400204. Delegation
21 4-1. Model of delegation
22 4-2. Common ancestor rule
235. Other Changes
24 5-1. [Un]populated Notification
25 5-2. Other Core Changes
Tejun Heo6abc8ca2015-08-04 15:20:55 -040026 5-3. Controller File Conventions
27 5-3-1. Format
28 5-3-2. Control Knobs
29 5-4. Per-Controller Changes
Tejun Heo2ee867dc2015-08-18 14:55:34 -070030 5-4-1. io
Tejun Heo6abc8ca2015-08-04 15:20:55 -040031 5-4-2. cpuset
32 5-4-3. memory
Tejun Heo8a0792e2015-06-18 16:54:28 -0400336. Planned Changes
34 6-1. CAP for resource control
Tejun Heo65731572014-04-25 18:28:02 -040035
36
371. Background
38
39cgroup allows an arbitrary number of hierarchies and each hierarchy
40can host any number of controllers. While this seems to provide a
41high level of flexibility, it isn't quite useful in practice.
42
43For example, as there is only one instance of each controller, utility
44type controllers such as freezer which can be useful in all
45hierarchies can only be used in one. The issue is exacerbated by the
46fact that controllers can't be moved around once hierarchies are
47populated. Another issue is that all controllers bound to a hierarchy
48are forced to have exactly the same view of the hierarchy. It isn't
49possible to vary the granularity depending on the specific controller.
50
51In practice, these issues heavily limit which controllers can be put
52on the same hierarchy and most configurations resort to putting each
53controller on its own hierarchy. Only closely related ones, such as
54the cpu and cpuacct controllers, make sense to put on the same
55hierarchy. This often means that userland ends up managing multiple
56similar hierarchies repeating the same steps on each hierarchy
57whenever a hierarchy management operation is necessary.
58
59Unfortunately, support for multiple hierarchies comes at a steep cost.
60Internal implementation in cgroup core proper is dazzlingly
61complicated but more importantly the support for multiple hierarchies
62restricts how cgroup is used in general and what controllers can do.
63
64There's no limit on how many hierarchies there may be, which means
65that a task's cgroup membership can't be described in finite length.
66The key may contain any varying number of entries and is unlimited in
67length, which makes it highly awkward to handle and leads to addition
68of controllers which exist only to identify membership, which in turn
69exacerbates the original problem.
70
71Also, as a controller can't have any expectation regarding what shape
72of hierarchies other controllers would be on, each controller has to
73assume that all other controllers are operating on completely
74orthogonal hierarchies. This makes it impossible, or at least very
75cumbersome, for controllers to cooperate with each other.
76
77In most use cases, putting controllers on hierarchies which are
78completely orthogonal to each other isn't necessary. What usually is
79called for is the ability to have differing levels of granularity
80depending on the specific controller. In other words, hierarchy may
81be collapsed from leaf towards root when viewed from specific
82controllers. For example, a given configuration might not care about
83how memory is distributed beyond a certain level while still wanting
84to control how CPU cycles are distributed.
85
86Unified hierarchy is the next version of cgroup interface. It aims to
87address the aforementioned issues by having more structure while
88retaining enough flexibility for most use cases. Various other
89general and controller-specific interface issues are also addressed in
90the process.
91
92
932. Basic Operation
94
952-1. Mounting
96
Tejun Heocd5367a2015-11-16 11:13:34 -050097Unified hierarchy can be mounted with the following mount command.
Tejun Heo65731572014-04-25 18:28:02 -040098
Tejun Heocd5367a2015-11-16 11:13:34 -050099 mount -t cgroup2 none $MOUNT_POINT
Tejun Heo65731572014-04-25 18:28:02 -0400100
Tejun Heoa8ddc822014-07-15 11:05:10 -0400101All controllers which support the unified hierarchy and are not bound
102to other hierarchies are automatically bound to unified hierarchy and
103show up at the root of it. Controllers which are enabled only in the
104root of unified hierarchy can be bound to other hierarchies. This
105allows mixing unified hierarchy with the traditional multiple
106hierarchies in a fully backward compatible way.
107
Tejun Heoaf0ba672014-07-08 18:02:57 -0400108A controller can be moved across hierarchies only after the controller
109is no longer referenced in its current hierarchy. Because per-cgroup
110controller states are destroyed asynchronously and controllers may
111have lingering references, a controller may not show up immediately on
112the unified hierarchy after the final umount of the previous
113hierarchy. Similarly, a controller should be fully disabled to be
114moved out of the unified hierarchy and it may take some time for the
115disabled controller to become available for other hierarchies;
116furthermore, due to dependencies among controllers, other controllers
117may need to be disabled too.
118
119While useful for development and manual configurations, dynamically
120moving controllers between the unified and other hierarchies is
121strongly discouraged for production use. It is recommended to decide
122the hierarchies and controller associations before starting using the
123controllers.
Tejun Heo65731572014-04-25 18:28:02 -0400124
125
1262-2. cgroup.subtree_control
127
128All cgroups on unified hierarchy have a "cgroup.subtree_control" file
129which governs which controllers are enabled on the children of the
130cgroup. Let's assume a hierarchy like the following.
131
132 root - A - B - C
133 \ D
134
135root's "cgroup.subtree_control" file determines which controllers are
136enabled on A. A's on B. B's on C and D. This coincides with the
137fact that controllers on the immediate sub-level are used to
138distribute the resources of the parent. In fact, it's natural to
139assume that resource control knobs of a child belong to its parent.
140Enabling a controller in a "cgroup.subtree_control" file declares that
141distribution of the respective resources of the cgroup will be
142controlled. Note that this means that controller enable states are
143shared among siblings.
144
145When read, the file contains a space-separated list of currently
146enabled controllers. A write to the file should contain a
147space-separated list of controllers with '+' or '-' prefixed (without
148the quotes). Controllers prefixed with '+' are enabled and '-'
149disabled. If a controller is listed multiple times, the last entry
150wins. The specific operations are executed atomically - either all
151succeed or fail.
152
153
1542-3. cgroup.controllers
155
156Read-only "cgroup.controllers" file contains a space-separated list of
157controllers which can be enabled in the cgroup's
158"cgroup.subtree_control" file.
159
160In the root cgroup, this lists controllers which are not bound to
161other hierarchies and the content changes as controllers are bound to
162and unbound from other hierarchies.
163
164In non-root cgroups, the content of this file equals that of the
165parent's "cgroup.subtree_control" file as only controllers enabled
166from the parent can be used in its children.
167
168
1693. Structural Constraints
170
1713-1. Top-down
172
173As it doesn't make sense to nest control of an uncontrolled resource,
174all non-root "cgroup.subtree_control" files can only contain
175controllers which are enabled in the parent's "cgroup.subtree_control"
176file. A controller can be enabled only if the parent has the
177controller enabled and a controller can't be disabled if one or more
178children have it enabled.
179
180
1813-2. No internal tasks
182
183One long-standing issue that cgroup faces is the competition between
184tasks belonging to the parent cgroup and its children cgroups. This
185is inherently nasty as two different types of entities compete and
186there is no agreed-upon obvious way to handle it. Different
187controllers are doing different things.
188
189The cpu controller considers tasks and cgroups as equivalents and maps
190nice levels to cgroup weights. This works for some cases but falls
191flat when children should be allocated specific ratios of CPU cycles
192and the number of internal tasks fluctuates - the ratios constantly
193change as the number of competing entities fluctuates. There also are
194other issues. The mapping from nice level to weight isn't obvious or
195universal, and there are various other knobs which simply aren't
196available for tasks.
197
Tejun Heo2ee867dc2015-08-18 14:55:34 -0700198The io controller implicitly creates a hidden leaf node for each
Tejun Heo65731572014-04-25 18:28:02 -0400199cgroup to host the tasks. The hidden leaf has its own copies of all
200the knobs with "leaf_" prefixed. While this allows equivalent control
201over internal tasks, it's with serious drawbacks. It always adds an
202extra layer of nesting which may not be necessary, makes the interface
203messy and significantly complicates the implementation.
204
205The memory controller currently doesn't have a way to control what
206happens between internal tasks and child cgroups and the behavior is
207not clearly defined. There have been attempts to add ad-hoc behaviors
208and knobs to tailor the behavior to specific workloads. Continuing
209this direction will lead to problems which will be extremely difficult
210to resolve in the long term.
211
212Multiple controllers struggle with internal tasks and came up with
213different ways to deal with it; unfortunately, all the approaches in
214use now are severely flawed and, furthermore, the widely different
215behaviors make cgroup as whole highly inconsistent.
216
217It is clear that this is something which needs to be addressed from
218cgroup core proper in a uniform way so that controllers don't need to
219worry about it and cgroup as a whole shows a consistent and logical
220behavior. To achieve that, unified hierarchy enforces the following
221structural constraint:
222
223 Except for the root, only cgroups which don't contain any task may
224 have controllers enabled in their "cgroup.subtree_control" files.
225
226Combined with other properties, this guarantees that, when a
227controller is looking at the part of the hierarchy which has it
228enabled, tasks are always only on the leaves. This rules out
229situations where child cgroups compete against internal tasks of the
230parent.
231
232There are two things to note. Firstly, the root cgroup is exempt from
233the restriction. Root contains tasks and anonymous resource
234consumption which can't be associated with any other cgroup and
235requires special treatment from most controllers. How resource
236consumption in the root cgroup is governed is up to each controller.
237
238Secondly, the restriction doesn't take effect if there is no enabled
239controller in the cgroup's "cgroup.subtree_control" file. This is
240important as otherwise it wouldn't be possible to create children of a
241populated cgroup. To control resource distribution of a cgroup, the
242cgroup must create children and transfer all its tasks to the children
243before enabling controllers in its "cgroup.subtree_control" file.
244
245
Tejun Heo8a0792e2015-06-18 16:54:28 -04002464. Delegation
Tejun Heo65731572014-04-25 18:28:02 -0400247
Tejun Heo8a0792e2015-06-18 16:54:28 -04002484-1. Model of delegation
249
250A cgroup can be delegated to a less privileged user by granting write
251access of the directory and its "cgroup.procs" file to the user. Note
252that the resource control knobs in a given directory concern the
253resources of the parent and thus must not be delegated along with the
254directory.
255
256Once delegated, the user can build sub-hierarchy under the directory,
257organize processes as it sees fit and further distribute the resources
258it got from the parent. The limits and other settings of all resource
259controllers are hierarchical and regardless of what happens in the
260delegated sub-hierarchy, nothing can escape the resource restrictions
261imposed by the parent.
262
263Currently, cgroup doesn't impose any restrictions on the number of
264cgroups in or nesting depth of a delegated sub-hierarchy; however,
265this may in the future be limited explicitly.
266
267
2684-2. Common ancestor rule
269
270On the unified hierarchy, to write to a "cgroup.procs" file, in
271addition to the usual write permission to the file and uid match, the
272writer must also have write access to the "cgroup.procs" file of the
273common ancestor of the source and destination cgroups. This prevents
274delegatees from smuggling processes across disjoint sub-hierarchies.
275
276Let's say cgroups C0 and C1 have been delegated to user U0 who created
277C00, C01 under C0 and C10 under C1 as follows.
278
279 ~~~~~~~~~~~~~ - C0 - C00
280 ~ cgroup ~ \ C01
281 ~ hierarchy ~
282 ~~~~~~~~~~~~~ - C1 - C10
283
284C0 and C1 are separate entities in terms of resource distribution
285regardless of their relative positions in the hierarchy. The
286resources the processes under C0 are entitled to are controlled by
287C0's ancestors and may be completely different from C1. It's clear
288that the intention of delegating C0 to U0 is allowing U0 to organize
289the processes under C0 and further control the distribution of C0's
290resources.
291
292On traditional hierarchies, if a task has write access to "tasks" or
293"cgroup.procs" file of a cgroup and its uid agrees with the target, it
294can move the target to the cgroup. In the above example, U0 will not
295only be able to move processes in each sub-hierarchy but also across
296the two sub-hierarchies, effectively allowing it to violate the
297organizational and resource restrictions implied by the hierarchical
298structure above C0 and C1.
299
300On the unified hierarchy, let's say U0 wants to write the pid of a
301process which has a matching uid and is currently in C10 into
302"C00/cgroup.procs". U0 obviously has write access to the file and
303migration permission on the process; however, the common ancestor of
304the source cgroup C10 and the destination cgroup C00 is above the
305points of delegation and U0 would not have write access to its
306"cgroup.procs" and thus be denied with -EACCES.
307
308
3095. Other Changes
310
3115-1. [Un]populated Notification
Tejun Heo65731572014-04-25 18:28:02 -0400312
313cgroup users often need a way to determine when a cgroup's
314subhierarchy becomes empty so that it can be cleaned up. cgroup
315currently provides release_agent for it; unfortunately, this mechanism
316is riddled with issues.
317
318- It delivers events by forking and execing a userland binary
319 specified as the release_agent. This is a long deprecated method of
320 notification delivery. It's extremely heavy, slow and cumbersome to
321 integrate with larger infrastructure.
322
323- There is single monitoring point at the root. There's no way to
324 delegate management of a subtree.
325
326- The event isn't recursive. It triggers when a cgroup doesn't have
327 any tasks or child cgroups. Events for internal nodes trigger only
328 after all children are removed. This again makes it impossible to
329 delegate management of a subtree.
330
331- Events are filtered from the kernel side. A "notify_on_release"
332 file is used to subscribe to or suppress release events. This is
333 unnecessarily complicated and probably done this way because event
334 delivery itself was expensive.
335
Tejun Heo4a07c222015-09-18 17:54:22 -0400336Unified hierarchy implements "populated" field in "cgroup.events"
337interface file which can be used to monitor whether the cgroup's
338subhierarchy has tasks in it or not. Its value is 0 if there is no
339task in the cgroup and its descendants; otherwise, 1. poll and
340[id]notify events are triggered when the value changes.
Tejun Heo65731572014-04-25 18:28:02 -0400341
342This is significantly lighter and simpler and trivially allows
343delegating management of subhierarchy - subhierarchy monitoring can
344block further propagation simply by putting itself or another process
345in the subhierarchy and monitor events that it's interested in from
346there without interfering with monitoring higher in the tree.
347
348In unified hierarchy, the release_agent mechanism is no longer
349supported and the interface files "release_agent" and
350"notify_on_release" do not exist.
351
352
Tejun Heo8a0792e2015-06-18 16:54:28 -04003535-2. Other Core Changes
Tejun Heo65731572014-04-25 18:28:02 -0400354
355- None of the mount options is allowed.
356
357- remount is disallowed.
358
359- rename(2) is disallowed.
360
361- The "tasks" file is removed. Everything should at process
362 granularity. Use the "cgroup.procs" file instead.
363
364- The "cgroup.procs" file is not sorted. pids will be unique unless
365 they got recycled in-between reads.
366
367- The "cgroup.clone_children" file is removed.
368
Tejun Heo2e91fa72015-10-15 16:41:53 -0400369- /proc/PID/cgroup keeps reporting the cgroup that a zombie belonged
370 to before exiting. If the cgroup is removed before the zombie is
371 reaped, " (deleted)" is appeneded to the path.
372
Tejun Heo65731572014-04-25 18:28:02 -0400373
Tejun Heo6abc8ca2015-08-04 15:20:55 -04003745-3. Controller File Conventions
Tejun Heo65731572014-04-25 18:28:02 -0400375
Tejun Heo6abc8ca2015-08-04 15:20:55 -04003765-3-1. Format
377
378In general, all controller files should be in one of the following
379formats whenever possible.
380
381- Values only files
382
383 VAL0 VAL1...\n
384
385- Flat keyed files
386
387 KEY0 VAL0\n
388 KEY1 VAL1\n
389 ...
390
391- Nested keyed files
392
393 KEY0 SUB_KEY0=VAL00 SUB_KEY1=VAL01...
394 KEY1 SUB_KEY0=VAL10 SUB_KEY1=VAL11...
395 ...
396
397For a writeable file, the format for writing should generally match
398reading; however, controllers may allow omitting later fields or
399implement restricted shortcuts for most common use cases.
400
401For both flat and nested keyed files, only the values for a single key
402can be written at a time. For nested keyed files, the sub key pairs
403may be specified in any order and not all pairs have to be specified.
404
405
4065-3-2. Control Knobs
407
408- Settings for a single feature should generally be implemented in a
409 single file.
410
411- In general, the root cgroup should be exempt from resource control
412 and thus shouldn't have resource control knobs.
413
414- If a controller implements ratio based resource distribution, the
415 control knob should be named "weight" and have the range [1, 10000]
416 and 100 should be the default value. The values are chosen to allow
417 enough and symmetric bias in both directions while keeping it
418 intuitive (the default is 100%).
419
420- If a controller implements an absolute resource guarantee and/or
421 limit, the control knobs should be named "min" and "max"
422 respectively. If a controller implements best effort resource
423 gurantee and/or limit, the control knobs should be named "low" and
424 "high" respectively.
425
426 In the above four control files, the special token "max" should be
427 used to represent upward infinity for both reading and writing.
428
429- If a setting has configurable default value and specific overrides,
430 the default settings should be keyed with "default" and appear as
431 the first entry in the file. Specific entries can use "default" as
432 its value to indicate inheritance of the default value.
433
Tejun Heo4a07c222015-09-18 17:54:22 -0400434- For events which are not very high frequency, an interface file
435 "events" should be created which lists event key value pairs.
436 Whenever a notifiable event happens, file modified event should be
437 generated on the file.
438
Tejun Heo6abc8ca2015-08-04 15:20:55 -0400439
4405-4. Per-Controller Changes
441
Tejun Heo2ee867dc2015-08-18 14:55:34 -07004425-4-1. io
Tejun Heo65731572014-04-25 18:28:02 -0400443
Tejun Heo2ee867dc2015-08-18 14:55:34 -0700444- blkio is renamed to io. The interface is overhauled anyway. The
445 new name is more in line with the other two major controllers, cpu
446 and memory, and better suited given that it may be used for cgroup
447 writeback without involving block layer.
448
449- Everything including stat is always hierarchical making separate
450 recursive stat files pointless and, as no internal node can have
451 tasks, leaf weights are meaningless. The operation model is
452 simplified and the interface is overhauled accordingly.
453
454 io.stat
455
456 The stat file. The reported stats are from the point where
457 bio's are issued to request_queue. The stats are counted
458 independent of which policies are enabled. Each line in the
459 file follows the following format. More fields may later be
460 added at the end.
461
462 $MAJ:$MIN rbytes=$RBYTES wbytes=$WBYTES rios=$RIOS wrios=$WIOS
463
464 io.weight
465
466 The weight setting, currently only available and effective if
467 cfq-iosched is in use for the target device. The weight is
Tejun Heo69d7fde2015-08-18 14:55:36 -0700468 between 1 and 10000 and defaults to 100. The first line
Tejun Heo2ee867dc2015-08-18 14:55:34 -0700469 always contains the default weight in the following format to
470 use when per-device setting is missing.
471
472 default $WEIGHT
473
474 Subsequent lines list per-device weights of the following
475 format.
476
477 $MAJ:$MIN $WEIGHT
478
479 Writing "$WEIGHT" or "default $WEIGHT" changes the default
480 setting. Writing "$MAJ:$MIN $WEIGHT" sets per-device weight
481 while "$MAJ:$MIN default" clears it.
482
483 This file is available only on non-root cgroups.
484
485 io.max
486
487 The maximum bandwidth and/or iops setting, only available if
488 blk-throttle is enabled. The file is of the following format.
489
490 $MAJ:$MIN rbps=$RBPS wbps=$WBPS riops=$RIOPS wiops=$WIOPS
491
492 ${R|W}BPS are read/write bytes per second and ${R|W}IOPS are
493 read/write IOs per second. "max" indicates no limit. Writing
494 to the file follows the same format but the individual
Yuan Sun55d01592015-09-22 17:00:06 +0800495 settings may be omitted or specified in any order.
Tejun Heo2ee867dc2015-08-18 14:55:34 -0700496
497 This file is available only on non-root cgroups.
Tejun Heo65731572014-04-25 18:28:02 -0400498
499
Tejun Heo6abc8ca2015-08-04 15:20:55 -04005005-4-2. cpuset
Tejun Heo65731572014-04-25 18:28:02 -0400501
502- Tasks are kept in empty cpusets after hotplug and take on the masks
503 of the nearest non-empty ancestor, instead of being moved to it.
504
505- A task can be moved into an empty cpuset, and again it takes on the
506 masks of the nearest non-empty ancestor.
507
508
Tejun Heo6abc8ca2015-08-04 15:20:55 -04005095-4-3. memory
Tejun Heo65731572014-04-25 18:28:02 -0400510
511- use_hierarchy is on by default and the cgroup file for the flag is
512 not created.
513
Johannes Weiner241994ed2015-02-11 15:26:06 -0800514- The original lower boundary, the soft limit, is defined as a limit
515 that is per default unset. As a result, the set of cgroups that
516 global reclaim prefers is opt-in, rather than opt-out. The costs
517 for optimizing these mostly negative lookups are so high that the
518 implementation, despite its enormous size, does not even provide the
519 basic desirable behavior. First off, the soft limit has no
520 hierarchical meaning. All configured groups are organized in a
521 global rbtree and treated like equal peers, regardless where they
522 are located in the hierarchy. This makes subtree delegation
523 impossible. Second, the soft limit reclaim pass is so aggressive
524 that it not just introduces high allocation latencies into the
525 system, but also impacts system performance due to overreclaim, to
526 the point where the feature becomes self-defeating.
527
528 The memory.low boundary on the other hand is a top-down allocated
529 reserve. A cgroup enjoys reclaim protection when it and all its
530 ancestors are below their low boundaries, which makes delegation of
531 subtrees possible. Secondly, new cgroups have no reserve per
532 default and in the common case most cgroups are eligible for the
533 preferred reclaim pass. This allows the new low boundary to be
534 efficiently implemented with just a minor addition to the generic
535 reclaim code, without the need for out-of-band data structures and
536 reclaim passes. Because the generic reclaim code considers all
537 cgroups except for the ones running low in the preferred first
538 reclaim pass, overreclaim of individual groups is eliminated as
539 well, resulting in much better overall workload performance.
540
541- The original high boundary, the hard limit, is defined as a strict
542 limit that can not budge, even if the OOM killer has to be called.
543 But this generally goes against the goal of making the most out of
544 the available memory. The memory consumption of workloads varies
545 during runtime, and that requires users to overcommit. But doing
546 that with a strict upper limit requires either a fairly accurate
547 prediction of the working set size or adding slack to the limit.
548 Since working set size estimation is hard and error prone, and
549 getting it wrong results in OOM kills, most users tend to err on the
550 side of a looser limit and end up wasting precious resources.
551
552 The memory.high boundary on the other hand can be set much more
553 conservatively. When hit, it throttles allocations by forcing them
554 into direct reclaim to work off the excess, but it never invokes the
555 OOM killer. As a result, a high boundary that is chosen too
556 aggressively will not terminate the processes, but instead it will
557 lead to gradual performance degradation. The user can monitor this
558 and make corrections until the minimal memory footprint that still
559 gives acceptable performance is found.
560
561 In extreme cases, with many concurrent allocations and a complete
562 breakdown of reclaim progress within the group, the high boundary
563 can be exceeded. But even then it's mostly better to satisfy the
564 allocation from the slack available in other groups or the rest of
565 the system than killing the group. Otherwise, memory.max is there
566 to limit this type of spillover and ultimately contain buggy or even
567 malicious applications.
568
569- The original control file names are unwieldy and inconsistent in
570 many different ways. For example, the upper boundary hit count is
571 exported in the memory.failcnt file, but an OOM event count has to
572 be manually counted by listening to memory.oom_control events, and
573 lower boundary / soft limit events have to be counted by first
574 setting a threshold for that value and then counting those events.
575 Also, usage and limit files encode their units in the filename.
576 That makes the filenames very long, even though this is not
577 information that a user needs to be reminded of every time they type
578 out those names.
579
580 To address these naming issues, as well as to signal clearly that
581 the new interface carries a new configuration model, the naming
582 conventions in it necessarily differ from the old interface.
583
584- The original limit files indicate the state of an unset limit with a
585 Very High Number, and a configured limit can be unset by echoing -1
586 into those files. But that very high number is implementation and
587 architecture dependent and not very descriptive. And while -1 can
588 be understood as an underflow into the highest possible value, -2 or
589 -10M etc. do not work, so it's not consistent.
590
Johannes Weinerd2973692015-02-27 15:52:04 -0800591 memory.low, memory.high, and memory.max will use the string "max" to
592 indicate and set the highest possible value.
Tejun Heo65731572014-04-25 18:28:02 -0400593
Tejun Heo8a0792e2015-06-18 16:54:28 -04005946. Planned Changes
Tejun Heo65731572014-04-25 18:28:02 -0400595
Tejun Heo8a0792e2015-06-18 16:54:28 -04005966-1. CAP for resource control
Tejun Heo65731572014-04-25 18:28:02 -0400597
598Unified hierarchy will require one of the capabilities(7), which is
599yet to be decided, for all resource control related knobs. Process
600organization operations - creation of sub-cgroups and migration of
601processes in sub-hierarchies may be delegated by changing the
602ownership and/or permissions on the cgroup directory and
603"cgroup.procs" interface file; however, all operations which affect
604resource control - writes to a "cgroup.subtree_control" file or any
605controller-specific knobs - will require an explicit CAP privilege.
606
607This, in part, is to prevent the cgroup interface from being
608inadvertently promoted to programmable API used by non-privileged
609binaries. cgroup exposes various aspects of the system in ways which
610aren't properly abstracted for direct consumption by regular programs.
611This is an administration interface much closer to sysctl knobs than
612system calls. Even the basic access model, being filesystem path
613based, isn't suitable for direct consumption. There's no way to
614access "my cgroup" in a race-free way or make multiple operations
615atomic against migration to another cgroup.
616
617Another aspect is that, for better or for worse, the cgroup interface
618goes through far less scrutiny than regular interfaces for
619unprivileged userland. The upside is that cgroup is able to expose
620useful features which may not be suitable for general consumption in a
621reasonable time frame. It provides a relatively short path between
622internal details and userland-visible interface. Of course, this
623shortcut comes with high risk. We go through what we go through for
624general kernel APIs for good reasons. It may end up leaking internal
625details in a way which can exert significant pain by locking the
626kernel into a contract that can't be maintained in a reasonable
627manner.
628
629Also, due to the specific nature, cgroup and its controllers don't
630tend to attract attention from a wide scope of developers. cgroup's
631short history is already fraught with severely mis-designed
632interfaces, unnecessary commitments to and exposing of internal
633details, broken and dangerous implementations of various features.
634
635Keeping cgroup as an administration interface is both advantageous for
636its role and imperative given its nature. Some of the cgroup features
637may make sense for unprivileged access. If deemed justified, those
638must be further abstracted and implemented as a different interface,
639be it a system call or process-private filesystem, and survive through
640the scrutiny that any interface for general consumption is required to
641go through.
642
643Requiring CAP is not a complete solution but should serve as a
644significant deterrent against spraying cgroup usages in non-privileged
645programs.