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