2021-01-20 00:18:19 +00:00
|
|
|
.. _cgroup-v2:
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
================
|
2015-11-16 16:13:34 +00:00
|
|
|
Control Group v2
|
2017-05-14 11:48:40 +00:00
|
|
|
================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
:Date: October, 2015
|
|
|
|
:Author: Tejun Heo <tj@kernel.org>
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
This is the authoritative documentation on the design, interface and
|
|
|
|
conventions of cgroup v2. It describes all userland-visible aspects
|
|
|
|
of cgroup including core and specific controller behaviors. All
|
|
|
|
future changes must be reflected in this document. Documentation for
|
2020-02-28 00:06:53 +00:00
|
|
|
v1 is available under :ref:`Documentation/admin-guide/cgroup-v1/index.rst <cgroup-v1>`.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
.. CONTENTS
|
|
|
|
|
|
|
|
1. Introduction
|
|
|
|
1-1. Terminology
|
|
|
|
1-2. What is cgroup?
|
|
|
|
2. Basic Operations
|
|
|
|
2-1. Mounting
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
2-2. Organizing Processes and Threads
|
|
|
|
2-2-1. Processes
|
|
|
|
2-2-2. Threads
|
2017-05-14 11:48:40 +00:00
|
|
|
2-3. [Un]populated Notification
|
|
|
|
2-4. Controlling Controllers
|
|
|
|
2-4-1. Enabling and Disabling
|
|
|
|
2-4-2. Top-down Constraint
|
|
|
|
2-4-3. No Internal Process Constraint
|
|
|
|
2-5. Delegation
|
|
|
|
2-5-1. Model of Delegation
|
|
|
|
2-5-2. Delegation Containment
|
|
|
|
2-6. Guidelines
|
|
|
|
2-6-1. Organize Once and Control
|
|
|
|
2-6-2. Avoid Name Collisions
|
|
|
|
3. Resource Distribution Models
|
|
|
|
3-1. Weights
|
|
|
|
3-2. Limits
|
|
|
|
3-3. Protections
|
|
|
|
3-4. Allocations
|
|
|
|
4. Interface Files
|
|
|
|
4-1. Format
|
|
|
|
4-2. Conventions
|
|
|
|
4-3. Core Interface Files
|
|
|
|
5. Controllers
|
|
|
|
5-1. CPU
|
|
|
|
5-1-1. CPU Interface Files
|
|
|
|
5-2. Memory
|
|
|
|
5-2-1. Memory Interface Files
|
|
|
|
5-2-2. Usage Guidelines
|
|
|
|
5-2-3. Memory Ownership
|
|
|
|
5-3. IO
|
|
|
|
5-3-1. IO Interface Files
|
|
|
|
5-3-2. Writeback
|
2018-07-03 15:15:02 +00:00
|
|
|
5-3-3. IO Latency
|
|
|
|
5-3-3-1. How IO Latency Throttling Works
|
|
|
|
5-3-3-2. IO Latency Interface Files
|
2021-06-18 00:44:44 +00:00
|
|
|
5-3-4. IO Priority
|
2017-05-14 11:48:40 +00:00
|
|
|
5-4. PID
|
|
|
|
5-4-1. PID Interface Files
|
2018-11-08 15:08:35 +00:00
|
|
|
5-5. Cpuset
|
|
|
|
5.5-1. Cpuset Interface Files
|
|
|
|
5-6. Device
|
|
|
|
5-7. RDMA
|
|
|
|
5-7-1. RDMA Interface Files
|
2019-12-16 19:38:31 +00:00
|
|
|
5-8. HugeTLB
|
|
|
|
5.8-1. HugeTLB Interface Files
|
2021-03-30 04:42:05 +00:00
|
|
|
5-9. Misc
|
|
|
|
5.9-1 Miscellaneous cgroup Interface Files
|
|
|
|
5.9-2 Migration and Ownership
|
|
|
|
5-10. Others
|
|
|
|
5-10-1. perf_event
|
2018-01-10 22:33:19 +00:00
|
|
|
5-N. Non-normative information
|
|
|
|
5-N-1. CPU controller root cgroup process behaviour
|
|
|
|
5-N-2. IO controller root cgroup process behaviour
|
2017-05-14 11:48:40 +00:00
|
|
|
6. Namespace
|
|
|
|
6-1. Basics
|
|
|
|
6-2. The Root and Views
|
|
|
|
6-3. Migration and setns(2)
|
|
|
|
6-4. Interaction with Other Namespaces
|
|
|
|
P. Information on Kernel Programming
|
|
|
|
P-1. Filesystem Support for Writeback
|
|
|
|
D. Deprecated v1 Core Features
|
|
|
|
R. Issues with v1 and Rationales for v2
|
|
|
|
R-1. Multiple Hierarchies
|
|
|
|
R-2. Thread Granularity
|
|
|
|
R-3. Competition Between Inner Nodes and Threads
|
|
|
|
R-4. Other Interface Issues
|
|
|
|
R-5. Controller Issues and Remedies
|
|
|
|
R-5-1. Memory
|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
|
|
|
|
Terminology
|
|
|
|
-----------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
"cgroup" stands for "control group" and is never capitalized. The
|
|
|
|
singular form is used to designate the whole feature and also as a
|
|
|
|
qualifier as in "cgroup controllers". When explicitly referring to
|
|
|
|
multiple individual control groups, the plural form "cgroups" is used.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
What is cgroup?
|
|
|
|
---------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cgroup is a mechanism to organize processes hierarchically and
|
|
|
|
distribute system resources along the hierarchy in a controlled and
|
|
|
|
configurable manner.
|
|
|
|
|
|
|
|
cgroup is largely composed of two parts - the core and controllers.
|
|
|
|
cgroup core is primarily responsible for hierarchically organizing
|
|
|
|
processes. A cgroup controller is usually responsible for
|
|
|
|
distributing a specific type of system resource along the hierarchy
|
|
|
|
although there are utility controllers which serve purposes other than
|
|
|
|
resource distribution.
|
|
|
|
|
|
|
|
cgroups form a tree structure and every process in the system belongs
|
|
|
|
to one and only one cgroup. All threads of a process belong to the
|
|
|
|
same cgroup. On creation, all processes are put in the cgroup that
|
|
|
|
the parent process belongs to at the time. A process can be migrated
|
|
|
|
to another cgroup. Migration of a process doesn't affect already
|
|
|
|
existing descendant processes.
|
|
|
|
|
|
|
|
Following certain structural constraints, controllers may be enabled or
|
|
|
|
disabled selectively on a cgroup. All controller behaviors are
|
|
|
|
hierarchical - if a controller is enabled on a cgroup, it affects all
|
|
|
|
processes which belong to the cgroups consisting the inclusive
|
|
|
|
sub-hierarchy of the cgroup. When a controller is enabled on a nested
|
|
|
|
cgroup, it always restricts the resource distribution further. The
|
|
|
|
restrictions set closer to the root in the hierarchy can not be
|
|
|
|
overridden from further away.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Basic Operations
|
|
|
|
================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Mounting
|
|
|
|
--------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Unlike v1, cgroup v2 has only single hierarchy. The cgroup v2
|
2017-05-14 11:48:40 +00:00
|
|
|
hierarchy can be mounted with the following mount command::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# mount -t cgroup2 none $MOUNT_POINT
|
|
|
|
|
|
|
|
cgroup2 filesystem has the magic number 0x63677270 ("cgrp"). All
|
|
|
|
controllers which support v2 and are not bound to a v1 hierarchy are
|
|
|
|
automatically bound to the v2 hierarchy and show up at the root.
|
|
|
|
Controllers which are not in active use in the v2 hierarchy can be
|
|
|
|
bound to other hierarchies. This allows mixing v2 hierarchy with the
|
|
|
|
legacy v1 multiple hierarchies in a fully backward compatible way.
|
|
|
|
|
|
|
|
A controller can be moved across hierarchies only after the controller
|
|
|
|
is no longer referenced in its current hierarchy. Because per-cgroup
|
|
|
|
controller states are destroyed asynchronously and controllers may
|
|
|
|
have lingering references, a controller may not show up immediately on
|
|
|
|
the v2 hierarchy after the final umount of the previous hierarchy.
|
|
|
|
Similarly, a controller should be fully disabled to be moved out of
|
|
|
|
the unified hierarchy and it may take some time for the disabled
|
|
|
|
controller to become available for other hierarchies; furthermore, due
|
|
|
|
to inter-controller dependencies, other controllers may need to be
|
|
|
|
disabled too.
|
|
|
|
|
|
|
|
While useful for development and manual configurations, moving
|
|
|
|
controllers dynamically between the v2 and other hierarchies is
|
|
|
|
strongly discouraged for production use. It is recommended to decide
|
|
|
|
the hierarchies and controller associations before starting using the
|
|
|
|
controllers after system boot.
|
|
|
|
|
2016-02-16 18:21:14 +00:00
|
|
|
During transition to v2, system management software might still
|
|
|
|
automount the v1 cgroup filesystem and so hijack all controllers
|
|
|
|
during boot, before manual intervention is possible. To make testing
|
|
|
|
and experimenting easier, the kernel parameter cgroup_no_v1= allows
|
|
|
|
disabling controllers in v1 and make them always available in v2.
|
|
|
|
|
2017-06-27 18:30:28 +00:00
|
|
|
cgroup v2 currently supports the following mount options.
|
|
|
|
|
cgroup: remove "no" prefixed mount options
30312730bd02 ("cgroup: Add "no" prefixed mount options") added "no" prefixed
mount options to allow turning them off and 6a010a49b63a ("cgroup: Make
!percpu threadgroup_rwsem operations optional") added one more "no" prefixed
mount option. However, Michal pointed out that the "no" prefixed options
aren't necessary in allowing mount options to be turned off:
# grep group /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot none /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,relatime,nsdelegate,memory_recursiveprot 0 0
Note that this is different from the remount behavior when the mount(1) is
invoked without the device argument - "none":
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
While a bit confusing, given that there is a way to turn off the options,
there's no reason to have the explicit "no" prefixed options. Let's remove
them.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2022-07-27 17:54:55 +00:00
|
|
|
nsdelegate
|
2017-06-27 18:30:28 +00:00
|
|
|
Consider cgroup namespaces as delegation boundaries. This
|
|
|
|
option is system wide and can only be set on mount or modified
|
|
|
|
through remount from the init namespace. The mount option is
|
|
|
|
ignored on non-init namespace mounts. Please refer to the
|
|
|
|
Delegation section for details.
|
|
|
|
|
cgroup: remove "no" prefixed mount options
30312730bd02 ("cgroup: Add "no" prefixed mount options") added "no" prefixed
mount options to allow turning them off and 6a010a49b63a ("cgroup: Make
!percpu threadgroup_rwsem operations optional") added one more "no" prefixed
mount option. However, Michal pointed out that the "no" prefixed options
aren't necessary in allowing mount options to be turned off:
# grep group /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot none /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,relatime,nsdelegate,memory_recursiveprot 0 0
Note that this is different from the remount behavior when the mount(1) is
invoked without the device argument - "none":
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
While a bit confusing, given that there is a way to turn off the options,
there's no reason to have the explicit "no" prefixed options. Let's remove
them.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2022-07-27 17:54:55 +00:00
|
|
|
favordynmods
|
2022-07-23 14:28:28 +00:00
|
|
|
Reduce the latencies of dynamic cgroup modifications such as
|
|
|
|
task migrations and controller on/offs at the cost of making
|
|
|
|
hot path operations such as forks and exits more expensive.
|
|
|
|
The static usage pattern of creating a cgroup, enabling
|
|
|
|
controllers, and then seeding it with CLONE_INTO_CGROUP is
|
|
|
|
not affected by this option.
|
|
|
|
|
cgroup: remove "no" prefixed mount options
30312730bd02 ("cgroup: Add "no" prefixed mount options") added "no" prefixed
mount options to allow turning them off and 6a010a49b63a ("cgroup: Make
!percpu threadgroup_rwsem operations optional") added one more "no" prefixed
mount option. However, Michal pointed out that the "no" prefixed options
aren't necessary in allowing mount options to be turned off:
# grep group /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot none /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,relatime,nsdelegate,memory_recursiveprot 0 0
Note that this is different from the remount behavior when the mount(1) is
invoked without the device argument - "none":
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
While a bit confusing, given that there is a way to turn off the options,
there's no reason to have the explicit "no" prefixed options. Let's remove
them.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2022-07-27 17:54:55 +00:00
|
|
|
memory_localevents
|
mm, memcg: consider subtrees in memory.events
memory.stat and other files already consider subtrees in their output, and
we should too in order to not present an inconsistent interface.
The current situation is fairly confusing, because people interacting with
cgroups expect hierarchical behaviour in the vein of memory.stat,
cgroup.events, and other files. For example, this causes confusion when
debugging reclaim events under low, as currently these always read "0" at
non-leaf memcg nodes, which frequently causes people to misdiagnose breach
behaviour. The same confusion applies to other counters in this file when
debugging issues.
Aggregation is done at write time instead of at read-time since these
counters aren't hot (unlike memory.stat which is per-page, so it does it
at read time), and it makes sense to bundle this with the file
notifications.
After this patch, events are propagated up the hierarchy:
[root@ktst ~]# cat /sys/fs/cgroup/system.slice/memory.events
low 0
high 0
max 0
oom 0
oom_kill 0
[root@ktst ~]# systemd-run -p MemoryMax=1 true
Running as unit: run-r251162a189fb4562b9dabfdc9b0422f5.service
[root@ktst ~]# cat /sys/fs/cgroup/system.slice/memory.events
low 0
high 0
max 7
oom 1
oom_kill 1
As this is a change in behaviour, this can be reverted to the old
behaviour by mounting with the `memory_localevents' flag set. However, we
use the new behaviour by default as there's a lack of evidence that there
are any current users of memory.events that would find this change
undesirable.
akpm: this is a behaviour change, so Cc:stable. THis is so that
forthcoming distros which use cgroup v2 are more likely to pick up the
revised behaviour.
Link: http://lkml.kernel.org/r/20190208224419.GA24772@chrisdown.name
Signed-off-by: Chris Down <chris@chrisdown.name>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Roman Gushchin <guro@fb.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-06-01 05:30:22 +00:00
|
|
|
Only populate memory.events with data for the current cgroup,
|
|
|
|
and not any subtrees. This is legacy behaviour, the default
|
|
|
|
behaviour without this option is to include subtree counts.
|
|
|
|
This option is system wide and can only be set on mount or
|
|
|
|
modified through remount from the init namespace. The mount
|
|
|
|
option is ignored on non-init namespace mounts.
|
|
|
|
|
cgroup: remove "no" prefixed mount options
30312730bd02 ("cgroup: Add "no" prefixed mount options") added "no" prefixed
mount options to allow turning them off and 6a010a49b63a ("cgroup: Make
!percpu threadgroup_rwsem operations optional") added one more "no" prefixed
mount option. However, Michal pointed out that the "no" prefixed options
aren't necessary in allowing mount options to be turned off:
# grep group /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot none /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,relatime,nsdelegate,memory_recursiveprot 0 0
Note that this is different from the remount behavior when the mount(1) is
invoked without the device argument - "none":
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
# mount -o remount,nsdelegate,memory_recursiveprot /sys/fs/cgroup
# grep cgroup /proc/mounts
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
While a bit confusing, given that there is a way to turn off the options,
there's no reason to have the explicit "no" prefixed options. Let's remove
them.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2022-07-27 17:54:55 +00:00
|
|
|
memory_recursiveprot
|
mm: memcontrol: recursive memory.low protection
Right now, the effective protection of any given cgroup is capped by its
own explicit memory.low setting, regardless of what the parent says. The
reasons for this are mostly historical and ease of implementation: to make
delegation of memory.low safe, effective protection is the min() of all
memory.low up the tree.
Unfortunately, this limitation makes it impossible to protect an entire
subtree from another without forcing the user to make explicit protection
allocations all the way to the leaf cgroups - something that is highly
undesirable in real life scenarios.
Consider memory in a data center host. At the cgroup top level, we have a
distinction between system management software and the actual workload the
system is executing. Both branches are further subdivided into individual
services, job components etc.
We want to protect the workload as a whole from the system management
software, but that doesn't mean we want to protect and prioritize
individual workload wrt each other. Their memory demand can vary over
time, and we'd want the VM to simply cache the hottest data within the
workload subtree. Yet, the current memory.low limitations force us to
allocate a fixed amount of protection to each workload component in order
to get protection from system management software in general. This
results in very inefficient resource distribution.
Another concern with mandating downward allocation is that, as the
complexity of the cgroup tree grows, it gets harder for the lower levels
to be informed about decisions made at the host-level. Consider a
container inside a namespace that in turn creates its own nested tree of
cgroups to run multiple workloads. It'd be extremely difficult to
configure memory.low parameters in those leaf cgroups that on one hand
balance pressure among siblings as the container desires, while also
reflecting the host-level protection from e.g. rpm upgrades, that lie
beyond one or more delegation and namespacing points in the tree.
It's highly unusual from a cgroup interface POV that nested levels have to
be aware of and reflect decisions made at higher levels for them to be
effective.
To enable such use cases and scale configurability for complex trees, this
patch implements a resource inheritance model for memory that is similar
to how the CPU and the IO controller implement work-conserving resource
allocations: a share of a resource allocated to a subree always applies to
the entire subtree recursively, while allowing, but not mandating,
children to further specify distribution rules.
That means that if protection is explicitly allocated among siblings,
those configured shares are being followed during page reclaim just like
they are now. However, if the memory.low set at a higher level is not
fully claimed by the children in that subtree, the "floating" remainder is
applied to each cgroup in the tree in proportion to its size. Since
reclaim pressure is applied in proportion to size as well, each child in
that tree gets the same boost, and the effect is neutral among siblings -
with respect to each other, they behave as if no memory control was
enabled at all, and the VM simply balances the memory demands optimally
within the subtree. But collectively those cgroups enjoy a boost over the
cgroups in neighboring trees.
E.g. a leaf cgroup with a memory.low setting of 0 no longer means that
it's not getting a share of the hierarchically assigned resource, just
that it doesn't claim a fixed amount of it to protect from its siblings.
This allows us to recursively protect one subtree (workload) from another
(system management), while letting subgroups compete freely among each
other - without having to assign fixed shares to each leaf, and without
nested groups having to echo higher-level settings.
The floating protection composes naturally with fixed protection.
Consider the following example tree:
A A: low = 2G
/ \ A1: low = 1G
A1 A2 A2: low = 0G
As outside pressure is applied to this tree, A1 will enjoy a fixed
protection from A2 of 1G, but the remaining, unclaimed 1G from A is split
evenly among A1 and A2, coming out to 1.5G and 0.5G.
There is a slight risk of regressing theoretical setups where the
top-level cgroups don't know about the true budgeting and set bogusly high
"bypass" values that are meaningfully allocated down the tree. Such
setups would rely on unclaimed protection to be discarded, and
distributing it would change the intended behavior. Be safe and hide the
new behavior behind a mount option, 'memory_recursiveprot'.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Roman Gushchin <guro@fb.com>
Acked-by: Chris Down <chris@chrisdown.name>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Michal Koutný <mkoutny@suse.com>
Link: http://lkml.kernel.org/r/20200227195606.46212-4-hannes@cmpxchg.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-02 04:07:07 +00:00
|
|
|
Recursively apply memory.min and memory.low protection to
|
|
|
|
entire subtrees, without requiring explicit downward
|
|
|
|
propagation into leaf cgroups. This allows protecting entire
|
|
|
|
subtrees from one another, while retaining free competition
|
|
|
|
within those subtrees. This should have been the default
|
|
|
|
behavior but is a mount-option to avoid regressing setups
|
|
|
|
relying on the original semantics (e.g. specifying bogusly
|
|
|
|
high 'bypass' protection values at higher tree levels).
|
|
|
|
|
hugetlb: memcg: account hugetlb-backed memory in memory controller
Currently, hugetlb memory usage is not acounted for in the memory
controller, which could lead to memory overprotection for cgroups with
hugetlb-backed memory. This has been observed in our production system.
For instance, here is one of our usecases: suppose there are two 32G
containers. The machine is booted with hugetlb_cma=6G, and each container
may or may not use up to 3 gigantic page, depending on the workload within
it. The rest is anon, cache, slab, etc. We can set the hugetlb cgroup
limit of each cgroup to 3G to enforce hugetlb fairness. But it is very
difficult to configure memory.max to keep overall consumption, including
anon, cache, slab etc. fair.
What we have had to resort to is to constantly poll hugetlb usage and
readjust memory.max. Similar procedure is done to other memory limits
(memory.low for e.g). However, this is rather cumbersome and buggy.
Furthermore, when there is a delay in memory limits correction, (for e.g
when hugetlb usage changes within consecutive runs of the userspace
agent), the system could be in an over/underprotected state.
This patch rectifies this issue by charging the memcg when the hugetlb
folio is utilized, and uncharging when the folio is freed (analogous to
the hugetlb controller). Note that we do not charge when the folio is
allocated to the hugetlb pool, because at this point it is not owned by
any memcg.
Some caveats to consider:
* This feature is only available on cgroup v2.
* There is no hugetlb pool management involved in the memory
controller. As stated above, hugetlb folios are only charged towards
the memory controller when it is used. Host overcommit management
has to consider it when configuring hard limits.
* Failure to charge towards the memcg results in SIGBUS. This could
happen even if the hugetlb pool still has pages (but the cgroup
limit is hit and reclaim attempt fails).
* When this feature is enabled, hugetlb pages contribute to memory
reclaim protection. low, min limits tuning must take into account
hugetlb memory.
* Hugetlb pages utilized while this option is not selected will not
be tracked by the memory controller (even if cgroup v2 is remounted
later on).
Link: https://lkml.kernel.org/r/20231006184629.155543-4-nphamcs@gmail.com
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Frank van der Linden <fvdl@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Rik van Riel <riel@surriel.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Tejun heo <tj@kernel.org>
Cc: Yosry Ahmed <yosryahmed@google.com>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-10-06 18:46:28 +00:00
|
|
|
memory_hugetlb_accounting
|
|
|
|
Count HugeTLB memory usage towards the cgroup's overall
|
|
|
|
memory usage for the memory controller (for the purpose of
|
|
|
|
statistics reporting and memory protetion). This is a new
|
|
|
|
behavior that could regress existing setups, so it must be
|
|
|
|
explicitly opted in with this mount option.
|
|
|
|
|
|
|
|
A few caveats to keep in mind:
|
|
|
|
|
|
|
|
* There is no HugeTLB pool management involved in the memory
|
|
|
|
controller. The pre-allocated pool does not belong to anyone.
|
|
|
|
Specifically, when a new HugeTLB folio is allocated to
|
|
|
|
the pool, it is not accounted for from the perspective of the
|
|
|
|
memory controller. It is only charged to a cgroup when it is
|
|
|
|
actually used (for e.g at page fault time). Host memory
|
|
|
|
overcommit management has to consider this when configuring
|
|
|
|
hard limits. In general, HugeTLB pool management should be
|
|
|
|
done via other mechanisms (such as the HugeTLB controller).
|
|
|
|
* Failure to charge a HugeTLB folio to the memory controller
|
|
|
|
results in SIGBUS. This could happen even if the HugeTLB pool
|
|
|
|
still has pages available (but the cgroup limit is hit and
|
|
|
|
reclaim attempt fails).
|
|
|
|
* Charging HugeTLB memory towards the memory controller affects
|
|
|
|
memory protection and reclaim dynamics. Any userspace tuning
|
|
|
|
(of low, min limits for e.g) needs to take this into account.
|
|
|
|
* HugeTLB pages utilized while this option is not selected
|
|
|
|
will not be tracked by the memory controller (even if cgroup
|
|
|
|
v2 is remounted later on).
|
|
|
|
|
2024-05-21 09:21:26 +00:00
|
|
|
pids_localevents
|
2024-05-21 09:21:27 +00:00
|
|
|
The option restores v1-like behavior of pids.events:max, that is only
|
|
|
|
local (inside cgroup proper) fork failures are counted. Without this
|
|
|
|
option pids.events.max represents any pids.max enforcemnt across
|
|
|
|
cgroup's subtree.
|
|
|
|
|
2024-05-21 09:21:26 +00:00
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
Organizing Processes and Threads
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
Processes
|
|
|
|
~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Initially, only the root cgroup exists to which all processes belong.
|
2017-05-14 11:48:40 +00:00
|
|
|
A child cgroup can be created by creating a sub-directory::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# mkdir $CGROUP_NAME
|
|
|
|
|
|
|
|
A given cgroup may have multiple child cgroups forming a tree
|
|
|
|
structure. Each cgroup has a read-writable interface file
|
|
|
|
"cgroup.procs". When read, it lists the PIDs of all processes which
|
|
|
|
belong to the cgroup one-per-line. The PIDs are not ordered and the
|
|
|
|
same PID may show up more than once if the process got moved to
|
|
|
|
another cgroup and then back or the PID got recycled while reading.
|
|
|
|
|
|
|
|
A process can be migrated into a cgroup by writing its PID to the
|
|
|
|
target cgroup's "cgroup.procs" file. Only one process can be migrated
|
|
|
|
on a single write(2) call. If a process is composed of multiple
|
|
|
|
threads, writing the PID of any thread migrates all threads of the
|
|
|
|
process.
|
|
|
|
|
|
|
|
When a process forks a child process, the new process is born into the
|
|
|
|
cgroup that the forking process belongs to at the time of the
|
|
|
|
operation. After exit, a process stays associated with the cgroup
|
|
|
|
that it belonged to at the time of exit until it's reaped; however, a
|
|
|
|
zombie process does not appear in "cgroup.procs" and thus can't be
|
|
|
|
moved to another cgroup.
|
|
|
|
|
|
|
|
A cgroup which doesn't have any children or live processes can be
|
|
|
|
destroyed by removing the directory. Note that a cgroup which doesn't
|
|
|
|
have any children and is associated only with zombie processes is
|
2017-05-14 11:48:40 +00:00
|
|
|
considered empty and can be removed::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# rmdir $CGROUP_NAME
|
|
|
|
|
|
|
|
"/proc/$PID/cgroup" lists a process's cgroup membership. If legacy
|
|
|
|
cgroup is in use in the system, this file may contain multiple lines,
|
|
|
|
one for each hierarchy. The entry for cgroup v2 is always in the
|
2017-05-14 11:48:40 +00:00
|
|
|
format "0::$PATH"::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# cat /proc/842/cgroup
|
|
|
|
...
|
|
|
|
0::/test-cgroup/test-cgroup-nested
|
|
|
|
|
|
|
|
If the process becomes a zombie and the cgroup it was associated with
|
2017-05-14 11:48:40 +00:00
|
|
|
is removed subsequently, " (deleted)" is appended to the path::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# cat /proc/842/cgroup
|
|
|
|
...
|
|
|
|
0::/test-cgroup/test-cgroup-nested (deleted)
|
|
|
|
|
|
|
|
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
Threads
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
cgroup v2 supports thread granularity for a subset of controllers to
|
|
|
|
support use cases requiring hierarchical resource distribution across
|
|
|
|
the threads of a group of processes. By default, all threads of a
|
|
|
|
process belong to the same cgroup, which also serves as the resource
|
|
|
|
domain to host resource consumptions which are not specific to a
|
|
|
|
process or thread. The thread mode allows threads to be spread across
|
|
|
|
a subtree while still maintaining the common resource domain for them.
|
|
|
|
|
|
|
|
Controllers which support thread mode are called threaded controllers.
|
|
|
|
The ones which don't are called domain controllers.
|
|
|
|
|
|
|
|
Marking a cgroup threaded makes it join the resource domain of its
|
|
|
|
parent as a threaded cgroup. The parent may be another threaded
|
|
|
|
cgroup whose resource domain is further up in the hierarchy. The root
|
|
|
|
of a threaded subtree, that is, the nearest ancestor which is not
|
|
|
|
threaded, is called threaded domain or thread root interchangeably and
|
|
|
|
serves as the resource domain for the entire subtree.
|
|
|
|
|
|
|
|
Inside a threaded subtree, threads of a process can be put in
|
|
|
|
different cgroups and are not subject to the no internal process
|
|
|
|
constraint - threaded controllers can be enabled on non-leaf cgroups
|
|
|
|
whether they have threads in them or not.
|
|
|
|
|
|
|
|
As the threaded domain cgroup hosts all the domain resource
|
|
|
|
consumptions of the subtree, it is considered to have internal
|
|
|
|
resource consumptions whether there are processes in it or not and
|
|
|
|
can't have populated child cgroups which aren't threaded. Because the
|
|
|
|
root cgroup is not subject to no internal process constraint, it can
|
|
|
|
serve both as a threaded domain and a parent to domain cgroups.
|
|
|
|
|
|
|
|
The current operation mode or type of the cgroup is shown in the
|
|
|
|
"cgroup.type" file which indicates whether the cgroup is a normal
|
|
|
|
domain, a domain which is serving as the domain of a threaded subtree,
|
|
|
|
or a threaded cgroup.
|
|
|
|
|
|
|
|
On creation, a cgroup is always a domain cgroup and can be made
|
|
|
|
threaded by writing "threaded" to the "cgroup.type" file. The
|
|
|
|
operation is single direction::
|
|
|
|
|
|
|
|
# echo threaded > cgroup.type
|
|
|
|
|
|
|
|
Once threaded, the cgroup can't be made a domain again. To enable the
|
|
|
|
thread mode, the following conditions must be met.
|
|
|
|
|
|
|
|
- As the cgroup will join the parent's resource domain. The parent
|
|
|
|
must either be a valid (threaded) domain or a threaded cgroup.
|
|
|
|
|
2017-07-23 12:18:26 +00:00
|
|
|
- When the parent is an unthreaded domain, it must not have any domain
|
|
|
|
controllers enabled or populated domain children. The root is
|
|
|
|
exempt from this requirement.
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
|
|
|
|
Topology-wise, a cgroup can be in an invalid state. Please consider
|
2018-01-02 16:27:41 +00:00
|
|
|
the following topology::
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
|
|
|
|
A (threaded domain) - B (threaded) - C (domain, just created)
|
|
|
|
|
|
|
|
C is created as a domain but isn't connected to a parent which can
|
|
|
|
host child domains. C can't be used until it is turned into a
|
|
|
|
threaded cgroup. "cgroup.type" file will report "domain (invalid)" in
|
|
|
|
these cases. Operations which fail due to invalid topology use
|
|
|
|
EOPNOTSUPP as the errno.
|
|
|
|
|
|
|
|
A domain cgroup is turned into a threaded domain when one of its child
|
|
|
|
cgroup becomes threaded or threaded controllers are enabled in the
|
|
|
|
"cgroup.subtree_control" file while there are processes in the cgroup.
|
|
|
|
A threaded domain reverts to a normal domain when the conditions
|
|
|
|
clear.
|
|
|
|
|
|
|
|
When read, "cgroup.threads" contains the list of the thread IDs of all
|
|
|
|
threads in the cgroup. Except that the operations are per-thread
|
|
|
|
instead of per-process, "cgroup.threads" has the same format and
|
|
|
|
behaves the same way as "cgroup.procs". While "cgroup.threads" can be
|
|
|
|
written to in any cgroup, as it can only move threads inside the same
|
|
|
|
threaded domain, its operations are confined inside each threaded
|
|
|
|
subtree.
|
|
|
|
|
|
|
|
The threaded domain cgroup serves as the resource domain for the whole
|
|
|
|
subtree, and, while the threads can be scattered across the subtree,
|
|
|
|
all the processes are considered to be in the threaded domain cgroup.
|
|
|
|
"cgroup.procs" in a threaded domain cgroup contains the PIDs of all
|
|
|
|
processes in the subtree and is not readable in the subtree proper.
|
|
|
|
However, "cgroup.procs" can be written to from anywhere in the subtree
|
|
|
|
to migrate all threads of the matching process to the cgroup.
|
|
|
|
|
|
|
|
Only threaded controllers can be enabled in a threaded subtree. When
|
|
|
|
a threaded controller is enabled inside a threaded subtree, it only
|
|
|
|
accounts for and controls resource consumptions associated with the
|
|
|
|
threads in the cgroup and its descendants. All consumptions which
|
|
|
|
aren't tied to a specific thread belong to the threaded domain cgroup.
|
|
|
|
|
|
|
|
Because a threaded subtree is exempt from no internal process
|
|
|
|
constraint, a threaded controller must be able to handle competition
|
|
|
|
between threads in a non-leaf cgroup and its child cgroups. Each
|
|
|
|
threaded controller defines how such competitions are handled.
|
|
|
|
|
2023-10-17 17:13:41 +00:00
|
|
|
Currently, the following controllers are threaded and can be enabled
|
|
|
|
in a threaded cgroup::
|
|
|
|
|
|
|
|
- cpu
|
|
|
|
- cpuset
|
|
|
|
- perf_event
|
|
|
|
- pids
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
[Un]populated Notification
|
|
|
|
--------------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Each non-root cgroup has a "cgroup.events" file which contains
|
|
|
|
"populated" field indicating whether the cgroup's sub-hierarchy has
|
|
|
|
live processes in it. Its value is 0 if there is no live process in
|
|
|
|
the cgroup and its descendants; otherwise, 1. poll and [id]notify
|
|
|
|
events are triggered when the value changes. This can be used, for
|
|
|
|
example, to start a clean-up operation after all processes of a given
|
|
|
|
sub-hierarchy have exited. The populated state updates and
|
|
|
|
notifications are recursive. Consider the following sub-hierarchy
|
|
|
|
where the numbers in the parentheses represent the numbers of processes
|
2017-05-14 11:48:40 +00:00
|
|
|
in each cgroup::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A(4) - B(0) - C(1)
|
|
|
|
\ D(0)
|
|
|
|
|
|
|
|
A, B and C's "populated" fields would be 1 while D's 0. After the one
|
|
|
|
process in C exits, B and C's "populated" fields would flip to "0" and
|
|
|
|
file modified events will be generated on the "cgroup.events" files of
|
|
|
|
both cgroups.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Controlling Controllers
|
|
|
|
-----------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Enabling and Disabling
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Each cgroup has a "cgroup.controllers" file which lists all
|
2017-05-14 11:48:40 +00:00
|
|
|
controllers available for the cgroup to enable::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# cat cgroup.controllers
|
|
|
|
cpu io memory
|
|
|
|
|
|
|
|
No controller is enabled by default. Controllers can be enabled and
|
2017-05-14 11:48:40 +00:00
|
|
|
disabled by writing to the "cgroup.subtree_control" file::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# echo "+cpu +memory -io" > cgroup.subtree_control
|
|
|
|
|
|
|
|
Only controllers which are listed in "cgroup.controllers" can be
|
|
|
|
enabled. When multiple operations are specified as above, either they
|
|
|
|
all succeed or fail. If multiple operations on the same controller
|
|
|
|
are specified, the last one is effective.
|
|
|
|
|
|
|
|
Enabling a controller in a cgroup indicates that the distribution of
|
|
|
|
the target resource across its immediate children will be controlled.
|
|
|
|
Consider the following sub-hierarchy. The enabled controllers are
|
2017-05-14 11:48:40 +00:00
|
|
|
listed in parentheses::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A(cpu,memory) - B(memory) - C()
|
|
|
|
\ D()
|
|
|
|
|
|
|
|
As A has "cpu" and "memory" enabled, A will control the distribution
|
|
|
|
of CPU cycles and memory to its children, in this case, B. As B has
|
|
|
|
"memory" enabled but not "CPU", C and D will compete freely on CPU
|
|
|
|
cycles but their division of memory available to B will be controlled.
|
|
|
|
|
|
|
|
As a controller regulates the distribution of the target resource to
|
|
|
|
the cgroup's children, enabling it creates the controller's interface
|
|
|
|
files in the child cgroups. In the above example, enabling "cpu" on B
|
|
|
|
would create the "cpu." prefixed controller interface files in C and
|
|
|
|
D. Likewise, disabling "memory" from B would remove the "memory."
|
|
|
|
prefixed controller interface files from C and D. This means that the
|
|
|
|
controller interface files - anything which doesn't start with
|
|
|
|
"cgroup." are owned by the parent rather than the cgroup itself.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Top-down Constraint
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Resources are distributed top-down and a cgroup can further distribute
|
|
|
|
a resource only if the resource has been distributed to it from the
|
|
|
|
parent. This means that all non-root "cgroup.subtree_control" files
|
|
|
|
can only contain controllers which are enabled in the parent's
|
|
|
|
"cgroup.subtree_control" file. A controller can be enabled only if
|
|
|
|
the parent has the controller enabled and a controller can't be
|
|
|
|
disabled if one or more children have it enabled.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
No Internal Process Constraint
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
Non-root cgroups can distribute domain resources to their children
|
|
|
|
only when they don't have any processes of their own. In other words,
|
|
|
|
only domain cgroups which don't contain any processes can have domain
|
|
|
|
controllers enabled in their "cgroup.subtree_control" files.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
This guarantees that, when a domain controller is looking at the part
|
|
|
|
of the hierarchy which has it enabled, processes are always only on
|
|
|
|
the leaves. This rules out situations where child cgroups compete
|
|
|
|
against internal processes of the parent.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
The root cgroup is exempt from this restriction. Root contains
|
|
|
|
processes and anonymous resource consumption which can't be associated
|
|
|
|
with any other cgroups and requires special treatment from most
|
|
|
|
controllers. How resource consumption in the root cgroup is governed
|
2018-01-10 22:33:19 +00:00
|
|
|
is up to each controller (for more information on this topic please
|
|
|
|
refer to the Non-normative information section in the Controllers
|
|
|
|
chapter).
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Note that the restriction doesn't get in the way if there is no
|
|
|
|
enabled controller in the cgroup's "cgroup.subtree_control". This is
|
|
|
|
important as otherwise it wouldn't be possible to create children of a
|
|
|
|
populated cgroup. To control resource distribution of a cgroup, the
|
|
|
|
cgroup must create children and transfer all its processes to the
|
|
|
|
children before enabling controllers in its "cgroup.subtree_control"
|
|
|
|
file.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Delegation
|
|
|
|
----------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Model of Delegation
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-06-27 18:30:28 +00:00
|
|
|
A cgroup can be delegated in two ways. First, to a less privileged
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
user by granting write access of the directory and its "cgroup.procs",
|
|
|
|
"cgroup.threads" and "cgroup.subtree_control" files to the user.
|
|
|
|
Second, if the "nsdelegate" mount option is set, automatically to a
|
|
|
|
cgroup namespace on namespace creation.
|
2017-06-27 18:30:28 +00:00
|
|
|
|
|
|
|
Because the resource control interface files in a given directory
|
|
|
|
control the distribution of the parent's resources, the delegatee
|
|
|
|
shouldn't be allowed to write to them. For the first method, this is
|
2024-08-15 13:14:08 +00:00
|
|
|
achieved by not granting access to these files. For the second, files
|
|
|
|
outside the namespace should be hidden from the delegatee by the means
|
|
|
|
of at least mount namespacing, and the kernel rejects writes to all
|
|
|
|
files on a namespace root from inside the cgroup namespace, except for
|
|
|
|
those files listed in "/sys/kernel/cgroup/delegate" (including
|
|
|
|
"cgroup.procs", "cgroup.threads", "cgroup.subtree_control", etc.).
|
2017-06-27 18:30:28 +00:00
|
|
|
|
|
|
|
The end results are equivalent for both delegation types. Once
|
|
|
|
delegated, the user can build sub-hierarchy under the directory,
|
|
|
|
organize processes inside it as it sees fit and further distribute the
|
|
|
|
resources it received from the parent. The limits and other settings
|
|
|
|
of all resource controllers are hierarchical and regardless of what
|
|
|
|
happens in the delegated sub-hierarchy, nothing can escape the
|
|
|
|
resource restrictions imposed by the parent.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Currently, cgroup doesn't impose any restrictions on the number of
|
|
|
|
cgroups in or nesting depth of a delegated sub-hierarchy; however,
|
|
|
|
this may be limited explicitly in the future.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Delegation Containment
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A delegated sub-hierarchy is contained in the sense that processes
|
2017-06-27 18:30:28 +00:00
|
|
|
can't be moved into or out of the sub-hierarchy by the delegatee.
|
|
|
|
|
|
|
|
For delegations to a less privileged user, this is achieved by
|
|
|
|
requiring the following conditions for a process with a non-root euid
|
|
|
|
to migrate a target process into a cgroup by writing its PID to the
|
|
|
|
"cgroup.procs" file.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
- The writer must have write access to the "cgroup.procs" file.
|
|
|
|
|
|
|
|
- The writer must have write access to the "cgroup.procs" file of the
|
|
|
|
common ancestor of the source and destination cgroups.
|
|
|
|
|
2017-01-20 16:29:54 +00:00
|
|
|
The above two constraints ensure that while a delegatee may migrate
|
2015-11-16 16:13:34 +00:00
|
|
|
processes around freely in the delegated sub-hierarchy it can't pull
|
|
|
|
in from or push out to outside the sub-hierarchy.
|
|
|
|
|
|
|
|
For an example, let's assume cgroups C0 and C1 have been delegated to
|
|
|
|
user U0 who created C00, C01 under C0 and C10 under C1 as follows and
|
2017-05-14 11:48:40 +00:00
|
|
|
all processes under C0 and C1 belong to U0::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
~~~~~~~~~~~~~ - C0 - C00
|
|
|
|
~ cgroup ~ \ C01
|
|
|
|
~ hierarchy ~
|
|
|
|
~~~~~~~~~~~~~ - C1 - C10
|
|
|
|
|
|
|
|
Let's also say U0 wants to write the PID of a process which is
|
|
|
|
currently in C10 into "C00/cgroup.procs". U0 has write access to the
|
2017-01-20 16:29:54 +00:00
|
|
|
file; however, the common ancestor of the source cgroup C10 and the
|
|
|
|
destination cgroup C00 is above the points of delegation and U0 would
|
|
|
|
not have write access to its "cgroup.procs" files and thus the write
|
|
|
|
will be denied with -EACCES.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-06-27 18:30:28 +00:00
|
|
|
For delegations to namespaces, containment is achieved by requiring
|
|
|
|
that both the source and destination cgroups are reachable from the
|
|
|
|
namespace of the process which is attempting the migration. If either
|
|
|
|
is not reachable, the migration is rejected with -ENOENT.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Guidelines
|
|
|
|
----------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Organize Once and Control
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Migrating a process across cgroups is a relatively expensive operation
|
|
|
|
and stateful resources such as memory are not moved together with the
|
|
|
|
process. This is an explicit design decision as there often exist
|
|
|
|
inherent trade-offs between migration and various hot paths in terms
|
|
|
|
of synchronization cost.
|
|
|
|
|
|
|
|
As such, migrating processes across cgroups frequently as a means to
|
|
|
|
apply different resource restrictions is discouraged. A workload
|
|
|
|
should be assigned to a cgroup according to the system's logical and
|
|
|
|
resource structure once on start-up. Dynamic adjustments to resource
|
|
|
|
distribution can be made by changing controller configuration through
|
|
|
|
the interface files.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Avoid Name Collisions
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Interface files for a cgroup and its children cgroups occupy the same
|
|
|
|
directory and it is possible to create children cgroups which collide
|
|
|
|
with interface files.
|
|
|
|
|
|
|
|
All cgroup core interface files are prefixed with "cgroup." and each
|
|
|
|
controller's interface files are prefixed with the controller name and
|
|
|
|
a dot. A controller's name is composed of lower case alphabets and
|
|
|
|
'_'s but never begins with an '_' so it can be used as the prefix
|
|
|
|
character for collision avoidance. Also, interface file names won't
|
|
|
|
start or end with terms which are often used in categorizing workloads
|
|
|
|
such as job, service, slice, unit or workload.
|
|
|
|
|
|
|
|
cgroup doesn't do anything to prevent name collisions and it's the
|
|
|
|
user's responsibility to avoid them.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Resource Distribution Models
|
|
|
|
============================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cgroup controllers implement several resource distribution schemes
|
|
|
|
depending on the resource type and expected use cases. This section
|
|
|
|
describes major schemes in use along with their expected behaviors.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Weights
|
|
|
|
-------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A parent's resource is distributed by adding up the weights of all
|
|
|
|
active children and giving each the fraction matching the ratio of its
|
|
|
|
weight against the sum. As only children which can make use of the
|
|
|
|
resource at the moment participate in the distribution, this is
|
|
|
|
work-conserving. Due to the dynamic nature, this model is usually
|
|
|
|
used for stateless resources.
|
|
|
|
|
|
|
|
All weights are in the range [1, 10000] with the default at 100. This
|
|
|
|
allows symmetric multiplicative biases in both directions at fine
|
|
|
|
enough granularity while staying in the intuitive range.
|
|
|
|
|
|
|
|
As long as the weight is in range, all configuration combinations are
|
|
|
|
valid and there is no reason to reject configuration changes or
|
|
|
|
process migrations.
|
|
|
|
|
|
|
|
"cpu.weight" proportionally distributes CPU cycles to active children
|
|
|
|
and is an example of this type.
|
|
|
|
|
|
|
|
|
2022-12-16 23:57:16 +00:00
|
|
|
.. _cgroupv2-limits-distributor:
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Limits
|
|
|
|
------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2023-01-29 23:10:45 +00:00
|
|
|
A child can only consume up to the configured amount of the resource.
|
2015-11-16 16:13:34 +00:00
|
|
|
Limits can be over-committed - the sum of the limits of children can
|
|
|
|
exceed the amount of resource available to the parent.
|
|
|
|
|
|
|
|
Limits are in the range [0, max] and defaults to "max", which is noop.
|
|
|
|
|
|
|
|
As limits can be over-committed, all configuration combinations are
|
|
|
|
valid and there is no reason to reject configuration changes or
|
|
|
|
process migrations.
|
|
|
|
|
|
|
|
"io.max" limits the maximum BPS and/or IOPS that a cgroup can consume
|
|
|
|
on an IO device and is an example of this type.
|
|
|
|
|
2022-12-16 23:57:16 +00:00
|
|
|
.. _cgroupv2-protections-distributor:
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Protections
|
|
|
|
-----------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2023-01-29 23:10:45 +00:00
|
|
|
A cgroup is protected up to the configured amount of the resource
|
mm, memcg: proportional memory.{low,min} reclaim
cgroup v2 introduces two memory protection thresholds: memory.low
(best-effort) and memory.min (hard protection). While they generally do
what they say on the tin, there is a limitation in their implementation
that makes them difficult to use effectively: that cliff behaviour often
manifests when they become eligible for reclaim. This patch implements
more intuitive and usable behaviour, where we gradually mount more
reclaim pressure as cgroups further and further exceed their protection
thresholds.
This cliff edge behaviour happens because we only choose whether or not
to reclaim based on whether the memcg is within its protection limits
(see the use of mem_cgroup_protected in shrink_node), but we don't vary
our reclaim behaviour based on this information. Imagine the following
timeline, with the numbers the lruvec size in this zone:
1. memory.low=1000000, memory.current=999999. 0 pages may be scanned.
2. memory.low=1000000, memory.current=1000000. 0 pages may be scanned.
3. memory.low=1000000, memory.current=1000001. 1000001* pages may be
scanned. (?!)
* Of course, we won't usually scan all available pages in the zone even
without this patch because of scan control priority, over-reclaim
protection, etc. However, as shown by the tests at the end, these
techniques don't sufficiently throttle such an extreme change in input,
so cliff-like behaviour isn't really averted by their existence alone.
Here's an example of how this plays out in practice. At Facebook, we are
trying to protect various workloads from "system" software, like
configuration management tools, metric collectors, etc (see this[0] case
study). In order to find a suitable memory.low value, we start by
determining the expected memory range within which the workload will be
comfortable operating. This isn't an exact science -- memory usage deemed
"comfortable" will vary over time due to user behaviour, differences in
composition of work, etc, etc. As such we need to ballpark memory.low,
but doing this is currently problematic:
1. If we end up setting it too low for the workload, it won't have
*any* effect (see discussion above). The group will receive the full
weight of reclaim and won't have any priority while competing with the
less important system software, as if we had no memory.low configured
at all.
2. Because of this behaviour, we end up erring on the side of setting
it too high, such that the comfort range is reliably covered. However,
protected memory is completely unavailable to the rest of the system,
so we might cause undue memory and IO pressure there when we *know* we
have some elasticity in the workload.
3. Even if we get the value totally right, smack in the middle of the
comfort zone, we get extreme jumps between no pressure and full
pressure that cause unpredictable pressure spikes in the workload due
to the current binary reclaim behaviour.
With this patch, we can set it to our ballpark estimation without too much
worry. Any undesirable behaviour, such as too much or too little reclaim
pressure on the workload or system will be proportional to how far our
estimation is off. This means we can set memory.low much more
conservatively and thus waste less resources *without* the risk of the
workload falling off a cliff if we overshoot.
As a more abstract technical description, this unintuitive behaviour
results in having to give high-priority workloads a large protection
buffer on top of their expected usage to function reliably, as otherwise
we have abrupt periods of dramatically increased memory pressure which
hamper performance. Having to set these thresholds so high wastes
resources and generally works against the principle of work conservation.
In addition, having proportional memory reclaim behaviour has other
benefits. Most notably, before this patch it's basically mandatory to set
memory.low to a higher than desirable value because otherwise as soon as
you exceed memory.low, all protection is lost, and all pages are eligible
to scan again. By contrast, having a gradual ramp in reclaim pressure
means that you now still get some protection when thresholds are exceeded,
which means that one can now be more comfortable setting memory.low to
lower values without worrying that all protection will be lost. This is
important because workingset size is really hard to know exactly,
especially with variable workloads, so at least getting *some* protection
if your workingset size grows larger than you expect increases user
confidence in setting memory.low without a huge buffer on top being
needed.
Thanks a lot to Johannes Weiner and Tejun Heo for their advice and
assistance in thinking about how to make this work better.
In testing these changes, I intended to verify that:
1. Changes in page scanning become gradual and proportional instead of
binary.
To test this, I experimented stepping further and further down
memory.low protection on a workload that floats around 19G workingset
when under memory.low protection, watching page scan rates for the
workload cgroup:
+------------+-----------------+--------------------+--------------+
| memory.low | test (pgscan/s) | control (pgscan/s) | % of control |
+------------+-----------------+--------------------+--------------+
| 21G | 0 | 0 | N/A |
| 17G | 867 | 3799 | 23% |
| 12G | 1203 | 3543 | 34% |
| 8G | 2534 | 3979 | 64% |
| 4G | 3980 | 4147 | 96% |
| 0 | 3799 | 3980 | 95% |
+------------+-----------------+--------------------+--------------+
As you can see, the test kernel (with a kernel containing this
patch) ramps up page scanning significantly more gradually than the
control kernel (without this patch).
2. More gradual ramp up in reclaim aggression doesn't result in
premature OOMs.
To test this, I wrote a script that slowly increments the number of
pages held by stress(1)'s --vm-keep mode until a production system
entered severe overall memory contention. This script runs in a highly
protected slice taking up the majority of available system memory.
Watching vmstat revealed that page scanning continued essentially
nominally between test and control, without causing forward reclaim
progress to become arrested.
[0]: https://facebookmicrosites.github.io/cgroup2/docs/overview.html#case-study-the-fbtax2-project
[akpm@linux-foundation.org: reflow block comments to fit in 80 cols]
[chris@chrisdown.name: handle cgroup_disable=memory when getting memcg protection]
Link: http://lkml.kernel.org/r/20190201045711.GA18302@chrisdown.name
Link: http://lkml.kernel.org/r/20190124014455.GA6396@chrisdown.name
Signed-off-by: Chris Down <chris@chrisdown.name>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-07 00:58:32 +00:00
|
|
|
as long as the usages of all its ancestors are under their
|
2015-11-16 16:13:34 +00:00
|
|
|
protected levels. Protections can be hard guarantees or best effort
|
|
|
|
soft boundaries. Protections can also be over-committed in which case
|
2023-01-29 23:10:45 +00:00
|
|
|
only up to the amount available to the parent is protected among
|
2015-11-16 16:13:34 +00:00
|
|
|
children.
|
|
|
|
|
|
|
|
Protections are in the range [0, max] and defaults to 0, which is
|
|
|
|
noop.
|
|
|
|
|
|
|
|
As protections can be over-committed, all configuration combinations
|
|
|
|
are valid and there is no reason to reject configuration changes or
|
|
|
|
process migrations.
|
|
|
|
|
|
|
|
"memory.low" implements best-effort memory protection and is an
|
|
|
|
example of this type.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Allocations
|
|
|
|
-----------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A cgroup is exclusively allocated a certain amount of a finite
|
|
|
|
resource. Allocations can't be over-committed - the sum of the
|
|
|
|
allocations of children can not exceed the amount of resource
|
|
|
|
available to the parent.
|
|
|
|
|
|
|
|
Allocations are in the range [0, max] and defaults to 0, which is no
|
|
|
|
resource.
|
|
|
|
|
|
|
|
As allocations can't be over-committed, some configuration
|
|
|
|
combinations are invalid and should be rejected. Also, if the
|
|
|
|
resource is mandatory for execution of processes, process migrations
|
|
|
|
may be rejected.
|
|
|
|
|
|
|
|
"cpu.rt.max" hard-allocates realtime slices and is an example of this
|
|
|
|
type.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Interface Files
|
|
|
|
===============
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Format
|
|
|
|
------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
All interface files should be in one of the following formats whenever
|
2017-05-14 11:48:40 +00:00
|
|
|
possible::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
New-line separated values
|
|
|
|
(when only one value can be written at once)
|
|
|
|
|
|
|
|
VAL0\n
|
|
|
|
VAL1\n
|
|
|
|
...
|
|
|
|
|
|
|
|
Space separated values
|
|
|
|
(when read-only or multiple values can be written at once)
|
|
|
|
|
|
|
|
VAL0 VAL1 ...\n
|
|
|
|
|
|
|
|
Flat keyed
|
|
|
|
|
|
|
|
KEY0 VAL0\n
|
|
|
|
KEY1 VAL1\n
|
|
|
|
...
|
|
|
|
|
|
|
|
Nested keyed
|
|
|
|
|
|
|
|
KEY0 SUB_KEY0=VAL00 SUB_KEY1=VAL01...
|
|
|
|
KEY1 SUB_KEY0=VAL10 SUB_KEY1=VAL11...
|
|
|
|
...
|
|
|
|
|
|
|
|
For a writable file, the format for writing should generally match
|
|
|
|
reading; however, controllers may allow omitting later fields or
|
|
|
|
implement restricted shortcuts for most common use cases.
|
|
|
|
|
|
|
|
For both flat and nested keyed files, only the values for a single key
|
|
|
|
can be written at a time. For nested keyed files, the sub key pairs
|
|
|
|
may be specified in any order and not all pairs have to be specified.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Conventions
|
|
|
|
-----------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
- Settings for a single feature should be contained in a single file.
|
|
|
|
|
|
|
|
- The root cgroup should be exempt from resource control and thus
|
2020-05-27 21:43:19 +00:00
|
|
|
shouldn't have resource control interface files.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2019-05-13 19:37:17 +00:00
|
|
|
- The default time unit is microseconds. If a different unit is ever
|
|
|
|
used, an explicit unit suffix must be present.
|
|
|
|
|
|
|
|
- A parts-per quantity should use a percentage decimal with at least
|
|
|
|
two digit fractional part - e.g. 13.40.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
- If a controller implements weight based resource distribution, its
|
|
|
|
interface file should be named "weight" and have the range [1,
|
|
|
|
10000] with 100 as the default. The values are chosen to allow
|
|
|
|
enough and symmetric bias in both directions while keeping it
|
|
|
|
intuitive (the default is 100%).
|
|
|
|
|
|
|
|
- If a controller implements an absolute resource guarantee and/or
|
|
|
|
limit, the interface files should be named "min" and "max"
|
|
|
|
respectively. If a controller implements best effort resource
|
|
|
|
guarantee and/or limit, the interface files should be named "low"
|
|
|
|
and "high" respectively.
|
|
|
|
|
|
|
|
In the above four control files, the special token "max" should be
|
|
|
|
used to represent upward infinity for both reading and writing.
|
|
|
|
|
|
|
|
- If a setting has a configurable default value and keyed specific
|
|
|
|
overrides, the default entry should be keyed with "default" and
|
|
|
|
appear as the first entry in the file.
|
|
|
|
|
|
|
|
The default value can be updated by writing either "default $VAL" or
|
|
|
|
"$VAL".
|
|
|
|
|
|
|
|
When writing to update a specific override, "default" can be used as
|
|
|
|
the value to indicate removal of the override. Override entries
|
|
|
|
with "default" as the value must not appear when read.
|
|
|
|
|
|
|
|
For example, a setting which is keyed by major:minor device numbers
|
2017-05-14 11:48:40 +00:00
|
|
|
with integer values may look like the following::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# cat cgroup-example-interface-file
|
|
|
|
default 150
|
|
|
|
8:0 300
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
The default value can be updated by::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# echo 125 > cgroup-example-interface-file
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
or::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# echo "default 125" > cgroup-example-interface-file
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
An override can be set by::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# echo "8:16 170" > cgroup-example-interface-file
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
and cleared by::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
# echo "8:0 default" > cgroup-example-interface-file
|
|
|
|
# cat cgroup-example-interface-file
|
|
|
|
default 125
|
|
|
|
8:16 170
|
|
|
|
|
|
|
|
- For events which are not very high frequency, an interface file
|
|
|
|
"events" should be created which lists event key value pairs.
|
|
|
|
Whenever a notifiable event happens, file modified event should be
|
|
|
|
generated on the file.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Core Interface Files
|
|
|
|
--------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
All cgroup core files are prefixed with "cgroup."
|
|
|
|
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
cgroup.type
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups.
|
|
|
|
|
|
|
|
When read, it indicates the current type of the cgroup, which
|
|
|
|
can be one of the following values.
|
|
|
|
|
|
|
|
- "domain" : A normal valid domain cgroup.
|
|
|
|
|
|
|
|
- "domain threaded" : A threaded domain cgroup which is
|
|
|
|
serving as the root of a threaded subtree.
|
|
|
|
|
|
|
|
- "domain invalid" : A cgroup which is in an invalid state.
|
|
|
|
It can't be populated or have controllers enabled. It may
|
|
|
|
be allowed to become a threaded cgroup.
|
|
|
|
|
|
|
|
- "threaded" : A threaded cgroup which is a member of a
|
|
|
|
threaded subtree.
|
|
|
|
|
|
|
|
A cgroup can be turned into a threaded cgroup by writing
|
|
|
|
"threaded" to this file.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
cgroup.procs
|
|
|
|
A read-write new-line separated values file which exists on
|
|
|
|
all cgroups.
|
|
|
|
|
|
|
|
When read, it lists the PIDs of all processes which belong to
|
|
|
|
the cgroup one-per-line. The PIDs are not ordered and the
|
|
|
|
same PID may show up more than once if the process got moved
|
|
|
|
to another cgroup and then back or the PID got recycled while
|
|
|
|
reading.
|
|
|
|
|
|
|
|
A PID can be written to migrate the process associated with
|
|
|
|
the PID to the cgroup. The writer should match all of the
|
|
|
|
following conditions.
|
|
|
|
|
|
|
|
- It must have write access to the "cgroup.procs" file.
|
cgroup: implement cgroup v2 thread support
This patch implements cgroup v2 thread support. The goal of the
thread mode is supporting hierarchical accounting and control at
thread granularity while staying inside the resource domain model
which allows coordination across different resource controllers and
handling of anonymous resource consumptions.
A cgroup is always created as a domain and can be made threaded by
writing to the "cgroup.type" file. When a cgroup becomes threaded, it
becomes a member of a threaded subtree which is anchored at the
closest ancestor which isn't threaded.
The threads of the processes which are in a threaded subtree can be
placed anywhere without being restricted by process granularity or
no-internal-process constraint. Note that the threads aren't allowed
to escape to a different threaded subtree. To be used inside a
threaded subtree, a controller should explicitly support threaded mode
and be able to handle internal competition in the way which is
appropriate for the resource.
The root of a threaded subtree, the nearest ancestor which isn't
threaded, is called the threaded domain and serves as the resource
domain for the whole subtree. This is the last cgroup where domain
controllers are operational and where all the domain-level resource
consumptions in the subtree are accounted. This allows threaded
controllers to operate at thread granularity when requested while
staying inside the scope of system-level resource distribution.
As the root cgroup is exempt from the no-internal-process constraint,
it can serve as both a threaded domain and a parent to normal cgroups,
so, unlike non-root cgroups, the root cgroup can have both domain and
threaded children.
Internally, in a threaded subtree, each css_set has its ->dom_cset
pointing to a matching css_set which belongs to the threaded domain.
This ensures that thread root level cgroup_subsys_state for all
threaded controllers are readily accessible for domain-level
operations.
This patch enables threaded mode for the pids and perf_events
controllers. Neither has to worry about domain-level resource
consumptions and it's enough to simply set the flag.
For more details on the interface and behavior of the thread mode,
please refer to the section 2-2-2 in Documentation/cgroup-v2.txt added
by this patch.
v5: - Dropped silly no-op ->dom_cgrp init from cgroup_create().
Spotted by Waiman.
- Documentation updated as suggested by Waiman.
- cgroup.type content slightly reformatted.
- Mark the debug controller threaded.
v4: - Updated to the general idea of marking specific cgroups
domain/threaded as suggested by PeterZ.
v3: - Dropped "join" and always make mixed children join the parent's
threaded subtree.
v2: - After discussions with Waiman, support for mixed thread mode is
added. This should address the issue that Peter pointed out
where any nesting should be avoided for thread subtrees while
coexisting with other domain cgroups.
- Enabling / disabling thread mode now piggy backs on the existing
control mask update mechanism.
- Bug fixes and cleanup.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
2017-07-21 15:14:51 +00:00
|
|
|
|
|
|
|
- It must have write access to the "cgroup.procs" file of the
|
|
|
|
common ancestor of the source and destination cgroups.
|
|
|
|
|
|
|
|
When delegating a sub-hierarchy, write access to this file
|
|
|
|
should be granted along with the containing directory.
|
|
|
|
|
|
|
|
In a threaded cgroup, reading this file fails with EOPNOTSUPP
|
|
|
|
as all the processes belong to the thread root. Writing is
|
|
|
|
supported and moves every thread of the process to the cgroup.
|
|
|
|
|
|
|
|
cgroup.threads
|
|
|
|
A read-write new-line separated values file which exists on
|
|
|
|
all cgroups.
|
|
|
|
|
|
|
|
When read, it lists the TIDs of all threads which belong to
|
|
|
|
the cgroup one-per-line. The TIDs are not ordered and the
|
|
|
|
same TID may show up more than once if the thread got moved to
|
|
|
|
another cgroup and then back or the TID got recycled while
|
|
|
|
reading.
|
|
|
|
|
|
|
|
A TID can be written to migrate the thread associated with the
|
|
|
|
TID to the cgroup. The writer should match all of the
|
|
|
|
following conditions.
|
|
|
|
|
|
|
|
- It must have write access to the "cgroup.threads" file.
|
|
|
|
|
|
|
|
- The cgroup that the thread is currently in must be in the
|
|
|
|
same resource domain as the destination cgroup.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
- It must have write access to the "cgroup.procs" file of the
|
|
|
|
common ancestor of the source and destination cgroups.
|
|
|
|
|
|
|
|
When delegating a sub-hierarchy, write access to this file
|
|
|
|
should be granted along with the containing directory.
|
|
|
|
|
|
|
|
cgroup.controllers
|
|
|
|
A read-only space separated values file which exists on all
|
|
|
|
cgroups.
|
|
|
|
|
|
|
|
It shows space separated list of all controllers available to
|
|
|
|
the cgroup. The controllers are not ordered.
|
|
|
|
|
|
|
|
cgroup.subtree_control
|
|
|
|
A read-write space separated values file which exists on all
|
|
|
|
cgroups. Starts out empty.
|
|
|
|
|
|
|
|
When read, it shows space separated list of the controllers
|
|
|
|
which are enabled to control resource distribution from the
|
|
|
|
cgroup to its children.
|
|
|
|
|
|
|
|
Space separated list of controllers prefixed with '+' or '-'
|
|
|
|
can be written to enable or disable controllers. A controller
|
|
|
|
name prefixed with '+' enables the controller and '-'
|
|
|
|
disables. If a controller appears more than once on the list,
|
|
|
|
the last one is effective. When multiple enable and disable
|
|
|
|
operations are specified, either all succeed or all fail.
|
|
|
|
|
|
|
|
cgroup.events
|
|
|
|
A read-only flat-keyed file which exists on non-root cgroups.
|
|
|
|
The following entries are defined. Unless specified
|
|
|
|
otherwise, a value change in this file generates a file
|
|
|
|
modified event.
|
|
|
|
|
|
|
|
populated
|
|
|
|
1 if the cgroup or its descendants contains any live
|
|
|
|
processes; otherwise, 0.
|
2019-04-19 17:03:09 +00:00
|
|
|
frozen
|
|
|
|
1 if the cgroup is frozen; otherwise, 0.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-07-28 17:28:44 +00:00
|
|
|
cgroup.max.descendants
|
|
|
|
A read-write single value files. The default is "max".
|
|
|
|
|
|
|
|
Maximum allowed number of descent cgroups.
|
|
|
|
If the actual number of descendants is equal or larger,
|
|
|
|
an attempt to create a new cgroup in the hierarchy will fail.
|
|
|
|
|
|
|
|
cgroup.max.depth
|
|
|
|
A read-write single value files. The default is "max".
|
|
|
|
|
|
|
|
Maximum allowed descent depth below the current cgroup.
|
|
|
|
If the actual descent depth is equal or larger,
|
|
|
|
an attempt to create a new child cgroup will fail.
|
|
|
|
|
2017-08-02 16:55:31 +00:00
|
|
|
cgroup.stat
|
|
|
|
A read-only flat-keyed file with the following entries:
|
|
|
|
|
|
|
|
nr_descendants
|
|
|
|
Total number of visible descendant cgroups.
|
|
|
|
|
|
|
|
nr_dying_descendants
|
|
|
|
Total number of dying descendant cgroups. A cgroup becomes
|
|
|
|
dying after being deleted by a user. The cgroup will remain
|
|
|
|
in dying state for some time undefined time (which can depend
|
|
|
|
on system load) before being completely destroyed.
|
|
|
|
|
|
|
|
A process can't enter a dying cgroup under any circumstances,
|
|
|
|
a dying cgroup can't revive.
|
|
|
|
|
|
|
|
A dying cgroup can consume system resources not exceeding
|
|
|
|
limits, which were active at the moment of cgroup deletion.
|
|
|
|
|
2024-07-15 15:00:34 +00:00
|
|
|
nr_subsys_<cgroup_subsys>
|
|
|
|
Total number of live cgroup subsystems (e.g memory
|
|
|
|
cgroup) at and beneath the current cgroup.
|
|
|
|
|
|
|
|
nr_dying_subsys_<cgroup_subsys>
|
|
|
|
Total number of dying cgroup subsystems (e.g. memory
|
|
|
|
cgroup) at and beneath the current cgroup.
|
|
|
|
|
2019-04-19 17:03:09 +00:00
|
|
|
cgroup.freeze
|
|
|
|
A read-write single value file which exists on non-root cgroups.
|
|
|
|
Allowed values are "0" and "1". The default is "0".
|
|
|
|
|
|
|
|
Writing "1" to the file causes freezing of the cgroup and all
|
|
|
|
descendant cgroups. This means that all belonging processes will
|
|
|
|
be stopped and will not run until the cgroup will be explicitly
|
|
|
|
unfrozen. Freezing of the cgroup may take some time; when this action
|
|
|
|
is completed, the "frozen" value in the cgroup.events control file
|
|
|
|
will be updated to "1" and the corresponding notification will be
|
|
|
|
issued.
|
|
|
|
|
|
|
|
A cgroup can be frozen either by its own settings, or by settings
|
|
|
|
of any ancestor cgroups. If any of ancestor cgroups is frozen, the
|
|
|
|
cgroup will remain frozen.
|
|
|
|
|
|
|
|
Processes in the frozen cgroup can be killed by a fatal signal.
|
|
|
|
They also can enter and leave a frozen cgroup: either by an explicit
|
|
|
|
move by a user, or if freezing of the cgroup races with fork().
|
|
|
|
If a process is moved to a frozen cgroup, it stops. If a process is
|
|
|
|
moved out of a frozen cgroup, it becomes running.
|
|
|
|
|
|
|
|
Frozen status of a cgroup doesn't affect any cgroup tree operations:
|
|
|
|
it's possible to delete a frozen (and empty) cgroup, as well as
|
|
|
|
create new sub-cgroups.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2021-05-08 12:15:39 +00:00
|
|
|
cgroup.kill
|
|
|
|
A write-only single value file which exists in non-root cgroups.
|
|
|
|
The only allowed value is "1".
|
|
|
|
|
|
|
|
Writing "1" to the file causes the cgroup and all descendant cgroups to
|
|
|
|
be killed. This means that all processes located in the affected cgroup
|
|
|
|
tree will be killed via SIGKILL.
|
|
|
|
|
|
|
|
Killing a cgroup tree will deal with concurrent forks appropriately and
|
|
|
|
is protected against migrations.
|
|
|
|
|
|
|
|
In a threaded cgroup, writing this file fails with EOPNOTSUPP as
|
|
|
|
killing cgroups is a process directed operation, i.e. it affects
|
|
|
|
the whole thread-group.
|
|
|
|
|
sched/psi: Per-cgroup PSI accounting disable/re-enable interface
PSI accounts stalls for each cgroup separately and aggregates it
at each level of the hierarchy. This may cause non-negligible overhead
for some workloads when under deep level of the hierarchy.
commit 3958e2d0c34e ("cgroup: make per-cgroup pressure stall tracking configurable")
make PSI to skip per-cgroup stall accounting, only account system-wide
to avoid this each level overhead.
But for our use case, we also want leaf cgroup PSI stats accounted for
userspace adjustment on that cgroup, apart from only system-wide adjustment.
So this patch introduce a per-cgroup PSI accounting disable/re-enable
interface "cgroup.pressure", which is a read-write single value file that
allowed values are "0" and "1", the defaults is "1" so per-cgroup
PSI stats is enabled by default.
Implementation details:
It should be relatively straight-forward to disable and re-enable
state aggregation, time tracking, averaging on a per-cgroup level,
if we can live with losing history from while it was disabled.
I.e. the avgs will restart from 0, total= will have gaps.
But it's hard or complex to stop/restart groupc->tasks[] updates,
which is not implemented in this patch. So we always update
groupc->tasks[] and PSI_ONCPU bit in psi_group_change() even when
the cgroup PSI stats is disabled.
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Link: https://lkml.kernel.org/r/20220907090332.2078-1-zhouchengming@bytedance.com
2022-09-07 09:03:32 +00:00
|
|
|
cgroup.pressure
|
|
|
|
A read-write single value file that allowed values are "0" and "1".
|
|
|
|
The default is "1".
|
|
|
|
|
|
|
|
Writing "0" to the file will disable the cgroup PSI accounting.
|
|
|
|
Writing "1" to the file will re-enable the cgroup PSI accounting.
|
|
|
|
|
|
|
|
This control attribute is not hierarchical, so disable or enable PSI
|
|
|
|
accounting in a cgroup does not affect PSI accounting in descendants
|
|
|
|
and doesn't need pass enablement via ancestors from root.
|
|
|
|
|
|
|
|
The reason this control attribute exists is that PSI accounts stalls for
|
|
|
|
each cgroup separately and aggregates it at each level of the hierarchy.
|
|
|
|
This may cause non-negligible overhead for some workloads when under
|
|
|
|
deep level of the hierarchy, in which case this control attribute can
|
|
|
|
be used to disable PSI accounting in the non-leaf cgroups.
|
|
|
|
|
2022-08-25 16:41:08 +00:00
|
|
|
irq.pressure
|
|
|
|
A read-write nested-keyed file.
|
|
|
|
|
|
|
|
Shows pressure stall information for IRQ/SOFTIRQ. See
|
|
|
|
:ref:`Documentation/accounting/psi.rst <psi>` for details.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Controllers
|
|
|
|
===========
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2021-01-20 00:18:19 +00:00
|
|
|
.. _cgroup-v2-cpu:
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
CPU
|
|
|
|
---
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
The "cpu" controllers regulates distribution of CPU cycles. This
|
|
|
|
controller implements weight and absolute bandwidth limit models for
|
|
|
|
normal scheduling policy and absolute bandwidth allocation model for
|
|
|
|
realtime scheduling policy.
|
|
|
|
|
sched/uclamp: Extend CPU's cgroup controller
The cgroup CPU bandwidth controller allows to assign a specified
(maximum) bandwidth to the tasks of a group. However this bandwidth is
defined and enforced only on a temporal base, without considering the
actual frequency a CPU is running on. Thus, the amount of computation
completed by a task within an allocated bandwidth can be very different
depending on the actual frequency the CPU is running that task.
The amount of computation can be affected also by the specific CPU a
task is running on, especially when running on asymmetric capacity
systems like Arm's big.LITTLE.
With the availability of schedutil, the scheduler is now able
to drive frequency selections based on actual task utilization.
Moreover, the utilization clamping support provides a mechanism to
bias the frequency selection operated by schedutil depending on
constraints assigned to the tasks currently RUNNABLE on a CPU.
Giving the mechanisms described above, it is now possible to extend the
cpu controller to specify the minimum (or maximum) utilization which
should be considered for tasks RUNNABLE on a cpu.
This makes it possible to better defined the actual computational
power assigned to task groups, thus improving the cgroup CPU bandwidth
controller which is currently based just on time constraints.
Extend the CPU controller with a couple of new attributes uclamp.{min,max}
which allow to enforce utilization boosting and capping for all the
tasks in a group.
Specifically:
- uclamp.min: defines the minimum utilization which should be considered
i.e. the RUNNABLE tasks of this group will run at least at a
minimum frequency which corresponds to the uclamp.min
utilization
- uclamp.max: defines the maximum utilization which should be considered
i.e. the RUNNABLE tasks of this group will run up to a
maximum frequency which corresponds to the uclamp.max
utilization
These attributes:
a) are available only for non-root nodes, both on default and legacy
hierarchies, while system wide clamps are defined by a generic
interface which does not depends on cgroups. This system wide
interface enforces constraints on tasks in the root node.
b) enforce effective constraints at each level of the hierarchy which
are a restriction of the group requests considering its parent's
effective constraints. Root group effective constraints are defined
by the system wide interface.
This mechanism allows each (non-root) level of the hierarchy to:
- request whatever clamp values it would like to get
- effectively get only up to the maximum amount allowed by its parent
c) have higher priority than task-specific clamps, defined via
sched_setattr(), thus allowing to control and restrict task requests.
Add two new attributes to the cpu controller to collect "requested"
clamp values. Allow that at each non-root level of the hierarchy.
Keep it simple by not caring now about "effective" values computation
and propagation along the hierarchy.
Update sysctl_sched_uclamp_handler() to use the newly introduced
uclamp_mutex so that we serialize system default updates with cgroup
relate updates.
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Michal Koutny <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Alessio Balsini <balsini@android.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Joel Fernandes <joelaf@google.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Morten Rasmussen <morten.rasmussen@arm.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Perret <quentin.perret@arm.com>
Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com>
Cc: Steve Muckle <smuckle@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Todd Kjos <tkjos@google.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lkml.kernel.org/r/20190822132811.31294-2-patrick.bellasi@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-08-22 13:28:06 +00:00
|
|
|
In all the above models, cycles distribution is defined only on a temporal
|
|
|
|
base and it does not account for the frequency at which tasks are executed.
|
|
|
|
The (optional) utilization clamping support allows to hint the schedutil
|
|
|
|
cpufreq governor about the minimum desired frequency which should always be
|
|
|
|
provided by a CPU, as well as the maximum desired frequency, which should not
|
|
|
|
be exceeded by a CPU.
|
|
|
|
|
2024-03-20 14:23:02 +00:00
|
|
|
WARNING: cgroup2 doesn't yet support control of realtime processes. For
|
|
|
|
a kernel built with the CONFIG_RT_GROUP_SCHED option enabled for group
|
|
|
|
scheduling of realtime processes, the cpu controller can only be enabled
|
|
|
|
when all RT processes are in the root cgroup. This limitation does
|
|
|
|
not apply if CONFIG_RT_GROUP_SCHED is disabled. Be aware that system
|
|
|
|
management software may already have placed RT processes into nonroot
|
|
|
|
cgroups during the system boot process, and these processes may need
|
|
|
|
to be moved to the root cgroup before the cpu controller can be enabled
|
|
|
|
with a CONFIG_RT_GROUP_SCHED enabled kernel.
|
2017-12-05 17:10:17 +00:00
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
CPU Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
All time durations are in microseconds.
|
|
|
|
|
|
|
|
cpu.stat
|
2020-05-27 21:43:19 +00:00
|
|
|
A read-only flat-keyed file.
|
2017-10-23 23:18:27 +00:00
|
|
|
This file exists whether the controller is enabled or not.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-10-23 23:18:27 +00:00
|
|
|
It always reports the following three stats:
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
- usage_usec
|
|
|
|
- user_usec
|
|
|
|
- system_usec
|
2017-10-23 23:18:27 +00:00
|
|
|
|
2023-08-03 15:55:27 +00:00
|
|
|
and the following five when the controller is enabled:
|
2017-10-23 23:18:27 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
- nr_periods
|
|
|
|
- nr_throttled
|
|
|
|
- throttled_usec
|
2021-08-30 03:22:15 +00:00
|
|
|
- nr_bursts
|
|
|
|
- burst_usec
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cpu.weight
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "100".
|
|
|
|
|
2023-12-01 00:52:03 +00:00
|
|
|
For non idle groups (cpu.idle = 0), the weight is in the
|
|
|
|
range [1, 10000].
|
|
|
|
|
|
|
|
If the cgroup has been configured to be SCHED_IDLE (cpu.idle = 1),
|
|
|
|
then the weight will show as a 0.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-09-25 16:00:19 +00:00
|
|
|
cpu.weight.nice
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "0".
|
|
|
|
|
|
|
|
The nice value is in the range [-20, 19].
|
|
|
|
|
|
|
|
This interface file is an alternative interface for
|
|
|
|
"cpu.weight" and allows reading and setting weight using the
|
|
|
|
same values used by nice(2). Because the range is smaller and
|
|
|
|
granularity is coarser for the nice values, the read value is
|
|
|
|
the closest approximation of the current weight.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
cpu.max
|
|
|
|
A read-write two value file which exists on non-root cgroups.
|
|
|
|
The default is "max 100000".
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
The maximum bandwidth limit. It's in the following format::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
$MAX $PERIOD
|
|
|
|
|
2023-01-29 23:10:45 +00:00
|
|
|
which indicates that the group may consume up to $MAX in each
|
2015-11-16 16:13:34 +00:00
|
|
|
$PERIOD duration. "max" for $MAX indicates no limit. If only
|
|
|
|
one number is written, $MAX is updated.
|
|
|
|
|
2021-08-30 03:22:15 +00:00
|
|
|
cpu.max.burst
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "0".
|
|
|
|
|
|
|
|
The burst in the range [0, $MAX].
|
|
|
|
|
2018-10-26 22:06:31 +00:00
|
|
|
cpu.pressure
|
2021-01-16 17:36:34 +00:00
|
|
|
A read-write nested-keyed file.
|
2018-10-26 22:06:31 +00:00
|
|
|
|
|
|
|
Shows pressure stall information for CPU. See
|
2020-02-28 00:06:53 +00:00
|
|
|
:ref:`Documentation/accounting/psi.rst <psi>` for details.
|
2018-10-26 22:06:31 +00:00
|
|
|
|
sched/uclamp: Extend CPU's cgroup controller
The cgroup CPU bandwidth controller allows to assign a specified
(maximum) bandwidth to the tasks of a group. However this bandwidth is
defined and enforced only on a temporal base, without considering the
actual frequency a CPU is running on. Thus, the amount of computation
completed by a task within an allocated bandwidth can be very different
depending on the actual frequency the CPU is running that task.
The amount of computation can be affected also by the specific CPU a
task is running on, especially when running on asymmetric capacity
systems like Arm's big.LITTLE.
With the availability of schedutil, the scheduler is now able
to drive frequency selections based on actual task utilization.
Moreover, the utilization clamping support provides a mechanism to
bias the frequency selection operated by schedutil depending on
constraints assigned to the tasks currently RUNNABLE on a CPU.
Giving the mechanisms described above, it is now possible to extend the
cpu controller to specify the minimum (or maximum) utilization which
should be considered for tasks RUNNABLE on a cpu.
This makes it possible to better defined the actual computational
power assigned to task groups, thus improving the cgroup CPU bandwidth
controller which is currently based just on time constraints.
Extend the CPU controller with a couple of new attributes uclamp.{min,max}
which allow to enforce utilization boosting and capping for all the
tasks in a group.
Specifically:
- uclamp.min: defines the minimum utilization which should be considered
i.e. the RUNNABLE tasks of this group will run at least at a
minimum frequency which corresponds to the uclamp.min
utilization
- uclamp.max: defines the maximum utilization which should be considered
i.e. the RUNNABLE tasks of this group will run up to a
maximum frequency which corresponds to the uclamp.max
utilization
These attributes:
a) are available only for non-root nodes, both on default and legacy
hierarchies, while system wide clamps are defined by a generic
interface which does not depends on cgroups. This system wide
interface enforces constraints on tasks in the root node.
b) enforce effective constraints at each level of the hierarchy which
are a restriction of the group requests considering its parent's
effective constraints. Root group effective constraints are defined
by the system wide interface.
This mechanism allows each (non-root) level of the hierarchy to:
- request whatever clamp values it would like to get
- effectively get only up to the maximum amount allowed by its parent
c) have higher priority than task-specific clamps, defined via
sched_setattr(), thus allowing to control and restrict task requests.
Add two new attributes to the cpu controller to collect "requested"
clamp values. Allow that at each non-root level of the hierarchy.
Keep it simple by not caring now about "effective" values computation
and propagation along the hierarchy.
Update sysctl_sched_uclamp_handler() to use the newly introduced
uclamp_mutex so that we serialize system default updates with cgroup
relate updates.
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Michal Koutny <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Alessio Balsini <balsini@android.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Joel Fernandes <joelaf@google.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Morten Rasmussen <morten.rasmussen@arm.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Perret <quentin.perret@arm.com>
Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com>
Cc: Steve Muckle <smuckle@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Todd Kjos <tkjos@google.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lkml.kernel.org/r/20190822132811.31294-2-patrick.bellasi@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-08-22 13:28:06 +00:00
|
|
|
cpu.uclamp.min
|
|
|
|
A read-write single value file which exists on non-root cgroups.
|
|
|
|
The default is "0", i.e. no utilization boosting.
|
|
|
|
|
|
|
|
The requested minimum utilization (protection) as a percentage
|
|
|
|
rational number, e.g. 12.34 for 12.34%.
|
|
|
|
|
|
|
|
This interface allows reading and setting minimum utilization clamp
|
|
|
|
values similar to the sched_setattr(2). This minimum utilization
|
|
|
|
value is used to clamp the task specific minimum utilization clamp.
|
|
|
|
|
|
|
|
The requested minimum utilization (protection) is always capped by
|
|
|
|
the current value for the maximum utilization (limit), i.e.
|
|
|
|
`cpu.uclamp.max`.
|
|
|
|
|
|
|
|
cpu.uclamp.max
|
|
|
|
A read-write single value file which exists on non-root cgroups.
|
|
|
|
The default is "max". i.e. no utilization capping
|
|
|
|
|
|
|
|
The requested maximum utilization (limit) as a percentage rational
|
|
|
|
number, e.g. 98.76 for 98.76%.
|
|
|
|
|
|
|
|
This interface allows reading and setting maximum utilization clamp
|
|
|
|
values similar to the sched_setattr(2). This maximum utilization
|
|
|
|
value is used to clamp the task specific maximum utilization clamp.
|
|
|
|
|
2023-12-01 00:52:03 +00:00
|
|
|
cpu.idle
|
|
|
|
A read-write single value file which exists on non-root cgroups.
|
|
|
|
The default is 0.
|
|
|
|
|
|
|
|
This is the cgroup analog of the per-task SCHED_IDLE sched policy.
|
|
|
|
Setting this value to a 1 will make the scheduling policy of the
|
|
|
|
cgroup SCHED_IDLE. The threads inside the cgroup will retain their
|
|
|
|
own relative priorities, but the cgroup itself will be treated as
|
|
|
|
very low priority relative to its peers.
|
|
|
|
|
sched/uclamp: Extend CPU's cgroup controller
The cgroup CPU bandwidth controller allows to assign a specified
(maximum) bandwidth to the tasks of a group. However this bandwidth is
defined and enforced only on a temporal base, without considering the
actual frequency a CPU is running on. Thus, the amount of computation
completed by a task within an allocated bandwidth can be very different
depending on the actual frequency the CPU is running that task.
The amount of computation can be affected also by the specific CPU a
task is running on, especially when running on asymmetric capacity
systems like Arm's big.LITTLE.
With the availability of schedutil, the scheduler is now able
to drive frequency selections based on actual task utilization.
Moreover, the utilization clamping support provides a mechanism to
bias the frequency selection operated by schedutil depending on
constraints assigned to the tasks currently RUNNABLE on a CPU.
Giving the mechanisms described above, it is now possible to extend the
cpu controller to specify the minimum (or maximum) utilization which
should be considered for tasks RUNNABLE on a cpu.
This makes it possible to better defined the actual computational
power assigned to task groups, thus improving the cgroup CPU bandwidth
controller which is currently based just on time constraints.
Extend the CPU controller with a couple of new attributes uclamp.{min,max}
which allow to enforce utilization boosting and capping for all the
tasks in a group.
Specifically:
- uclamp.min: defines the minimum utilization which should be considered
i.e. the RUNNABLE tasks of this group will run at least at a
minimum frequency which corresponds to the uclamp.min
utilization
- uclamp.max: defines the maximum utilization which should be considered
i.e. the RUNNABLE tasks of this group will run up to a
maximum frequency which corresponds to the uclamp.max
utilization
These attributes:
a) are available only for non-root nodes, both on default and legacy
hierarchies, while system wide clamps are defined by a generic
interface which does not depends on cgroups. This system wide
interface enforces constraints on tasks in the root node.
b) enforce effective constraints at each level of the hierarchy which
are a restriction of the group requests considering its parent's
effective constraints. Root group effective constraints are defined
by the system wide interface.
This mechanism allows each (non-root) level of the hierarchy to:
- request whatever clamp values it would like to get
- effectively get only up to the maximum amount allowed by its parent
c) have higher priority than task-specific clamps, defined via
sched_setattr(), thus allowing to control and restrict task requests.
Add two new attributes to the cpu controller to collect "requested"
clamp values. Allow that at each non-root level of the hierarchy.
Keep it simple by not caring now about "effective" values computation
and propagation along the hierarchy.
Update sysctl_sched_uclamp_handler() to use the newly introduced
uclamp_mutex so that we serialize system default updates with cgroup
relate updates.
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Michal Koutny <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Alessio Balsini <balsini@android.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Joel Fernandes <joelaf@google.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Morten Rasmussen <morten.rasmussen@arm.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Perret <quentin.perret@arm.com>
Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com>
Cc: Steve Muckle <smuckle@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Todd Kjos <tkjos@google.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lkml.kernel.org/r/20190822132811.31294-2-patrick.bellasi@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-08-22 13:28:06 +00:00
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Memory
|
|
|
|
------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
The "memory" controller regulates distribution of memory. Memory is
|
|
|
|
stateful and implements both limit and protection models. Due to the
|
|
|
|
intertwining between memory usage and reclaim pressure and the
|
|
|
|
stateful nature of memory, the distribution model is relatively
|
|
|
|
complex.
|
|
|
|
|
|
|
|
While not completely water-tight, all major memory usages by a given
|
|
|
|
cgroup are tracked so that the total memory consumption can be
|
|
|
|
accounted and controlled to a reasonable extent. Currently, the
|
|
|
|
following types of memory usages are tracked.
|
|
|
|
|
|
|
|
- Userland memory - page cache and anonymous memory.
|
|
|
|
|
|
|
|
- Kernel data structures such as dentries and inodes.
|
|
|
|
|
|
|
|
- TCP socket buffers.
|
|
|
|
|
|
|
|
The above list may expand in the future for better coverage.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Memory Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
All memory amounts are in bytes. If a value which is not aligned to
|
|
|
|
PAGE_SIZE is written, the value may be rounded up to the closest
|
|
|
|
PAGE_SIZE multiple when read back.
|
|
|
|
|
|
|
|
memory.current
|
|
|
|
A read-only single value file which exists on non-root
|
|
|
|
cgroups.
|
|
|
|
|
|
|
|
The total amount of memory currently being used by the cgroup
|
|
|
|
and its descendants.
|
|
|
|
|
2018-06-08 00:07:46 +00:00
|
|
|
memory.min
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "0".
|
|
|
|
|
|
|
|
Hard memory protection. If the memory usage of a cgroup
|
|
|
|
is within its effective min boundary, the cgroup's memory
|
|
|
|
won't be reclaimed under any conditions. If there is no
|
|
|
|
unprotected reclaimable memory available, OOM killer
|
mm, memcg: proportional memory.{low,min} reclaim
cgroup v2 introduces two memory protection thresholds: memory.low
(best-effort) and memory.min (hard protection). While they generally do
what they say on the tin, there is a limitation in their implementation
that makes them difficult to use effectively: that cliff behaviour often
manifests when they become eligible for reclaim. This patch implements
more intuitive and usable behaviour, where we gradually mount more
reclaim pressure as cgroups further and further exceed their protection
thresholds.
This cliff edge behaviour happens because we only choose whether or not
to reclaim based on whether the memcg is within its protection limits
(see the use of mem_cgroup_protected in shrink_node), but we don't vary
our reclaim behaviour based on this information. Imagine the following
timeline, with the numbers the lruvec size in this zone:
1. memory.low=1000000, memory.current=999999. 0 pages may be scanned.
2. memory.low=1000000, memory.current=1000000. 0 pages may be scanned.
3. memory.low=1000000, memory.current=1000001. 1000001* pages may be
scanned. (?!)
* Of course, we won't usually scan all available pages in the zone even
without this patch because of scan control priority, over-reclaim
protection, etc. However, as shown by the tests at the end, these
techniques don't sufficiently throttle such an extreme change in input,
so cliff-like behaviour isn't really averted by their existence alone.
Here's an example of how this plays out in practice. At Facebook, we are
trying to protect various workloads from "system" software, like
configuration management tools, metric collectors, etc (see this[0] case
study). In order to find a suitable memory.low value, we start by
determining the expected memory range within which the workload will be
comfortable operating. This isn't an exact science -- memory usage deemed
"comfortable" will vary over time due to user behaviour, differences in
composition of work, etc, etc. As such we need to ballpark memory.low,
but doing this is currently problematic:
1. If we end up setting it too low for the workload, it won't have
*any* effect (see discussion above). The group will receive the full
weight of reclaim and won't have any priority while competing with the
less important system software, as if we had no memory.low configured
at all.
2. Because of this behaviour, we end up erring on the side of setting
it too high, such that the comfort range is reliably covered. However,
protected memory is completely unavailable to the rest of the system,
so we might cause undue memory and IO pressure there when we *know* we
have some elasticity in the workload.
3. Even if we get the value totally right, smack in the middle of the
comfort zone, we get extreme jumps between no pressure and full
pressure that cause unpredictable pressure spikes in the workload due
to the current binary reclaim behaviour.
With this patch, we can set it to our ballpark estimation without too much
worry. Any undesirable behaviour, such as too much or too little reclaim
pressure on the workload or system will be proportional to how far our
estimation is off. This means we can set memory.low much more
conservatively and thus waste less resources *without* the risk of the
workload falling off a cliff if we overshoot.
As a more abstract technical description, this unintuitive behaviour
results in having to give high-priority workloads a large protection
buffer on top of their expected usage to function reliably, as otherwise
we have abrupt periods of dramatically increased memory pressure which
hamper performance. Having to set these thresholds so high wastes
resources and generally works against the principle of work conservation.
In addition, having proportional memory reclaim behaviour has other
benefits. Most notably, before this patch it's basically mandatory to set
memory.low to a higher than desirable value because otherwise as soon as
you exceed memory.low, all protection is lost, and all pages are eligible
to scan again. By contrast, having a gradual ramp in reclaim pressure
means that you now still get some protection when thresholds are exceeded,
which means that one can now be more comfortable setting memory.low to
lower values without worrying that all protection will be lost. This is
important because workingset size is really hard to know exactly,
especially with variable workloads, so at least getting *some* protection
if your workingset size grows larger than you expect increases user
confidence in setting memory.low without a huge buffer on top being
needed.
Thanks a lot to Johannes Weiner and Tejun Heo for their advice and
assistance in thinking about how to make this work better.
In testing these changes, I intended to verify that:
1. Changes in page scanning become gradual and proportional instead of
binary.
To test this, I experimented stepping further and further down
memory.low protection on a workload that floats around 19G workingset
when under memory.low protection, watching page scan rates for the
workload cgroup:
+------------+-----------------+--------------------+--------------+
| memory.low | test (pgscan/s) | control (pgscan/s) | % of control |
+------------+-----------------+--------------------+--------------+
| 21G | 0 | 0 | N/A |
| 17G | 867 | 3799 | 23% |
| 12G | 1203 | 3543 | 34% |
| 8G | 2534 | 3979 | 64% |
| 4G | 3980 | 4147 | 96% |
| 0 | 3799 | 3980 | 95% |
+------------+-----------------+--------------------+--------------+
As you can see, the test kernel (with a kernel containing this
patch) ramps up page scanning significantly more gradually than the
control kernel (without this patch).
2. More gradual ramp up in reclaim aggression doesn't result in
premature OOMs.
To test this, I wrote a script that slowly increments the number of
pages held by stress(1)'s --vm-keep mode until a production system
entered severe overall memory contention. This script runs in a highly
protected slice taking up the majority of available system memory.
Watching vmstat revealed that page scanning continued essentially
nominally between test and control, without causing forward reclaim
progress to become arrested.
[0]: https://facebookmicrosites.github.io/cgroup2/docs/overview.html#case-study-the-fbtax2-project
[akpm@linux-foundation.org: reflow block comments to fit in 80 cols]
[chris@chrisdown.name: handle cgroup_disable=memory when getting memcg protection]
Link: http://lkml.kernel.org/r/20190201045711.GA18302@chrisdown.name
Link: http://lkml.kernel.org/r/20190124014455.GA6396@chrisdown.name
Signed-off-by: Chris Down <chris@chrisdown.name>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-07 00:58:32 +00:00
|
|
|
is invoked. Above the effective min boundary (or
|
|
|
|
effective low boundary if it is higher), pages are reclaimed
|
|
|
|
proportionally to the overage, reducing reclaim pressure for
|
|
|
|
smaller overages.
|
2018-06-08 00:07:46 +00:00
|
|
|
|
2020-02-28 00:06:49 +00:00
|
|
|
Effective min boundary is limited by memory.min values of
|
2018-06-08 00:07:46 +00:00
|
|
|
all ancestor cgroups. If there is memory.min overcommitment
|
|
|
|
(child cgroup or cgroups are requiring more protected memory
|
|
|
|
than parent will allow), then each child cgroup will get
|
|
|
|
the part of parent's protection proportional to its
|
|
|
|
actual memory usage below memory.min.
|
|
|
|
|
|
|
|
Putting more memory than generally available under this
|
|
|
|
protection is discouraged and may lead to constant OOMs.
|
|
|
|
|
|
|
|
If a memory cgroup is not populated with processes,
|
|
|
|
its memory.min is ignored.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
memory.low
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "0".
|
|
|
|
|
2018-06-08 00:06:29 +00:00
|
|
|
Best-effort memory protection. If the memory usage of a
|
|
|
|
cgroup is within its effective low boundary, the cgroup's
|
2019-09-25 19:56:04 +00:00
|
|
|
memory won't be reclaimed unless there is no reclaimable
|
|
|
|
memory available in unprotected cgroups.
|
2019-10-29 10:43:29 +00:00
|
|
|
Above the effective low boundary (or
|
mm, memcg: proportional memory.{low,min} reclaim
cgroup v2 introduces two memory protection thresholds: memory.low
(best-effort) and memory.min (hard protection). While they generally do
what they say on the tin, there is a limitation in their implementation
that makes them difficult to use effectively: that cliff behaviour often
manifests when they become eligible for reclaim. This patch implements
more intuitive and usable behaviour, where we gradually mount more
reclaim pressure as cgroups further and further exceed their protection
thresholds.
This cliff edge behaviour happens because we only choose whether or not
to reclaim based on whether the memcg is within its protection limits
(see the use of mem_cgroup_protected in shrink_node), but we don't vary
our reclaim behaviour based on this information. Imagine the following
timeline, with the numbers the lruvec size in this zone:
1. memory.low=1000000, memory.current=999999. 0 pages may be scanned.
2. memory.low=1000000, memory.current=1000000. 0 pages may be scanned.
3. memory.low=1000000, memory.current=1000001. 1000001* pages may be
scanned. (?!)
* Of course, we won't usually scan all available pages in the zone even
without this patch because of scan control priority, over-reclaim
protection, etc. However, as shown by the tests at the end, these
techniques don't sufficiently throttle such an extreme change in input,
so cliff-like behaviour isn't really averted by their existence alone.
Here's an example of how this plays out in practice. At Facebook, we are
trying to protect various workloads from "system" software, like
configuration management tools, metric collectors, etc (see this[0] case
study). In order to find a suitable memory.low value, we start by
determining the expected memory range within which the workload will be
comfortable operating. This isn't an exact science -- memory usage deemed
"comfortable" will vary over time due to user behaviour, differences in
composition of work, etc, etc. As such we need to ballpark memory.low,
but doing this is currently problematic:
1. If we end up setting it too low for the workload, it won't have
*any* effect (see discussion above). The group will receive the full
weight of reclaim and won't have any priority while competing with the
less important system software, as if we had no memory.low configured
at all.
2. Because of this behaviour, we end up erring on the side of setting
it too high, such that the comfort range is reliably covered. However,
protected memory is completely unavailable to the rest of the system,
so we might cause undue memory and IO pressure there when we *know* we
have some elasticity in the workload.
3. Even if we get the value totally right, smack in the middle of the
comfort zone, we get extreme jumps between no pressure and full
pressure that cause unpredictable pressure spikes in the workload due
to the current binary reclaim behaviour.
With this patch, we can set it to our ballpark estimation without too much
worry. Any undesirable behaviour, such as too much or too little reclaim
pressure on the workload or system will be proportional to how far our
estimation is off. This means we can set memory.low much more
conservatively and thus waste less resources *without* the risk of the
workload falling off a cliff if we overshoot.
As a more abstract technical description, this unintuitive behaviour
results in having to give high-priority workloads a large protection
buffer on top of their expected usage to function reliably, as otherwise
we have abrupt periods of dramatically increased memory pressure which
hamper performance. Having to set these thresholds so high wastes
resources and generally works against the principle of work conservation.
In addition, having proportional memory reclaim behaviour has other
benefits. Most notably, before this patch it's basically mandatory to set
memory.low to a higher than desirable value because otherwise as soon as
you exceed memory.low, all protection is lost, and all pages are eligible
to scan again. By contrast, having a gradual ramp in reclaim pressure
means that you now still get some protection when thresholds are exceeded,
which means that one can now be more comfortable setting memory.low to
lower values without worrying that all protection will be lost. This is
important because workingset size is really hard to know exactly,
especially with variable workloads, so at least getting *some* protection
if your workingset size grows larger than you expect increases user
confidence in setting memory.low without a huge buffer on top being
needed.
Thanks a lot to Johannes Weiner and Tejun Heo for their advice and
assistance in thinking about how to make this work better.
In testing these changes, I intended to verify that:
1. Changes in page scanning become gradual and proportional instead of
binary.
To test this, I experimented stepping further and further down
memory.low protection on a workload that floats around 19G workingset
when under memory.low protection, watching page scan rates for the
workload cgroup:
+------------+-----------------+--------------------+--------------+
| memory.low | test (pgscan/s) | control (pgscan/s) | % of control |
+------------+-----------------+--------------------+--------------+
| 21G | 0 | 0 | N/A |
| 17G | 867 | 3799 | 23% |
| 12G | 1203 | 3543 | 34% |
| 8G | 2534 | 3979 | 64% |
| 4G | 3980 | 4147 | 96% |
| 0 | 3799 | 3980 | 95% |
+------------+-----------------+--------------------+--------------+
As you can see, the test kernel (with a kernel containing this
patch) ramps up page scanning significantly more gradually than the
control kernel (without this patch).
2. More gradual ramp up in reclaim aggression doesn't result in
premature OOMs.
To test this, I wrote a script that slowly increments the number of
pages held by stress(1)'s --vm-keep mode until a production system
entered severe overall memory contention. This script runs in a highly
protected slice taking up the majority of available system memory.
Watching vmstat revealed that page scanning continued essentially
nominally between test and control, without causing forward reclaim
progress to become arrested.
[0]: https://facebookmicrosites.github.io/cgroup2/docs/overview.html#case-study-the-fbtax2-project
[akpm@linux-foundation.org: reflow block comments to fit in 80 cols]
[chris@chrisdown.name: handle cgroup_disable=memory when getting memcg protection]
Link: http://lkml.kernel.org/r/20190201045711.GA18302@chrisdown.name
Link: http://lkml.kernel.org/r/20190124014455.GA6396@chrisdown.name
Signed-off-by: Chris Down <chris@chrisdown.name>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-07 00:58:32 +00:00
|
|
|
effective min boundary if it is higher), pages are reclaimed
|
|
|
|
proportionally to the overage, reducing reclaim pressure for
|
|
|
|
smaller overages.
|
2018-06-08 00:06:29 +00:00
|
|
|
|
|
|
|
Effective low boundary is limited by memory.low values of
|
|
|
|
all ancestor cgroups. If there is memory.low overcommitment
|
2018-06-08 00:07:46 +00:00
|
|
|
(child cgroup or cgroups are requiring more protected memory
|
2018-06-08 00:06:29 +00:00
|
|
|
than parent will allow), then each child cgroup will get
|
2018-06-08 00:07:46 +00:00
|
|
|
the part of parent's protection proportional to its
|
2018-06-08 00:06:29 +00:00
|
|
|
actual memory usage below memory.low.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Putting more memory than generally available under this
|
|
|
|
protection is discouraged.
|
|
|
|
|
|
|
|
memory.high
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "max".
|
|
|
|
|
2023-06-01 18:38:19 +00:00
|
|
|
Memory usage throttle limit. If a cgroup's usage goes
|
2015-11-16 16:13:34 +00:00
|
|
|
over the high boundary, the processes of the cgroup are
|
|
|
|
throttled and put under heavy reclaim pressure.
|
|
|
|
|
|
|
|
Going over the high limit never invokes the OOM killer and
|
2023-06-01 18:38:19 +00:00
|
|
|
under extreme conditions the limit may be breached. The high
|
|
|
|
limit should be used in scenarios where an external process
|
|
|
|
monitors the limited cgroup to alleviate heavy reclaim
|
|
|
|
pressure.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
memory.max
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "max".
|
|
|
|
|
2023-06-01 18:38:19 +00:00
|
|
|
Memory usage hard limit. This is the main mechanism to limit
|
|
|
|
memory usage of a cgroup. If a cgroup's memory usage reaches
|
|
|
|
this limit and can't be reduced, the OOM killer is invoked in
|
|
|
|
the cgroup. Under certain circumstances, the usage may go
|
|
|
|
over the limit temporarily.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2020-06-08 04:42:55 +00:00
|
|
|
In default configuration regular 0-order allocations always
|
|
|
|
succeed unless OOM killer chooses current task as a victim.
|
|
|
|
|
|
|
|
Some kinds of allocations don't invoke the OOM killer.
|
|
|
|
Caller could retry them differently, return into userspace
|
|
|
|
as -ENOMEM or silently ignore in cases like disk readahead.
|
|
|
|
|
memcg: introduce per-memcg reclaim interface
This patch series adds a memory.reclaim proactive reclaim interface.
The rationale behind the interface and how it works are in the first
patch.
This patch (of 4):
Introduce a memcg interface to trigger memory reclaim on a memory cgroup.
Use case: Proactive Reclaim
---------------------------
A userspace proactive reclaimer can continuously probe the memcg to
reclaim a small amount of memory. This gives more accurate and up-to-date
workingset estimation as the LRUs are continuously sorted and can
potentially provide more deterministic memory overcommit behavior. The
memory overcommit controller can provide more proactive response to the
changing behavior of the running applications instead of being reactive.
A userspace reclaimer's purpose in this case is not a complete replacement
for kswapd or direct reclaim, it is to proactively identify memory savings
opportunities and reclaim some amount of cold pages set by the policy to
free up the memory for more demanding jobs or scheduling new jobs.
A user space proactive reclaimer is used in Google data centers.
Additionally, Meta's TMO paper recently referenced a very similar
interface used for user space proactive reclaim:
https://dl.acm.org/doi/pdf/10.1145/3503222.3507731
Benefits of a user space reclaimer:
-----------------------------------
1) More flexible on who should be charged for the cpu of the memory
reclaim. For proactive reclaim, it makes more sense to be centralized.
2) More flexible on dedicating the resources (like cpu). The memory
overcommit controller can balance the cost between the cpu usage and
the memory reclaimed.
3) Provides a way to the applications to keep their LRUs sorted, so,
under memory pressure better reclaim candidates are selected. This
also gives more accurate and uptodate notion of working set for an
application.
Why memory.high is not enough?
------------------------------
- memory.high can be used to trigger reclaim in a memcg and can
potentially be used for proactive reclaim. However there is a big
downside in using memory.high. It can potentially introduce high
reclaim stalls in the target application as the allocations from the
processes or the threads of the application can hit the temporary
memory.high limit.
- Userspace proactive reclaimers usually use feedback loops to decide
how much memory to proactively reclaim from a workload. The metrics
used for this are usually either refaults or PSI, and these metrics will
become messy if the application gets throttled by hitting the high
limit.
- memory.high is a stateful interface, if the userspace proactive
reclaimer crashes for any reason while triggering reclaim it can leave
the application in a bad state.
- If a workload is rapidly expanding, setting memory.high to proactively
reclaim memory can result in actually reclaiming more memory than
intended.
The benefits of such interface and shortcomings of existing interface were
further discussed in this RFC thread:
https://lore.kernel.org/linux-mm/5df21376-7dd1-bf81-8414-32a73cea45dd@google.com/
Interface:
----------
Introducing a very simple memcg interface 'echo 10M > memory.reclaim' to
trigger reclaim in the target memory cgroup.
The interface is introduced as a nested-keyed file to allow for future
optional arguments to be easily added to configure the behavior of
reclaim.
Possible Extensions:
--------------------
- This interface can be extended with an additional parameter or flags
to allow specifying one or more types of memory to reclaim from (e.g.
file, anon, ..).
- The interface can also be extended with a node mask to reclaim from
specific nodes. This has use cases for reclaim-based demotion in memory
tiering systens.
- A similar per-node interface can also be added to support proactive
reclaim and reclaim-based demotion in systems without memcg.
- Add a timeout parameter to make it easier for user space to call the
interface without worrying about being blocked for an undefined amount
of time.
For now, let's keep things simple by adding the basic functionality.
[yosryahmed@google.com: worked on versions v2 onwards, refreshed to
current master, updated commit message based on recent
discussions and use cases]
Link: https://lkml.kernel.org/r/20220425190040.2475377-1-yosryahmed@google.com
Link: https://lkml.kernel.org/r/20220425190040.2475377-2-yosryahmed@google.com
Signed-off-by: Shakeel Butt <shakeelb@google.com>
Co-developed-by: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Wei Xu <weixugc@google.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: David Rientjes <rientjes@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Zefan Li <lizefan.x@bytedance.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Chen Wandun <chenwandun@huawei.com>
Cc: Vaibhav Jain <vaibhav@linux.ibm.com>
Cc: "Michal Koutn" <mkoutny@suse.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-04-29 21:36:59 +00:00
|
|
|
memory.reclaim
|
|
|
|
A write-only nested-keyed file which exists for all cgroups.
|
|
|
|
|
|
|
|
This is a simple interface to trigger memory reclaim in the
|
|
|
|
target cgroup.
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
echo "1G" > memory.reclaim
|
|
|
|
|
|
|
|
Please note that the kernel can over or under reclaim from
|
|
|
|
the target cgroup. If less bytes are reclaimed than the
|
|
|
|
specified amount, -EAGAIN is returned.
|
|
|
|
|
2022-07-14 06:49:18 +00:00
|
|
|
Please note that the proactive reclaim (triggered by this
|
|
|
|
interface) is not meant to indicate memory pressure on the
|
|
|
|
memory cgroup. Therefore socket memory balancing triggered by
|
|
|
|
the memory reclaim normally is not exercised in this case.
|
|
|
|
This means that the networking layer will not adapt based on
|
|
|
|
reclaim induced by memory.reclaim.
|
|
|
|
|
2024-01-03 16:48:37 +00:00
|
|
|
The following nested keys are defined.
|
|
|
|
|
|
|
|
========== ================================
|
|
|
|
swappiness Swappiness value to reclaim with
|
|
|
|
========== ================================
|
|
|
|
|
|
|
|
Specifying a swappiness value instructs the kernel to perform
|
|
|
|
the reclaim with that swappiness value. Note that this has the
|
|
|
|
same semantics as vm.swappiness applied to memcg reclaim with
|
|
|
|
all the existing limitations and potential future extensions.
|
|
|
|
|
2022-05-13 23:48:57 +00:00
|
|
|
memory.peak
|
mm, memcg: cg2 memory{.swap,}.peak write handlers
Patch series "mm, memcg: cg2 memory{.swap,}.peak write handlers", v7.
This patch (of 2):
Other mechanisms for querying the peak memory usage of either a process or
v1 memory cgroup allow for resetting the high watermark. Restore parity
with those mechanisms, but with a less racy API.
For example:
- Any write to memory.max_usage_in_bytes in a cgroup v1 mount resets
the high watermark.
- writing "5" to the clear_refs pseudo-file in a processes's proc
directory resets the peak RSS.
This change is an evolution of a previous patch, which mostly copied the
cgroup v1 behavior, however, there were concerns about races/ownership
issues with a global reset, so instead this change makes the reset
filedescriptor-local.
Writing any non-empty string to the memory.peak and memory.swap.peak
pseudo-files reset the high watermark to the current usage for subsequent
reads through that same FD.
Notably, following Johannes's suggestion, this implementation moves the
O(FDs that have written) behavior onto the FD write(2) path. Instead, on
the page-allocation path, we simply add one additional watermark to
conditionally bump per-hierarchy level in the page-counter.
Additionally, this takes Longman's suggestion of nesting the
page-charging-path checks for the two watermarks to reduce the number of
common-case comparisons.
This behavior is particularly useful for work scheduling systems that need
to track memory usage of worker processes/cgroups per-work-item. Since
memory can't be squeezed like CPU can (the OOM-killer has opinions), these
systems need to track the peak memory usage to compute system/container
fullness when binpacking workitems.
Most notably, Vimeo's use-case involves a system that's doing global
binpacking across many Kubernetes pods/containers, and while we can use
PSI for some local decisions about overload, we strive to avoid packing
workloads too tightly in the first place. To facilitate this, we track
the peak memory usage. However, since we run with long-lived workers (to
amortize startup costs) we need a way to track the high watermark while a
work-item is executing. Polling runs the risk of missing short spikes
that last for timescales below the polling interval, and peak memory
tracking at the cgroup level is otherwise perfect for this use-case.
As this data is used to ensure that binpacked work ends up with sufficient
headroom, this use-case mostly avoids the inaccuracies surrounding
reclaimable memory.
Link: https://lkml.kernel.org/r/20240730231304.761942-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-2-davidf@vimeo.com
Signed-off-by: David Finkel <davidf@vimeo.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Waiman Long <longman@redhat.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-07-29 14:37:42 +00:00
|
|
|
A read-write single value file which exists on non-root cgroups.
|
|
|
|
|
|
|
|
The max memory usage recorded for the cgroup and its descendants since
|
|
|
|
either the creation of the cgroup or the most recent reset for that FD.
|
2022-05-13 23:48:57 +00:00
|
|
|
|
mm, memcg: cg2 memory{.swap,}.peak write handlers
Patch series "mm, memcg: cg2 memory{.swap,}.peak write handlers", v7.
This patch (of 2):
Other mechanisms for querying the peak memory usage of either a process or
v1 memory cgroup allow for resetting the high watermark. Restore parity
with those mechanisms, but with a less racy API.
For example:
- Any write to memory.max_usage_in_bytes in a cgroup v1 mount resets
the high watermark.
- writing "5" to the clear_refs pseudo-file in a processes's proc
directory resets the peak RSS.
This change is an evolution of a previous patch, which mostly copied the
cgroup v1 behavior, however, there were concerns about races/ownership
issues with a global reset, so instead this change makes the reset
filedescriptor-local.
Writing any non-empty string to the memory.peak and memory.swap.peak
pseudo-files reset the high watermark to the current usage for subsequent
reads through that same FD.
Notably, following Johannes's suggestion, this implementation moves the
O(FDs that have written) behavior onto the FD write(2) path. Instead, on
the page-allocation path, we simply add one additional watermark to
conditionally bump per-hierarchy level in the page-counter.
Additionally, this takes Longman's suggestion of nesting the
page-charging-path checks for the two watermarks to reduce the number of
common-case comparisons.
This behavior is particularly useful for work scheduling systems that need
to track memory usage of worker processes/cgroups per-work-item. Since
memory can't be squeezed like CPU can (the OOM-killer has opinions), these
systems need to track the peak memory usage to compute system/container
fullness when binpacking workitems.
Most notably, Vimeo's use-case involves a system that's doing global
binpacking across many Kubernetes pods/containers, and while we can use
PSI for some local decisions about overload, we strive to avoid packing
workloads too tightly in the first place. To facilitate this, we track
the peak memory usage. However, since we run with long-lived workers (to
amortize startup costs) we need a way to track the high watermark while a
work-item is executing. Polling runs the risk of missing short spikes
that last for timescales below the polling interval, and peak memory
tracking at the cgroup level is otherwise perfect for this use-case.
As this data is used to ensure that binpacked work ends up with sufficient
headroom, this use-case mostly avoids the inaccuracies surrounding
reclaimable memory.
Link: https://lkml.kernel.org/r/20240730231304.761942-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-2-davidf@vimeo.com
Signed-off-by: David Finkel <davidf@vimeo.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Waiman Long <longman@redhat.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-07-29 14:37:42 +00:00
|
|
|
A write of any non-empty string to this file resets it to the
|
|
|
|
current memory usage for subsequent reads through the same
|
|
|
|
file descriptor.
|
2022-05-13 23:48:57 +00:00
|
|
|
|
2018-08-22 04:53:54 +00:00
|
|
|
memory.oom.group
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default value is "0".
|
|
|
|
|
|
|
|
Determines whether the cgroup should be treated as
|
|
|
|
an indivisible workload by the OOM killer. If set,
|
|
|
|
all tasks belonging to the cgroup or to its descendants
|
|
|
|
(if the memory cgroup is not a leaf cgroup) are killed
|
|
|
|
together or not at all. This can be used to avoid
|
|
|
|
partial kills to guarantee workload integrity.
|
|
|
|
|
|
|
|
Tasks with the OOM protection (oom_score_adj set to -1000)
|
|
|
|
are treated as an exception and are never killed.
|
|
|
|
|
|
|
|
If the OOM killer is invoked in a cgroup, it's not going
|
|
|
|
to kill any tasks outside of this cgroup, regardless
|
|
|
|
memory.oom.group values of ancestor cgroups.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
memory.events
|
|
|
|
A read-only flat-keyed file which exists on non-root cgroups.
|
|
|
|
The following entries are defined. Unless specified
|
|
|
|
otherwise, a value change in this file generates a file
|
|
|
|
modified event.
|
|
|
|
|
2019-07-12 03:55:55 +00:00
|
|
|
Note that all fields in this file are hierarchical and the
|
|
|
|
file modified event can be generated due to an event down the
|
2021-09-13 05:09:14 +00:00
|
|
|
hierarchy. For the local events at the cgroup level see
|
2019-07-12 03:55:55 +00:00
|
|
|
memory.events.local.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
low
|
|
|
|
The number of times the cgroup is reclaimed due to
|
|
|
|
high memory pressure even though its usage is under
|
|
|
|
the low boundary. This usually indicates that the low
|
|
|
|
boundary is over-committed.
|
|
|
|
|
|
|
|
high
|
|
|
|
The number of times processes of the cgroup are
|
|
|
|
throttled and routed to perform direct memory reclaim
|
|
|
|
because the high memory boundary was exceeded. For a
|
|
|
|
cgroup whose memory usage is capped by the high limit
|
|
|
|
rather than global memory pressure, this event's
|
|
|
|
occurrences are expected.
|
|
|
|
|
|
|
|
max
|
|
|
|
The number of times the cgroup's memory usage was
|
|
|
|
about to go over the max boundary. If direct reclaim
|
2017-07-06 22:40:28 +00:00
|
|
|
fails to bring it down, the cgroup goes to OOM state.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
oom
|
2017-07-06 22:40:28 +00:00
|
|
|
The number of time the cgroup's memory usage was
|
|
|
|
reached the limit and allocation was about to fail.
|
|
|
|
|
mm: don't raise MEMCG_OOM event due to failed high-order allocation
It was reported that on some of our machines containers were restarted
with OOM symptoms without an obvious reason. Despite there were almost no
memory pressure and plenty of page cache, MEMCG_OOM event was raised
occasionally, causing the container management software to think, that OOM
has happened. However, no tasks have been killed.
The following investigation showed that the problem is caused by a failing
attempt to charge a high-order page. In such case, the OOM killer is
never invoked. As shown below, it can happen under conditions, which are
very far from a real OOM: e.g. there is plenty of clean page cache and no
memory pressure.
There is no sense in raising an OOM event in this case, as it might
confuse a user and lead to wrong and excessive actions (e.g. restart the
workload, as in my case).
Let's look at the charging path in try_charge(). If the memory usage is
about memory.max, which is absolutely natural for most memory cgroups, we
try to reclaim some pages. Even if we were able to reclaim enough memory
for the allocation, the following check can fail due to a race with
another concurrent allocation:
if (mem_cgroup_margin(mem_over_limit) >= nr_pages)
goto retry;
For regular pages the following condition will save us from triggering
the OOM:
if (nr_reclaimed && nr_pages <= (1 << PAGE_ALLOC_COSTLY_ORDER))
goto retry;
But for high-order allocation this condition will intentionally fail. The
reason behind is that we'll likely fall to regular pages anyway, so it's
ok and even preferred to return ENOMEM.
In this case the idea of raising MEMCG_OOM looks dubious.
Fix this by moving MEMCG_OOM raising to mem_cgroup_oom() after allocation
order check, so that the event won't be raised for high order allocations.
This change doesn't affect regular pages allocation and charging.
Link: http://lkml.kernel.org/r/20181004214050.7417-1-guro@fb.com
Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Michal Hocko <mhocko@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-26 22:09:48 +00:00
|
|
|
This event is not raised if the OOM killer is not
|
|
|
|
considered as an option, e.g. for failed high-order
|
2020-06-08 04:42:55 +00:00
|
|
|
allocations or if caller asked to not retry attempts.
|
mm: don't raise MEMCG_OOM event due to failed high-order allocation
It was reported that on some of our machines containers were restarted
with OOM symptoms without an obvious reason. Despite there were almost no
memory pressure and plenty of page cache, MEMCG_OOM event was raised
occasionally, causing the container management software to think, that OOM
has happened. However, no tasks have been killed.
The following investigation showed that the problem is caused by a failing
attempt to charge a high-order page. In such case, the OOM killer is
never invoked. As shown below, it can happen under conditions, which are
very far from a real OOM: e.g. there is plenty of clean page cache and no
memory pressure.
There is no sense in raising an OOM event in this case, as it might
confuse a user and lead to wrong and excessive actions (e.g. restart the
workload, as in my case).
Let's look at the charging path in try_charge(). If the memory usage is
about memory.max, which is absolutely natural for most memory cgroups, we
try to reclaim some pages. Even if we were able to reclaim enough memory
for the allocation, the following check can fail due to a race with
another concurrent allocation:
if (mem_cgroup_margin(mem_over_limit) >= nr_pages)
goto retry;
For regular pages the following condition will save us from triggering
the OOM:
if (nr_reclaimed && nr_pages <= (1 << PAGE_ALLOC_COSTLY_ORDER))
goto retry;
But for high-order allocation this condition will intentionally fail. The
reason behind is that we'll likely fall to regular pages anyway, so it's
ok and even preferred to return ENOMEM.
In this case the idea of raising MEMCG_OOM looks dubious.
Fix this by moving MEMCG_OOM raising to mem_cgroup_oom() after allocation
order check, so that the event won't be raised for high order allocations.
This change doesn't affect regular pages allocation and charging.
Link: http://lkml.kernel.org/r/20181004214050.7417-1-guro@fb.com
Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Michal Hocko <mhocko@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-26 22:09:48 +00:00
|
|
|
|
2017-07-06 22:40:28 +00:00
|
|
|
oom_kill
|
|
|
|
The number of processes belonging to this cgroup
|
|
|
|
killed by any kind of OOM killer.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2022-01-14 22:05:35 +00:00
|
|
|
oom_group_kill
|
|
|
|
The number of times a group OOM has occurred.
|
|
|
|
|
2019-07-12 03:55:55 +00:00
|
|
|
memory.events.local
|
|
|
|
Similar to memory.events but the fields in the file are local
|
|
|
|
to the cgroup i.e. not hierarchical. The file modified event
|
|
|
|
generated on this file reflects only the local events.
|
|
|
|
|
2016-01-20 23:03:19 +00:00
|
|
|
memory.stat
|
|
|
|
A read-only flat-keyed file which exists on non-root cgroups.
|
|
|
|
|
|
|
|
This breaks down the cgroup's memory footprint into different
|
|
|
|
types of memory, type-specific details, and other information
|
|
|
|
on the state and past events of the memory management system.
|
|
|
|
|
|
|
|
All memory amounts are in bytes.
|
|
|
|
|
|
|
|
The entries are ordered to be human readable, and new entries
|
|
|
|
can show up in the middle. Don't rely on items remaining in a
|
|
|
|
fixed position; use the keys to look up specific values!
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
If the entry has no per-node counter (or not show in the
|
|
|
|
memory.numa_stat). We use 'npn' (non-per-node) as the tag
|
|
|
|
to indicate that it will not show in the memory.numa_stat.
|
2020-10-13 23:52:59 +00:00
|
|
|
|
2016-01-20 23:03:19 +00:00
|
|
|
anon
|
|
|
|
Amount of memory used in anonymous mappings such as
|
|
|
|
brk(), sbrk(), and mmap(MAP_ANONYMOUS)
|
|
|
|
|
|
|
|
file
|
|
|
|
Amount of memory used to cache filesystem data,
|
|
|
|
including tmpfs and shared memory.
|
|
|
|
|
memcg: add per-memcg total kernel memory stat
Currently memcg stats show several types of kernel memory: kernel stack,
page tables, sock, vmalloc, and slab. However, there are other
allocations with __GFP_ACCOUNT (or supersets such as GFP_KERNEL_ACCOUNT)
that are not accounted in any of those stats, a few examples are:
- various kvm allocations (e.g. allocated pages to create vcpus)
- io_uring
- tmp_page in pipes during pipe_write()
- bpf ringbuffers
- unix sockets
Keeping track of the total kernel memory is essential for the ease of
migration from cgroup v1 to v2 as there are large discrepancies between
v1's kmem.usage_in_bytes and the sum of the available kernel memory
stats in v2. Adding separate memcg stats for all __GFP_ACCOUNT kernel
allocations is an impractical maintenance burden as there a lot of those
all over the kernel code, with more use cases likely to show up in the
future.
Therefore, add a "kernel" memcg stat that is analogous to kmem page
counter, with added benefits such as using rstat infrastructure which
aggregates stats more efficiently. Additionally, this provides a
lighter alternative in case the legacy kmem is deprecated in the future
[yosryahmed@google.com: v2]
Link: https://lkml.kernel.org/r/20220203193856.972500-1-yosryahmed@google.com
Link: https://lkml.kernel.org/r/20220201200823.3283171-1-yosryahmed@google.com
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-22 21:40:10 +00:00
|
|
|
kernel (npn)
|
|
|
|
Amount of total kernel memory, including
|
|
|
|
(kernel_stack, pagetables, percpu, vmalloc, slab) in
|
|
|
|
addition to other kernel memory use cases.
|
|
|
|
|
2016-03-17 21:17:38 +00:00
|
|
|
kernel_stack
|
|
|
|
Amount of memory allocated to kernel stacks.
|
|
|
|
|
2020-12-15 03:07:17 +00:00
|
|
|
pagetables
|
|
|
|
Amount of memory allocated for page tables.
|
|
|
|
|
mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses.
We keep track of several kernel memory stats (total kernel memory, page
tables, stack, vmalloc, etc) on multiple levels (global, per-node,
per-memcg, etc). These stats give insights to users to how much memory
is used by the kernel and for what purposes.
Currently, memory used by KVM mmu is not accounted in any of those
kernel memory stats. This patch series accounts the memory pages
used by KVM for page tables in those stats in a new
NR_SECONDARY_PAGETABLE stat. This stat can be later extended to account
for other types of secondary pages tables (e.g. iommu page tables).
KVM has a decent number of large allocations that aren't for page
tables, but for most of them, the number/size of those allocations
scales linearly with either the number of vCPUs or the amount of memory
assigned to the VM. KVM's secondary page table allocations do not scale
linearly, especially when nested virtualization is in use.
From a KVM perspective, NR_SECONDARY_PAGETABLE will scale with KVM's
per-VM pages_{4k,2m,1g} stats unless the guest is doing something
bizarre (e.g. accessing only 4kb chunks of 2mb pages so that KVM is
forced to allocate a large number of page tables even though the guest
isn't accessing that much memory). However, someone would need to either
understand how KVM works to make that connection, or know (or be told) to
go look at KVM's stats if they're running VMs to better decipher the stats.
Furthermore, having NR_PAGETABLE side-by-side with NR_SECONDARY_PAGETABLE
is informative. For example, when backing a VM with THP vs. HugeTLB,
NR_SECONDARY_PAGETABLE is roughly the same, but NR_PAGETABLE is an order
of magnitude higher with THP. So having this stat will at the very least
prove to be useful for understanding tradeoffs between VM backing types,
and likely even steer folks towards potential optimizations.
The original discussion with more details about the rationale:
https://lore.kernel.org/all/87ilqoi77b.wl-maz@kernel.org
This stat will be used by subsequent patches to count KVM mmu
memory usage.
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220823004639.2387269-2-yosryahmed@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
2022-08-23 00:46:36 +00:00
|
|
|
sec_pagetables
|
|
|
|
Amount of memory allocated for secondary page tables,
|
|
|
|
this currently includes KVM mmu allocations on x86
|
2024-04-13 00:25:22 +00:00
|
|
|
and arm64 and IOMMU page tables.
|
mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses.
We keep track of several kernel memory stats (total kernel memory, page
tables, stack, vmalloc, etc) on multiple levels (global, per-node,
per-memcg, etc). These stats give insights to users to how much memory
is used by the kernel and for what purposes.
Currently, memory used by KVM mmu is not accounted in any of those
kernel memory stats. This patch series accounts the memory pages
used by KVM for page tables in those stats in a new
NR_SECONDARY_PAGETABLE stat. This stat can be later extended to account
for other types of secondary pages tables (e.g. iommu page tables).
KVM has a decent number of large allocations that aren't for page
tables, but for most of them, the number/size of those allocations
scales linearly with either the number of vCPUs or the amount of memory
assigned to the VM. KVM's secondary page table allocations do not scale
linearly, especially when nested virtualization is in use.
From a KVM perspective, NR_SECONDARY_PAGETABLE will scale with KVM's
per-VM pages_{4k,2m,1g} stats unless the guest is doing something
bizarre (e.g. accessing only 4kb chunks of 2mb pages so that KVM is
forced to allocate a large number of page tables even though the guest
isn't accessing that much memory). However, someone would need to either
understand how KVM works to make that connection, or know (or be told) to
go look at KVM's stats if they're running VMs to better decipher the stats.
Furthermore, having NR_PAGETABLE side-by-side with NR_SECONDARY_PAGETABLE
is informative. For example, when backing a VM with THP vs. HugeTLB,
NR_SECONDARY_PAGETABLE is roughly the same, but NR_PAGETABLE is an order
of magnitude higher with THP. So having this stat will at the very least
prove to be useful for understanding tradeoffs between VM backing types,
and likely even steer folks towards potential optimizations.
The original discussion with more details about the rationale:
https://lore.kernel.org/all/87ilqoi77b.wl-maz@kernel.org
This stat will be used by subsequent patches to count KVM mmu
memory usage.
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220823004639.2387269-2-yosryahmed@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
2022-08-23 00:46:36 +00:00
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
percpu (npn)
|
2020-08-12 01:30:21 +00:00
|
|
|
Amount of memory used for storing per-cpu kernel
|
|
|
|
data structures.
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
sock (npn)
|
2016-02-03 00:57:41 +00:00
|
|
|
Amount of memory used in network transmission buffers
|
|
|
|
|
2022-01-14 22:05:45 +00:00
|
|
|
vmalloc (npn)
|
|
|
|
Amount of memory used for vmap backed memory.
|
|
|
|
|
2017-05-03 21:52:45 +00:00
|
|
|
shmem
|
|
|
|
Amount of cached filesystem data that is swap-backed,
|
|
|
|
such as tmpfs, shm segments, shared anonymous mmap()s
|
|
|
|
|
2022-05-19 21:08:53 +00:00
|
|
|
zswap
|
|
|
|
Amount of memory consumed by the zswap compression backend.
|
|
|
|
|
|
|
|
zswapped
|
|
|
|
Amount of application memory swapped out to zswap.
|
|
|
|
|
2016-01-20 23:03:19 +00:00
|
|
|
file_mapped
|
|
|
|
Amount of cached filesystem data mapped with mmap()
|
|
|
|
|
|
|
|
file_dirty
|
|
|
|
Amount of cached filesystem data that was modified but
|
|
|
|
not yet written back to disk
|
|
|
|
|
|
|
|
file_writeback
|
|
|
|
Amount of cached filesystem data that was modified and
|
|
|
|
is currently being written back to disk
|
|
|
|
|
2021-02-24 20:03:55 +00:00
|
|
|
swapcached
|
|
|
|
Amount of swap cached in memory. The swapcache is accounted
|
|
|
|
against both memory and swap usage.
|
|
|
|
|
2019-03-05 23:48:09 +00:00
|
|
|
anon_thp
|
|
|
|
Amount of memory used in anonymous mappings backed by
|
|
|
|
transparent hugepages
|
2020-12-15 03:06:20 +00:00
|
|
|
|
|
|
|
file_thp
|
|
|
|
Amount of cached filesystem data backed by transparent
|
|
|
|
hugepages
|
|
|
|
|
|
|
|
shmem_thp
|
|
|
|
Amount of shm, tmpfs, shared anonymous mmap()s backed by
|
|
|
|
transparent hugepages
|
2019-03-05 23:48:09 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
inactive_anon, active_anon, inactive_file, active_file, unevictable
|
2016-01-20 23:03:19 +00:00
|
|
|
Amount of memory, swap-backed and filesystem-backed,
|
|
|
|
on the internal memory management lists used by the
|
2019-12-01 01:50:19 +00:00
|
|
|
page reclaim algorithm.
|
|
|
|
|
|
|
|
As these represent internal list state (eg. shmem pages are on anon
|
|
|
|
memory management lists), inactive_foo + active_foo may not be equal to
|
|
|
|
the value for the foo counter, since the foo counter is type-based, not
|
|
|
|
list-based.
|
2016-01-20 23:03:19 +00:00
|
|
|
|
2016-03-17 21:17:35 +00:00
|
|
|
slab_reclaimable
|
|
|
|
Part of "slab" that might be reclaimed, such as
|
|
|
|
dentries and inodes.
|
|
|
|
|
|
|
|
slab_unreclaimable
|
|
|
|
Part of "slab" that cannot be reclaimed on memory
|
|
|
|
pressure.
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
slab (npn)
|
2020-10-13 23:52:59 +00:00
|
|
|
Amount of memory used for storing in-kernel data
|
|
|
|
structures.
|
2016-01-20 23:03:19 +00:00
|
|
|
|
2020-09-26 04:19:05 +00:00
|
|
|
workingset_refault_anon
|
|
|
|
Number of refaults of previously evicted anonymous pages.
|
2017-05-12 22:47:09 +00:00
|
|
|
|
2020-09-26 04:19:05 +00:00
|
|
|
workingset_refault_file
|
|
|
|
Number of refaults of previously evicted file pages.
|
2017-05-12 22:47:09 +00:00
|
|
|
|
2020-09-26 04:19:05 +00:00
|
|
|
workingset_activate_anon
|
|
|
|
Number of refaulted anonymous pages that were immediately
|
|
|
|
activated.
|
|
|
|
|
|
|
|
workingset_activate_file
|
|
|
|
Number of refaulted file pages that were immediately activated.
|
|
|
|
|
|
|
|
workingset_restore_anon
|
|
|
|
Number of restored anonymous pages which have been detected as
|
|
|
|
an active workingset before they got reclaimed.
|
|
|
|
|
|
|
|
workingset_restore_file
|
|
|
|
Number of restored file pages which have been detected as an
|
|
|
|
active workingset before they got reclaimed.
|
2020-06-02 04:49:32 +00:00
|
|
|
|
2017-05-12 22:47:09 +00:00
|
|
|
workingset_nodereclaim
|
|
|
|
Number of times a shadow node has been reclaimed
|
|
|
|
|
mm: memcontrol: add {pgscan,pgsteal}_{kswapd,direct} items in memory.stat of cgroup v2
There are already statistics of {pgscan,pgsteal}_kswapd and
{pgscan,pgsteal}_direct of memcg event here, but now only the sum of the
two is displayed in memory.stat of cgroup v2.
In order to obtain more accurate information during monitoring and
debugging, and to align with the display in /proc/vmstat, it better to
display {pgscan,pgsteal}_kswapd and {pgscan,pgsteal}_direct separately.
Also, for forward compatibility, we still display pgscan and pgsteal items
so that it won't break existing applications.
[zhengqi.arch@bytedance.com: add comment for memcg_vm_event_stat (suggested by Michal)]
Link: https://lkml.kernel.org/r/20220606154028.55030-1-zhengqi.arch@bytedance.com
[zhengqi.arch@bytedance.com: fix the doc, thanks to Johannes]
Link: https://lkml.kernel.org/r/20220607064803.79363-1-zhengqi.arch@bytedance.com
Link: https://lkml.kernel.org/r/20220604082209.55174-1-zhengqi.arch@bytedance.com
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-06-04 08:22:09 +00:00
|
|
|
pgscan (npn)
|
|
|
|
Amount of scanned pages (in an inactive LRU list)
|
|
|
|
|
|
|
|
pgsteal (npn)
|
|
|
|
Amount of reclaimed pages
|
|
|
|
|
|
|
|
pgscan_kswapd (npn)
|
|
|
|
Amount of scanned pages by kswapd (in an inactive LRU list)
|
|
|
|
|
|
|
|
pgscan_direct (npn)
|
|
|
|
Amount of scanned pages directly (in an inactive LRU list)
|
|
|
|
|
2022-10-26 18:01:33 +00:00
|
|
|
pgscan_khugepaged (npn)
|
|
|
|
Amount of scanned pages by khugepaged (in an inactive LRU list)
|
|
|
|
|
mm: memcontrol: add {pgscan,pgsteal}_{kswapd,direct} items in memory.stat of cgroup v2
There are already statistics of {pgscan,pgsteal}_kswapd and
{pgscan,pgsteal}_direct of memcg event here, but now only the sum of the
two is displayed in memory.stat of cgroup v2.
In order to obtain more accurate information during monitoring and
debugging, and to align with the display in /proc/vmstat, it better to
display {pgscan,pgsteal}_kswapd and {pgscan,pgsteal}_direct separately.
Also, for forward compatibility, we still display pgscan and pgsteal items
so that it won't break existing applications.
[zhengqi.arch@bytedance.com: add comment for memcg_vm_event_stat (suggested by Michal)]
Link: https://lkml.kernel.org/r/20220606154028.55030-1-zhengqi.arch@bytedance.com
[zhengqi.arch@bytedance.com: fix the doc, thanks to Johannes]
Link: https://lkml.kernel.org/r/20220607064803.79363-1-zhengqi.arch@bytedance.com
Link: https://lkml.kernel.org/r/20220604082209.55174-1-zhengqi.arch@bytedance.com
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-06-04 08:22:09 +00:00
|
|
|
pgsteal_kswapd (npn)
|
|
|
|
Amount of reclaimed pages by kswapd
|
|
|
|
|
|
|
|
pgsteal_direct (npn)
|
|
|
|
Amount of reclaimed pages directly
|
|
|
|
|
2022-10-26 18:01:33 +00:00
|
|
|
pgsteal_khugepaged (npn)
|
|
|
|
Amount of reclaimed pages by khugepaged
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pgfault (npn)
|
2020-10-13 23:52:59 +00:00
|
|
|
Total number of page faults incurred
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pgmajfault (npn)
|
2020-10-13 23:52:59 +00:00
|
|
|
Number of major page faults incurred
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pgrefill (npn)
|
2017-07-06 22:40:25 +00:00
|
|
|
Amount of scanned pages (in an active LRU list)
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pgactivate (npn)
|
2017-07-06 22:40:25 +00:00
|
|
|
Amount of pages moved to the active LRU list
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pgdeactivate (npn)
|
2019-11-11 14:44:38 +00:00
|
|
|
Amount of pages moved to the inactive LRU list
|
2017-07-06 22:40:25 +00:00
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pglazyfree (npn)
|
2017-07-06 22:40:25 +00:00
|
|
|
Amount of pages postponed to be freed under memory pressure
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
pglazyfreed (npn)
|
2017-07-06 22:40:25 +00:00
|
|
|
Amount of reclaimed lazyfree pages
|
|
|
|
|
mm: count zeromap read and set for swapout and swapin
When the proportion of folios from the zeromap is small, missing their
accounting may not significantly impact profiling. However, it's easy to
construct a scenario where this becomes an issue—for example, allocating
1 GB of memory, writing zeros from userspace, followed by MADV_PAGEOUT,
and then swapping it back in. In this case, the swap-out and swap-in
counts seem to vanish into a black hole, potentially causing semantic
ambiguity.
On the other hand, Usama reported that zero-filled pages can exceed 10% in
workloads utilizing zswap, while Hailong noted that some app in Android
have more than 6% zero-filled pages. Before commit 0ca0c24e3211 ("mm:
store zero pages to be swapped out in a bitmap"), both zswap and zRAM
implemented similar optimizations, leading to these optimized-out pages
being counted in either zswap or zRAM counters (with pswpin/pswpout also
increasing for zRAM). With zeromap functioning prior to both zswap and
zRAM, userspace will no longer detect these swap-out and swap-in actions.
We have three ways to address this:
1. Introduce a dedicated counter specifically for the zeromap.
2. Use pswpin/pswpout accounting, treating the zero map as a standard
backend. This approach aligns with zRAM's current handling of
same-page fills at the device level. However, it would mean losing the
optimized-out page counters previously available in zRAM and would not
align with systems using zswap. Additionally, as noted by Nhat Pham,
pswpin/pswpout counters apply only to I/O done directly to the backend
device.
3. Count zeromap pages under zswap, aligning with system behavior when
zswap is enabled. However, this would not be consistent with zRAM, nor
would it align with systems lacking both zswap and zRAM.
Given the complications with options 2 and 3, this patch selects
option 1.
We can find these counters from /proc/vmstat (counters for the whole
system) and memcg's memory.stat (counters for the interested memcg).
For example:
$ grep -E 'swpin_zero|swpout_zero' /proc/vmstat
swpin_zero 1648
swpout_zero 33536
$ grep -E 'swpin_zero|swpout_zero' /sys/fs/cgroup/system.slice/memory.stat
swpin_zero 3905
swpout_zero 3985
This patch does not address any specific zeromap bug, but the missing
swpout and swpin counts for zero-filled pages can be highly confusing and
may mislead user-space agents that rely on changes in these counters as
indicators. Therefore, we add a Fixes tag to encourage the inclusion of
this counter in any kernel versions with zeromap.
Many thanks to Kanchana for the contribution of changing
count_objcg_event() to count_objcg_events() to support large folios[1],
which has now been incorporated into this patch.
[1] https://lkml.kernel.org/r/20241001053222.6944-5-kanchana.p.sridhar@intel.com
Link: https://lkml.kernel.org/r/20241107011246.59137-1-21cnbao@gmail.com
Fixes: 0ca0c24e3211 ("mm: store zero pages to be swapped out in a bitmap")
Co-developed-by: Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Usama Arif <usamaarif642@gmail.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Cc: Hailong Liu <hailong.liu@oppo.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-11-07 01:12:46 +00:00
|
|
|
swpin_zero
|
|
|
|
Number of pages swapped into memory and filled with zero, where I/O
|
|
|
|
was optimized out because the page content was detected to be zero
|
|
|
|
during swapout.
|
|
|
|
|
|
|
|
swpout_zero
|
|
|
|
Number of zero-filled pages swapped out with I/O skipped due to the
|
|
|
|
content being detected as zero.
|
|
|
|
|
2024-05-02 18:50:24 +00:00
|
|
|
zswpin
|
|
|
|
Number of pages moved in to memory from zswap.
|
|
|
|
|
|
|
|
zswpout
|
|
|
|
Number of pages moved out of memory to zswap.
|
|
|
|
|
|
|
|
zswpwb
|
|
|
|
Number of pages written from zswap to swap.
|
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
thp_fault_alloc (npn)
|
2019-03-05 23:48:09 +00:00
|
|
|
Number of transparent hugepages which were allocated to satisfy
|
2020-06-26 03:30:28 +00:00
|
|
|
a page fault. This counter is not present when CONFIG_TRANSPARENT_HUGEPAGE
|
|
|
|
is not set.
|
2019-03-05 23:48:09 +00:00
|
|
|
|
2021-01-20 00:18:20 +00:00
|
|
|
thp_collapse_alloc (npn)
|
2019-03-05 23:48:09 +00:00
|
|
|
Number of transparent hugepages which were allocated to allow
|
|
|
|
collapsing an existing range of pages. This counter is not
|
|
|
|
present when CONFIG_TRANSPARENT_HUGEPAGE is not set.
|
|
|
|
|
mm: memcg: add THP swap out info for anonymous reclaim
At present, we support per-memcg reclaim strategy, however we do not know
the number of transparent huge pages being reclaimed, as we know the
transparent huge pages need to be splited before reclaim them, and they
will bring some performance bottleneck effect. for example, when two
memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A'
memcg is reclaiming a large number of transparent huge pages, we can
better analyze that the performance bottleneck will be caused by 'A'
memcg. therefore, in order to better analyze such problems, there add THP
swap out info for per-memcg.
[akpm@linux-foundation.orgL fix swap_writepage_fs(), per Johannes]
Link: https://lkml.kernel.org/r/20230913213343.GB48476@cmpxchg.org
Link: https://lkml.kernel.org/r/20230913164938.16918-1-vernhao@tencent.com
Signed-off-by: Xin Hao <vernhao@tencent.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-09-13 16:49:37 +00:00
|
|
|
thp_swpout (npn)
|
|
|
|
Number of transparent hugepages which are swapout in one piece
|
|
|
|
without splitting.
|
|
|
|
|
|
|
|
thp_swpout_fallback (npn)
|
|
|
|
Number of transparent hugepages which were split before swapout.
|
|
|
|
Usually because failed to allocate some continuous swap space
|
|
|
|
for the huge page.
|
|
|
|
|
mm,memcg: provide per-cgroup counters for NUMA balancing operations
The ability to observe the demotion and promotion decisions made by the
kernel on a per-cgroup basis is important for monitoring and tuning
containerized workloads on machines equipped with tiered memory.
Different containers in the system may experience drastically different
memory tiering actions that cannot be distinguished from the global
counters alone.
For example, a container running a workload that has a much hotter memory
accesses will likely see more promotions and fewer demotions, potentially
depriving a colocated container of top tier memory to such an extent that
its performance degrades unacceptably.
For another example, some containers may exhibit longer periods between
data reuse, causing much more numa_hint_faults than numa_pages_migrated.
In this case, tuning hot_threshold_ms may be appropriate, but the signal
can easily be lost if only global counters are available.
In the long term, we hope to introduce per-cgroup control of promotion and
demotion actions to implement memory placement policies in tiering.
This patch set adds seven counters to memory.stat in a cgroup:
numa_pages_migrated, numa_pte_updates, numa_hint_faults, pgdemote_kswapd,
pgdemote_khugepaged, pgdemote_direct and pgpromote_success. pgdemote_*
and pgpromote_success are also available in memory.numa_stat.
count_memcg_events_mm() is added to count multiple event occurrences at
once, and get_mem_cgroup_from_folio() is added because we need to get a
reference to the memcg of a folio before it's migrated to track
numa_pages_migrated. The accounting of PGDEMOTE_* is moved to
shrink_inactive_list() before being changed to per-cgroup.
[kaiyang2@cs.cmu.edu: add documentation of the memcg counters in cgroup-v2.rst]
Link: https://lkml.kernel.org/r/20240814235122.252309-1-kaiyang2@cs.cmu.edu
Link: https://lkml.kernel.org/r/20240814174227.30639-1-kaiyang2@cs.cmu.edu
Signed-off-by: Kaiyang Zhao <kaiyang2@cs.cmu.edu>
Cc: David Rientjes <rientjes@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Wei Xu <weixugc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-08-14 17:42:27 +00:00
|
|
|
numa_pages_migrated (npn)
|
|
|
|
Number of pages migrated by NUMA balancing.
|
|
|
|
|
|
|
|
numa_pte_updates (npn)
|
|
|
|
Number of pages whose page table entries are modified by
|
|
|
|
NUMA balancing to produce NUMA hinting faults on access.
|
|
|
|
|
|
|
|
numa_hint_faults (npn)
|
|
|
|
Number of NUMA hinting faults.
|
|
|
|
|
|
|
|
pgdemote_kswapd
|
|
|
|
Number of pages demoted by kswapd.
|
|
|
|
|
|
|
|
pgdemote_direct
|
|
|
|
Number of pages demoted directly.
|
|
|
|
|
|
|
|
pgdemote_khugepaged
|
|
|
|
Number of pages demoted by khugepaged.
|
|
|
|
|
memcg/hugetlb: add hugeTLB counters to memcg
This patch introduces a new counter to memory.stat that tracks hugeTLB
usage, only if hugeTLB accounting is done to memory.current. This feature
is enabled the same way hugeTLB accounting is enabled, via the
memory_hugetlb_accounting mount flag for cgroupsv2.
1. Why is this patch necessary?
Currently, memcg hugeTLB accounting is an opt-in feature [1] that adds
hugeTLB usage to memory.current. However, the metric is not reported in
memory.stat. Given that users often interpret memory.stat as a breakdown
of the value reported in memory.current, the disparity between the two
reports can be confusing. This patch solves this problem by including the
metric in memory.stat as well, but only if it is also reported in
memory.current (it would also be confusing if the value was reported in
memory.stat, but not in memory.current)
Aside from the consistency between the two files, we also see benefits in
observability. Userspace might be interested in the hugeTLB footprint of
cgroups for many reasons. For instance, system admins might want to
verify that hugeTLB usage is distributed as expected across tasks: i.e.
memory-intensive tasks are using more hugeTLB pages than tasks that don't
consume a lot of memory, or are seen to fault frequently. Note that this
is separate from wanting to inspect the distribution for limiting purposes
(in which case, hugeTLB controller makes more sense).
2. We already have a hugeTLB controller. Why not use that?
It is true that hugeTLB tracks the exact value that we want. In fact, by
enabling the hugeTLB controller, we get all of the observability benefits
that I mentioned above, and users can check the total hugeTLB usage,
verify if it is distributed as expected, etc.
With this said, there are 2 problems:
(a) They are still not reported in memory.stat, which means the
disparity between the memcg reports are still there.
(b) We cannot reasonably expect users to enable the hugeTLB controller
just for the sake of hugeTLB usage reporting, especially since
they don't have any use for hugeTLB usage enforcing [2].
3. Implementation Details:
In the alloc / free hugetlb functions, we call lruvec_stat_mod_folio
regardless of whether memcg accounts hugetlb. mem_cgroup_commit_charge
which is called from alloc_hugetlb_folio will set memcg for the folio only
if the CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING cgroup mount option is used, so
lruvec_stat_mod_folio accounts per-memcg hugetlb counters only if the
feature is enabled. Regardless of whether memcg accounts for hugetlb, the
newly added global counter is updated and shown in /proc/vmstat.
The global counter is added because vmstats is the preferred framework for
cgroup stats. It makes stat items consistent between global and cgroups.
It also provides a per-node breakdown, which is useful. Because it does
not use cgroup-specific hooks, we also keep generic MM code separate from
memcg code.
[1] https://lore.kernel.org/all/20231006184629.155543-1-nphamcs@gmail.com/
[2] Of course, we can't make a new patch for every feature that can be
duplicated. However, since the existing solution of enabling the
hugeTLB controller is an imperfect solution that still leaves a
discrepancy between memory.stat and memory.curent, I think that it
is reasonable to isolate the feature in this case.
Link: https://lkml.kernel.org/r/20241101204402.1885383-1-joshua.hahnjy@gmail.com
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Suggested-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Chris Down <chris@chrisdown.name>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-11-01 20:44:02 +00:00
|
|
|
hugetlb
|
|
|
|
Amount of memory used by hugetlb pages. This metric only shows
|
|
|
|
up if hugetlb usage is accounted for in memory.current (i.e.
|
|
|
|
cgroup is mounted with the memory_hugetlb_accounting option).
|
|
|
|
|
2020-10-13 23:52:59 +00:00
|
|
|
memory.numa_stat
|
|
|
|
A read-only nested-keyed file which exists on non-root cgroups.
|
|
|
|
|
|
|
|
This breaks down the cgroup's memory footprint into different
|
|
|
|
types of memory, type-specific details, and other information
|
|
|
|
per node on the state of the memory management system.
|
|
|
|
|
|
|
|
This is useful for providing visibility into the NUMA locality
|
|
|
|
information within an memcg since the pages are allowed to be
|
|
|
|
allocated from any physical node. One of the use case is evaluating
|
|
|
|
application performance by combining this information with the
|
|
|
|
application's CPU allocation.
|
|
|
|
|
|
|
|
All memory amounts are in bytes.
|
|
|
|
|
|
|
|
The output format of memory.numa_stat is::
|
|
|
|
|
|
|
|
type N0=<bytes in node 0> N1=<bytes in node 1> ...
|
|
|
|
|
|
|
|
The entries are ordered to be human readable, and new entries
|
|
|
|
can show up in the middle. Don't rely on items remaining in a
|
|
|
|
fixed position; use the keys to look up specific values!
|
|
|
|
|
|
|
|
The entries can refer to the memory.stat.
|
|
|
|
|
2016-01-20 23:03:13 +00:00
|
|
|
memory.swap.current
|
|
|
|
A read-only single value file which exists on non-root
|
|
|
|
cgroups.
|
|
|
|
|
|
|
|
The total amount of swap currently being used by the cgroup
|
|
|
|
and its descendants.
|
|
|
|
|
2020-06-02 04:49:52 +00:00
|
|
|
memory.swap.high
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "max".
|
|
|
|
|
|
|
|
Swap usage throttle limit. If a cgroup's swap usage exceeds
|
|
|
|
this limit, all its further allocations will be throttled to
|
|
|
|
allow userspace to implement custom out-of-memory procedures.
|
|
|
|
|
|
|
|
This limit marks a point of no return for the cgroup. It is NOT
|
|
|
|
designed to manage the amount of swapping a workload does
|
|
|
|
during regular operation. Compare to memory.swap.max, which
|
|
|
|
prohibits swapping past a set amount, but lets the cgroup
|
|
|
|
continue unimpeded as long as other memory can be reclaimed.
|
|
|
|
|
|
|
|
Healthy workloads are not expected to reach this limit.
|
|
|
|
|
2023-05-24 18:17:33 +00:00
|
|
|
memory.swap.peak
|
mm, memcg: cg2 memory{.swap,}.peak write handlers
Patch series "mm, memcg: cg2 memory{.swap,}.peak write handlers", v7.
This patch (of 2):
Other mechanisms for querying the peak memory usage of either a process or
v1 memory cgroup allow for resetting the high watermark. Restore parity
with those mechanisms, but with a less racy API.
For example:
- Any write to memory.max_usage_in_bytes in a cgroup v1 mount resets
the high watermark.
- writing "5" to the clear_refs pseudo-file in a processes's proc
directory resets the peak RSS.
This change is an evolution of a previous patch, which mostly copied the
cgroup v1 behavior, however, there were concerns about races/ownership
issues with a global reset, so instead this change makes the reset
filedescriptor-local.
Writing any non-empty string to the memory.peak and memory.swap.peak
pseudo-files reset the high watermark to the current usage for subsequent
reads through that same FD.
Notably, following Johannes's suggestion, this implementation moves the
O(FDs that have written) behavior onto the FD write(2) path. Instead, on
the page-allocation path, we simply add one additional watermark to
conditionally bump per-hierarchy level in the page-counter.
Additionally, this takes Longman's suggestion of nesting the
page-charging-path checks for the two watermarks to reduce the number of
common-case comparisons.
This behavior is particularly useful for work scheduling systems that need
to track memory usage of worker processes/cgroups per-work-item. Since
memory can't be squeezed like CPU can (the OOM-killer has opinions), these
systems need to track the peak memory usage to compute system/container
fullness when binpacking workitems.
Most notably, Vimeo's use-case involves a system that's doing global
binpacking across many Kubernetes pods/containers, and while we can use
PSI for some local decisions about overload, we strive to avoid packing
workloads too tightly in the first place. To facilitate this, we track
the peak memory usage. However, since we run with long-lived workers (to
amortize startup costs) we need a way to track the high watermark while a
work-item is executing. Polling runs the risk of missing short spikes
that last for timescales below the polling interval, and peak memory
tracking at the cgroup level is otherwise perfect for this use-case.
As this data is used to ensure that binpacked work ends up with sufficient
headroom, this use-case mostly avoids the inaccuracies surrounding
reclaimable memory.
Link: https://lkml.kernel.org/r/20240730231304.761942-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-2-davidf@vimeo.com
Signed-off-by: David Finkel <davidf@vimeo.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Waiman Long <longman@redhat.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-07-29 14:37:42 +00:00
|
|
|
A read-write single value file which exists on non-root cgroups.
|
|
|
|
|
|
|
|
The max swap usage recorded for the cgroup and its descendants since
|
|
|
|
the creation of the cgroup or the most recent reset for that FD.
|
2023-05-24 18:17:33 +00:00
|
|
|
|
mm, memcg: cg2 memory{.swap,}.peak write handlers
Patch series "mm, memcg: cg2 memory{.swap,}.peak write handlers", v7.
This patch (of 2):
Other mechanisms for querying the peak memory usage of either a process or
v1 memory cgroup allow for resetting the high watermark. Restore parity
with those mechanisms, but with a less racy API.
For example:
- Any write to memory.max_usage_in_bytes in a cgroup v1 mount resets
the high watermark.
- writing "5" to the clear_refs pseudo-file in a processes's proc
directory resets the peak RSS.
This change is an evolution of a previous patch, which mostly copied the
cgroup v1 behavior, however, there were concerns about races/ownership
issues with a global reset, so instead this change makes the reset
filedescriptor-local.
Writing any non-empty string to the memory.peak and memory.swap.peak
pseudo-files reset the high watermark to the current usage for subsequent
reads through that same FD.
Notably, following Johannes's suggestion, this implementation moves the
O(FDs that have written) behavior onto the FD write(2) path. Instead, on
the page-allocation path, we simply add one additional watermark to
conditionally bump per-hierarchy level in the page-counter.
Additionally, this takes Longman's suggestion of nesting the
page-charging-path checks for the two watermarks to reduce the number of
common-case comparisons.
This behavior is particularly useful for work scheduling systems that need
to track memory usage of worker processes/cgroups per-work-item. Since
memory can't be squeezed like CPU can (the OOM-killer has opinions), these
systems need to track the peak memory usage to compute system/container
fullness when binpacking workitems.
Most notably, Vimeo's use-case involves a system that's doing global
binpacking across many Kubernetes pods/containers, and while we can use
PSI for some local decisions about overload, we strive to avoid packing
workloads too tightly in the first place. To facilitate this, we track
the peak memory usage. However, since we run with long-lived workers (to
amortize startup costs) we need a way to track the high watermark while a
work-item is executing. Polling runs the risk of missing short spikes
that last for timescales below the polling interval, and peak memory
tracking at the cgroup level is otherwise perfect for this use-case.
As this data is used to ensure that binpacked work ends up with sufficient
headroom, this use-case mostly avoids the inaccuracies surrounding
reclaimable memory.
Link: https://lkml.kernel.org/r/20240730231304.761942-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-1-davidf@vimeo.com
Link: https://lkml.kernel.org/r/20240729143743.34236-2-davidf@vimeo.com
Signed-off-by: David Finkel <davidf@vimeo.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Waiman Long <longman@redhat.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-07-29 14:37:42 +00:00
|
|
|
A write of any non-empty string to this file resets it to the
|
|
|
|
current memory usage for subsequent reads through the same
|
|
|
|
file descriptor.
|
2023-05-24 18:17:33 +00:00
|
|
|
|
2016-01-20 23:03:13 +00:00
|
|
|
memory.swap.max
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "max".
|
|
|
|
|
|
|
|
Swap usage hard limit. If a cgroup's swap usage reaches this
|
2018-01-02 16:27:41 +00:00
|
|
|
limit, anonymous memory of the cgroup will not be swapped out.
|
2016-01-20 23:03:13 +00:00
|
|
|
|
2018-06-08 00:05:35 +00:00
|
|
|
memory.swap.events
|
|
|
|
A read-only flat-keyed file which exists on non-root cgroups.
|
|
|
|
The following entries are defined. Unless specified
|
|
|
|
otherwise, a value change in this file generates a file
|
|
|
|
modified event.
|
|
|
|
|
2020-06-02 04:49:52 +00:00
|
|
|
high
|
|
|
|
The number of times the cgroup's swap usage was over
|
|
|
|
the high threshold.
|
|
|
|
|
2018-06-08 00:05:35 +00:00
|
|
|
max
|
|
|
|
The number of times the cgroup's swap usage was about
|
|
|
|
to go over the max boundary and swap allocation
|
|
|
|
failed.
|
|
|
|
|
|
|
|
fail
|
|
|
|
The number of times swap allocation failed either
|
|
|
|
because of running out of swap system-wide or max
|
|
|
|
limit.
|
|
|
|
|
2018-06-08 00:09:21 +00:00
|
|
|
When reduced under the current usage, the existing swap
|
|
|
|
entries are reclaimed gradually and the swap usage may stay
|
|
|
|
higher than the limit for an extended period of time. This
|
|
|
|
reduces the impact on the workload and memory management.
|
|
|
|
|
2022-05-19 21:08:53 +00:00
|
|
|
memory.zswap.current
|
|
|
|
A read-only single value file which exists on non-root
|
|
|
|
cgroups.
|
|
|
|
|
|
|
|
The total amount of memory consumed by the zswap compression
|
|
|
|
backend.
|
|
|
|
|
|
|
|
memory.zswap.max
|
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "max".
|
|
|
|
|
|
|
|
Zswap usage hard limit. If a cgroup's zswap pool reaches this
|
|
|
|
limit, it will refuse to take any more stores before existing
|
|
|
|
entries fault back in or are written out to disk.
|
|
|
|
|
zswap: memcontrol: implement zswap writeback disabling
During our experiment with zswap, we sometimes observe swap IOs due to
occasional zswap store failures and writebacks-to-swap. These swapping
IOs prevent many users who cannot tolerate swapping from adopting zswap to
save memory and improve performance where possible.
This patch adds the option to disable this behavior entirely: do not
writeback to backing swapping device when a zswap store attempt fail, and
do not write pages in the zswap pool back to the backing swap device (both
when the pool is full, and when the new zswap shrinker is called).
This new behavior can be opted-in/out on a per-cgroup basis via a new
cgroup file. By default, writebacks to swap device is enabled, which is
the previous behavior. Initially, writeback is enabled for the root
cgroup, and a newly created cgroup will inherit the current setting of its
parent.
Note that this is subtly different from setting memory.swap.max to 0, as
it still allows for pages to be stored in the zswap pool (which itself
consumes swap space in its current form).
This patch should be applied on top of the zswap shrinker series:
https://lore.kernel.org/linux-mm/20231130194023.4102148-1-nphamcs@gmail.com/
as it also disables the zswap shrinker, a major source of zswap
writebacks.
For the most part, this feature is motivated by internal parties who
have already established their opinions regarding swapping - the
workloads that are highly sensitive to IO, and especially those who are
using servers with really slow disk performance (for instance, massive
but slow HDDs). For these folks, it's impossible to convince them to
even entertain zswap if swapping also comes as a packaged deal.
Writeback disabling is quite a useful feature in these situations - on
a mixed workloads deployment, they can disable writeback for the more
IO-sensitive workloads, and enable writeback for other background
workloads.
For instance, on a server with HDD, I allocate memories and populate
them with random values (so that zswap store will always fail), and
specify memory.high low enough to trigger reclaim. The time it takes
to allocate the memories and just read through it a couple of times
(doing silly things like computing the values' average etc.):
zswap.writeback disabled:
real 0m30.537s
user 0m23.687s
sys 0m6.637s
0 pages swapped in
0 pages swapped out
zswap.writeback enabled:
real 0m45.061s
user 0m24.310s
sys 0m8.892s
712686 pages swapped in
461093 pages swapped out
(the last two lines are from vmstat -s).
[nphamcs@gmail.com: add a comment about recurring zswap store failures leading to reclaim inefficiency]
Link: https://lkml.kernel.org/r/20231221005725.3446672-1-nphamcs@gmail.com
Link: https://lkml.kernel.org/r/20231207192406.3809579-1-nphamcs@gmail.com
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: David Heidelberg <david@ixit.cz>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-12-07 19:24:06 +00:00
|
|
|
memory.zswap.writeback
|
2024-08-23 16:27:06 +00:00
|
|
|
A read-write single value file. The default value is "1".
|
|
|
|
Note that this setting is hierarchical, i.e. the writeback would be
|
|
|
|
implicitly disabled for child cgroups if the upper hierarchy
|
|
|
|
does so.
|
zswap: memcontrol: implement zswap writeback disabling
During our experiment with zswap, we sometimes observe swap IOs due to
occasional zswap store failures and writebacks-to-swap. These swapping
IOs prevent many users who cannot tolerate swapping from adopting zswap to
save memory and improve performance where possible.
This patch adds the option to disable this behavior entirely: do not
writeback to backing swapping device when a zswap store attempt fail, and
do not write pages in the zswap pool back to the backing swap device (both
when the pool is full, and when the new zswap shrinker is called).
This new behavior can be opted-in/out on a per-cgroup basis via a new
cgroup file. By default, writebacks to swap device is enabled, which is
the previous behavior. Initially, writeback is enabled for the root
cgroup, and a newly created cgroup will inherit the current setting of its
parent.
Note that this is subtly different from setting memory.swap.max to 0, as
it still allows for pages to be stored in the zswap pool (which itself
consumes swap space in its current form).
This patch should be applied on top of the zswap shrinker series:
https://lore.kernel.org/linux-mm/20231130194023.4102148-1-nphamcs@gmail.com/
as it also disables the zswap shrinker, a major source of zswap
writebacks.
For the most part, this feature is motivated by internal parties who
have already established their opinions regarding swapping - the
workloads that are highly sensitive to IO, and especially those who are
using servers with really slow disk performance (for instance, massive
but slow HDDs). For these folks, it's impossible to convince them to
even entertain zswap if swapping also comes as a packaged deal.
Writeback disabling is quite a useful feature in these situations - on
a mixed workloads deployment, they can disable writeback for the more
IO-sensitive workloads, and enable writeback for other background
workloads.
For instance, on a server with HDD, I allocate memories and populate
them with random values (so that zswap store will always fail), and
specify memory.high low enough to trigger reclaim. The time it takes
to allocate the memories and just read through it a couple of times
(doing silly things like computing the values' average etc.):
zswap.writeback disabled:
real 0m30.537s
user 0m23.687s
sys 0m6.637s
0 pages swapped in
0 pages swapped out
zswap.writeback enabled:
real 0m45.061s
user 0m24.310s
sys 0m8.892s
712686 pages swapped in
461093 pages swapped out
(the last two lines are from vmstat -s).
[nphamcs@gmail.com: add a comment about recurring zswap store failures leading to reclaim inefficiency]
Link: https://lkml.kernel.org/r/20231221005725.3446672-1-nphamcs@gmail.com
Link: https://lkml.kernel.org/r/20231207192406.3809579-1-nphamcs@gmail.com
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: David Heidelberg <david@ixit.cz>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-12-07 19:24:06 +00:00
|
|
|
|
|
|
|
When this is set to 0, all swapping attempts to swapping devices
|
|
|
|
are disabled. This included both zswap writebacks, and swapping due
|
|
|
|
to zswap store failures. If the zswap store failures are recurring
|
|
|
|
(for e.g if the pages are incompressible), users can observe
|
|
|
|
reclaim inefficiency after disabling writeback (because the same
|
|
|
|
pages might be rejected again and again).
|
|
|
|
|
|
|
|
Note that this is subtly different from setting memory.swap.max to
|
|
|
|
0, as it still allows for pages to be written to the zswap pool.
|
2024-08-23 16:27:11 +00:00
|
|
|
This setting has no effect if zswap is disabled, and swapping
|
|
|
|
is allowed unless memory.swap.max is set to 0.
|
zswap: memcontrol: implement zswap writeback disabling
During our experiment with zswap, we sometimes observe swap IOs due to
occasional zswap store failures and writebacks-to-swap. These swapping
IOs prevent many users who cannot tolerate swapping from adopting zswap to
save memory and improve performance where possible.
This patch adds the option to disable this behavior entirely: do not
writeback to backing swapping device when a zswap store attempt fail, and
do not write pages in the zswap pool back to the backing swap device (both
when the pool is full, and when the new zswap shrinker is called).
This new behavior can be opted-in/out on a per-cgroup basis via a new
cgroup file. By default, writebacks to swap device is enabled, which is
the previous behavior. Initially, writeback is enabled for the root
cgroup, and a newly created cgroup will inherit the current setting of its
parent.
Note that this is subtly different from setting memory.swap.max to 0, as
it still allows for pages to be stored in the zswap pool (which itself
consumes swap space in its current form).
This patch should be applied on top of the zswap shrinker series:
https://lore.kernel.org/linux-mm/20231130194023.4102148-1-nphamcs@gmail.com/
as it also disables the zswap shrinker, a major source of zswap
writebacks.
For the most part, this feature is motivated by internal parties who
have already established their opinions regarding swapping - the
workloads that are highly sensitive to IO, and especially those who are
using servers with really slow disk performance (for instance, massive
but slow HDDs). For these folks, it's impossible to convince them to
even entertain zswap if swapping also comes as a packaged deal.
Writeback disabling is quite a useful feature in these situations - on
a mixed workloads deployment, they can disable writeback for the more
IO-sensitive workloads, and enable writeback for other background
workloads.
For instance, on a server with HDD, I allocate memories and populate
them with random values (so that zswap store will always fail), and
specify memory.high low enough to trigger reclaim. The time it takes
to allocate the memories and just read through it a couple of times
(doing silly things like computing the values' average etc.):
zswap.writeback disabled:
real 0m30.537s
user 0m23.687s
sys 0m6.637s
0 pages swapped in
0 pages swapped out
zswap.writeback enabled:
real 0m45.061s
user 0m24.310s
sys 0m8.892s
712686 pages swapped in
461093 pages swapped out
(the last two lines are from vmstat -s).
[nphamcs@gmail.com: add a comment about recurring zswap store failures leading to reclaim inefficiency]
Link: https://lkml.kernel.org/r/20231221005725.3446672-1-nphamcs@gmail.com
Link: https://lkml.kernel.org/r/20231207192406.3809579-1-nphamcs@gmail.com
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: David Heidelberg <david@ixit.cz>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-12-07 19:24:06 +00:00
|
|
|
|
2018-10-26 22:06:31 +00:00
|
|
|
memory.pressure
|
2021-01-16 17:36:34 +00:00
|
|
|
A read-only nested-keyed file.
|
2018-10-26 22:06:31 +00:00
|
|
|
|
|
|
|
Shows pressure stall information for memory. See
|
2020-02-28 00:06:53 +00:00
|
|
|
:ref:`Documentation/accounting/psi.rst <psi>` for details.
|
2018-10-26 22:06:31 +00:00
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Usage Guidelines
|
|
|
|
~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
"memory.high" is the main mechanism to control memory usage.
|
|
|
|
Over-committing on high limit (sum of high limits > available memory)
|
|
|
|
and letting global memory pressure to distribute memory according to
|
|
|
|
usage is a viable strategy.
|
|
|
|
|
|
|
|
Because breach of the high limit doesn't trigger the OOM killer but
|
|
|
|
throttles the offending cgroup, a management agent has ample
|
|
|
|
opportunities to monitor and take appropriate actions such as granting
|
|
|
|
more memory or terminating the workload.
|
|
|
|
|
|
|
|
Determining whether a cgroup has enough memory is not trivial as
|
|
|
|
memory usage doesn't indicate whether the workload can benefit from
|
|
|
|
more memory. For example, a workload which writes data received from
|
|
|
|
network to a file can use all available memory but can also operate as
|
|
|
|
performant with a small amount of memory. A measure of memory
|
|
|
|
pressure - how much the workload is being impacted due to lack of
|
|
|
|
memory - is necessary to determine whether a workload needs more
|
|
|
|
memory; unfortunately, memory pressure monitoring mechanism isn't
|
|
|
|
implemented yet.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Memory Ownership
|
|
|
|
~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A memory area is charged to the cgroup which instantiated it and stays
|
|
|
|
charged to the cgroup until the area is released. Migrating a process
|
|
|
|
to a different cgroup doesn't move the memory usages that it
|
|
|
|
instantiated while in the previous cgroup to the new cgroup.
|
|
|
|
|
|
|
|
A memory area may be used by processes belonging to different cgroups.
|
|
|
|
To which cgroup the area will be charged is in-deterministic; however,
|
|
|
|
over time, the memory area is likely to end up in a cgroup which has
|
|
|
|
enough memory allowance to avoid high reclaim pressure.
|
|
|
|
|
|
|
|
If a cgroup sweeps a considerable amount of memory which is expected
|
|
|
|
to be accessed repeatedly by other cgroups, it may make sense to use
|
|
|
|
POSIX_FADV_DONTNEED to relinquish the ownership of memory areas
|
|
|
|
belonging to the affected files to ensure correct memory ownership.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
IO
|
|
|
|
--
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
The "io" controller regulates the distribution of IO resources. This
|
|
|
|
controller implements both weight based and absolute bandwidth or IOPS
|
|
|
|
limit distribution; however, weight based distribution is available
|
|
|
|
only if cfq-iosched is in use and neither scheme is available for
|
|
|
|
blk-mq devices.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
IO Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
io.stat
|
2020-06-01 20:12:05 +00:00
|
|
|
A read-only nested-keyed file.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Lines are keyed by $MAJ:$MIN device numbers and not ordered.
|
|
|
|
The following nested keys are defined.
|
|
|
|
|
2018-07-18 11:47:41 +00:00
|
|
|
====== =====================
|
2015-11-16 16:13:34 +00:00
|
|
|
rbytes Bytes read
|
|
|
|
wbytes Bytes written
|
|
|
|
rios Number of read IOs
|
|
|
|
wios Number of write IOs
|
2018-07-18 11:47:41 +00:00
|
|
|
dbytes Bytes discarded
|
|
|
|
dios Number of discard IOs
|
|
|
|
====== =====================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2020-02-28 00:06:51 +00:00
|
|
|
An example read output follows::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2018-07-18 11:47:41 +00:00
|
|
|
8:16 rbytes=1459200 wbytes=314773504 rios=192 wios=353 dbytes=0 dios=0
|
|
|
|
8:0 rbytes=90430464 wbytes=299008000 rios=8950 wios=1252 dbytes=50331648 dios=3021
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2019-08-28 22:05:58 +00:00
|
|
|
io.cost.qos
|
2021-01-07 14:11:18 +00:00
|
|
|
A read-write nested-keyed file which exists only on the root
|
2019-08-28 22:05:58 +00:00
|
|
|
cgroup.
|
|
|
|
|
|
|
|
This file configures the Quality of Service of the IO cost
|
|
|
|
model based controller (CONFIG_BLK_CGROUP_IOCOST) which
|
|
|
|
currently implements "io.weight" proportional control. Lines
|
|
|
|
are keyed by $MAJ:$MIN device numbers and not ordered. The
|
|
|
|
line for a given device is populated on the first write for
|
|
|
|
the device on "io.cost.qos" or "io.cost.model". The following
|
|
|
|
nested keys are defined.
|
|
|
|
|
|
|
|
====== =====================================
|
|
|
|
enable Weight-based control enable
|
|
|
|
ctrl "auto" or "user"
|
|
|
|
rpct Read latency percentile [0, 100]
|
|
|
|
rlat Read latency threshold
|
|
|
|
wpct Write latency percentile [0, 100]
|
|
|
|
wlat Write latency threshold
|
|
|
|
min Minimum scaling percentage [1, 10000]
|
|
|
|
max Maximum scaling percentage [1, 10000]
|
|
|
|
====== =====================================
|
|
|
|
|
|
|
|
The controller is disabled by default and can be enabled by
|
|
|
|
setting "enable" to 1. "rpct" and "wpct" parameters default
|
|
|
|
to zero and the controller uses internal device saturation
|
|
|
|
state to adjust the overall IO rate between "min" and "max".
|
|
|
|
|
|
|
|
When a better control quality is needed, latency QoS
|
|
|
|
parameters can be configured. For example::
|
|
|
|
|
|
|
|
8:16 enable=1 ctrl=auto rpct=95.00 rlat=75000 wpct=95.00 wlat=150000 min=50.00 max=150.0
|
|
|
|
|
|
|
|
shows that on sdb, the controller is enabled, will consider
|
|
|
|
the device saturated if the 95th percentile of read completion
|
|
|
|
latencies is above 75ms or write 150ms, and adjust the overall
|
|
|
|
IO issue rate between 50% and 150% accordingly.
|
|
|
|
|
|
|
|
The lower the saturation point, the better the latency QoS at
|
|
|
|
the cost of aggregate bandwidth. The narrower the allowed
|
|
|
|
adjustment range between "min" and "max", the more conformant
|
|
|
|
to the cost model the IO behavior. Note that the IO issue
|
|
|
|
base rate may be far off from 100% and setting "min" and "max"
|
|
|
|
blindly can lead to a significant loss of device capacity or
|
|
|
|
control quality. "min" and "max" are useful for regulating
|
|
|
|
devices which show wide temporary behavior changes - e.g. a
|
|
|
|
ssd which accepts writes at the line speed for a while and
|
|
|
|
then completely stalls for multiple seconds.
|
|
|
|
|
|
|
|
When "ctrl" is "auto", the parameters are controlled by the
|
|
|
|
kernel and may change automatically. Setting "ctrl" to "user"
|
|
|
|
or setting any of the percentile and latency parameters puts
|
|
|
|
it into "user" mode and disables the automatic changes. The
|
|
|
|
automatic mode can be restored by setting "ctrl" to "auto".
|
|
|
|
|
|
|
|
io.cost.model
|
2021-01-07 14:11:18 +00:00
|
|
|
A read-write nested-keyed file which exists only on the root
|
2019-08-28 22:05:58 +00:00
|
|
|
cgroup.
|
|
|
|
|
|
|
|
This file configures the cost model of the IO cost model based
|
|
|
|
controller (CONFIG_BLK_CGROUP_IOCOST) which currently
|
|
|
|
implements "io.weight" proportional control. Lines are keyed
|
|
|
|
by $MAJ:$MIN device numbers and not ordered. The line for a
|
|
|
|
given device is populated on the first write for the device on
|
|
|
|
"io.cost.qos" or "io.cost.model". The following nested keys
|
|
|
|
are defined.
|
|
|
|
|
|
|
|
===== ================================
|
|
|
|
ctrl "auto" or "user"
|
|
|
|
model The cost model in use - "linear"
|
|
|
|
===== ================================
|
|
|
|
|
|
|
|
When "ctrl" is "auto", the kernel may change all parameters
|
|
|
|
dynamically. When "ctrl" is set to "user" or any other
|
|
|
|
parameters are written to, "ctrl" become "user" and the
|
|
|
|
automatic changes are disabled.
|
|
|
|
|
|
|
|
When "model" is "linear", the following model parameters are
|
|
|
|
defined.
|
|
|
|
|
|
|
|
============= ========================================
|
|
|
|
[r|w]bps The maximum sequential IO throughput
|
|
|
|
[r|w]seqiops The maximum 4k sequential IOs per second
|
|
|
|
[r|w]randiops The maximum 4k random IOs per second
|
|
|
|
============= ========================================
|
|
|
|
|
|
|
|
From the above, the builtin linear model determines the base
|
|
|
|
costs of a sequential and random IO and the cost coefficient
|
|
|
|
for the IO size. While simple, this model can cover most
|
|
|
|
common device classes acceptably.
|
|
|
|
|
|
|
|
The IO cost model isn't expected to be accurate in absolute
|
|
|
|
sense and is scaled to the device behavior dynamically.
|
|
|
|
|
2019-08-28 22:06:00 +00:00
|
|
|
If needed, tools/cgroup/iocost_coef_gen.py can be used to
|
|
|
|
generate device-specific coefficients.
|
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
io.weight
|
|
|
|
A read-write flat-keyed file which exists on non-root cgroups.
|
|
|
|
The default is "default 100".
|
|
|
|
|
|
|
|
The first line is the default weight applied to devices
|
|
|
|
without specific override. The rest are overrides keyed by
|
|
|
|
$MAJ:$MIN device numbers and not ordered. The weights are in
|
|
|
|
the range [1, 10000] and specifies the relative amount IO time
|
|
|
|
the cgroup can use in relation to its siblings.
|
|
|
|
|
|
|
|
The default weight can be updated by writing either "default
|
|
|
|
$WEIGHT" or simply "$WEIGHT". Overrides can be set by writing
|
|
|
|
"$MAJ:$MIN $WEIGHT" and unset by writing "$MAJ:$MIN default".
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
An example read output follows::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
default 100
|
|
|
|
8:16 200
|
|
|
|
8:0 50
|
|
|
|
|
|
|
|
io.max
|
|
|
|
A read-write nested-keyed file which exists on non-root
|
|
|
|
cgroups.
|
|
|
|
|
|
|
|
BPS and IOPS based IO limit. Lines are keyed by $MAJ:$MIN
|
|
|
|
device numbers and not ordered. The following nested keys are
|
|
|
|
defined.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
===== ==================================
|
2015-11-16 16:13:34 +00:00
|
|
|
rbps Max read bytes per second
|
|
|
|
wbps Max write bytes per second
|
|
|
|
riops Max read IO operations per second
|
|
|
|
wiops Max write IO operations per second
|
2017-05-14 11:48:40 +00:00
|
|
|
===== ==================================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
When writing, any number of nested key-value pairs can be
|
|
|
|
specified in any order. "max" can be specified as the value
|
|
|
|
to remove a specific limit. If the same key is specified
|
|
|
|
multiple times, the outcome is undefined.
|
|
|
|
|
|
|
|
BPS and IOPS are measured in each IO direction and IOs are
|
|
|
|
delayed if limit is reached. Temporary bursts are allowed.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Setting read limit at 2M BPS and write at 120 IOPS for 8:16::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
echo "8:16 rbps=2097152 wiops=120" > io.max
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Reading returns the following::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
8:16 rbps=2097152 wbps=max riops=max wiops=120
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Write IOPS limit can be removed by writing the following::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
echo "8:16 wiops=max" > io.max
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Reading now returns the following::
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
8:16 rbps=2097152 wbps=max riops=max wiops=max
|
|
|
|
|
2018-10-26 22:06:31 +00:00
|
|
|
io.pressure
|
2021-01-16 17:36:34 +00:00
|
|
|
A read-only nested-keyed file.
|
2018-10-26 22:06:31 +00:00
|
|
|
|
|
|
|
Shows pressure stall information for IO. See
|
2020-02-28 00:06:53 +00:00
|
|
|
:ref:`Documentation/accounting/psi.rst <psi>` for details.
|
2018-10-26 22:06:31 +00:00
|
|
|
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Writeback
|
|
|
|
~~~~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
Page cache is dirtied through buffered writes and shared mmaps and
|
|
|
|
written asynchronously to the backing filesystem by the writeback
|
|
|
|
mechanism. Writeback sits between the memory and IO domains and
|
|
|
|
regulates the proportion of dirty memory by balancing dirtying and
|
|
|
|
write IOs.
|
|
|
|
|
|
|
|
The io controller, in conjunction with the memory controller,
|
|
|
|
implements control of page cache writeback IOs. The memory controller
|
|
|
|
defines the memory domain that dirty memory ratio is calculated and
|
|
|
|
maintained for and the io controller defines the io domain which
|
|
|
|
writes out dirty pages for the memory domain. Both system-wide and
|
|
|
|
per-cgroup dirty memory states are examined and the more restrictive
|
|
|
|
of the two is enforced.
|
|
|
|
|
|
|
|
cgroup writeback requires explicit support from the underlying
|
2020-06-29 19:08:09 +00:00
|
|
|
filesystem. Currently, cgroup writeback is implemented on ext2, ext4,
|
|
|
|
btrfs, f2fs, and xfs. On other filesystems, all writeback IOs are
|
|
|
|
attributed to the root cgroup.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
There are inherent differences in memory and writeback management
|
|
|
|
which affects how cgroup ownership is tracked. Memory is tracked per
|
|
|
|
page while writeback per inode. For the purpose of writeback, an
|
|
|
|
inode is assigned to a cgroup and all IO requests to write dirty pages
|
|
|
|
from the inode are attributed to that cgroup.
|
|
|
|
|
|
|
|
As cgroup ownership for memory is tracked per page, there can be pages
|
|
|
|
which are associated with different cgroups than the one the inode is
|
|
|
|
associated with. These are called foreign pages. The writeback
|
|
|
|
constantly keeps track of foreign pages and, if a particular foreign
|
|
|
|
cgroup becomes the majority over a certain period of time, switches
|
|
|
|
the ownership of the inode to that cgroup.
|
|
|
|
|
|
|
|
While this model is enough for most use cases where a given inode is
|
|
|
|
mostly dirtied by a single cgroup even when the main writing cgroup
|
|
|
|
changes over time, use cases where multiple cgroups write to a single
|
|
|
|
inode simultaneously are not supported well. In such circumstances, a
|
|
|
|
significant portion of IOs are likely to be attributed incorrectly.
|
|
|
|
As memory controller assigns page ownership on the first use and
|
|
|
|
doesn't update it until the page is released, even if writeback
|
|
|
|
strictly follows page ownership, multiple cgroups dirtying overlapping
|
|
|
|
areas wouldn't work as expected. It's recommended to avoid such usage
|
|
|
|
patterns.
|
|
|
|
|
|
|
|
The sysctl knobs which affect writeback behavior are applied to cgroup
|
|
|
|
writeback as follows.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
vm.dirty_background_ratio, vm.dirty_ratio
|
2015-11-16 16:13:34 +00:00
|
|
|
These ratios apply the same to cgroup writeback with the
|
|
|
|
amount of available memory capped by limits imposed by the
|
|
|
|
memory controller and system-wide clean memory.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
vm.dirty_background_bytes, vm.dirty_bytes
|
2015-11-16 16:13:34 +00:00
|
|
|
For cgroup writeback, this is calculated into ratio against
|
|
|
|
total available memory and applied the same way as
|
|
|
|
vm.dirty[_background]_ratio.
|
|
|
|
|
|
|
|
|
2018-07-03 15:15:02 +00:00
|
|
|
IO Latency
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
This is a cgroup v2 controller for IO workload protection. You provide a group
|
|
|
|
with a latency target, and if the average latency exceeds that target the
|
|
|
|
controller will throttle any peers that have a lower latency target than the
|
|
|
|
protected workload.
|
|
|
|
|
|
|
|
The limits are only applied at the peer level in the hierarchy. This means that
|
|
|
|
in the diagram below, only groups A, B, and C will influence each other, and
|
2019-02-07 00:59:00 +00:00
|
|
|
groups D and F will influence each other. Group G will influence nobody::
|
2018-07-03 15:15:02 +00:00
|
|
|
|
|
|
|
[root]
|
|
|
|
/ | \
|
|
|
|
A B C
|
|
|
|
/ \ |
|
|
|
|
D F G
|
|
|
|
|
|
|
|
|
|
|
|
So the ideal way to configure this is to set io.latency in groups A, B, and C.
|
|
|
|
Generally you do not want to set a value lower than the latency your device
|
|
|
|
supports. Experiment to find the value that works best for your workload.
|
|
|
|
Start at higher than the expected latency for your device and watch the
|
2018-08-02 06:15:41 +00:00
|
|
|
avg_lat value in io.stat for your workload group to get an idea of the
|
|
|
|
latency you see during normal operation. Use the avg_lat value as a basis for
|
|
|
|
your real setting, setting at 10-15% higher than the value in io.stat.
|
2018-07-03 15:15:02 +00:00
|
|
|
|
|
|
|
How IO Latency Throttling Works
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
io.latency is work conserving; so as long as everybody is meeting their latency
|
|
|
|
target the controller doesn't do anything. Once a group starts missing its
|
|
|
|
target it begins throttling any peer group that has a higher target than itself.
|
|
|
|
This throttling takes 2 forms:
|
|
|
|
|
|
|
|
- Queue depth throttling. This is the number of outstanding IO's a group is
|
|
|
|
allowed to have. We will clamp down relatively quickly, starting at no limit
|
|
|
|
and going all the way down to 1 IO at a time.
|
|
|
|
|
|
|
|
- Artificial delay induction. There are certain types of IO that cannot be
|
|
|
|
throttled without possibly adversely affecting higher priority groups. This
|
|
|
|
includes swapping and metadata IO. These types of IO are allowed to occur
|
|
|
|
normally, however they are "charged" to the originating group. If the
|
|
|
|
originating group is being throttled you will see the use_delay and delay
|
|
|
|
fields in io.stat increase. The delay value is how many microseconds that are
|
|
|
|
being added to any process that runs in this group. Because this number can
|
|
|
|
grow quite large if there is a lot of swapping or metadata IO occurring we
|
|
|
|
limit the individual delay events to 1 second at a time.
|
|
|
|
|
|
|
|
Once the victimized group starts meeting its latency target again it will start
|
|
|
|
unthrottling any peer groups that were throttled previously. If the victimized
|
|
|
|
group simply stops doing IO the global counter will unthrottle appropriately.
|
|
|
|
|
|
|
|
IO Latency Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
io.latency
|
|
|
|
This takes a similar format as the other controllers.
|
|
|
|
|
2022-04-22 16:45:26 +00:00
|
|
|
"MAJOR:MINOR target=<target time in microseconds>"
|
2018-07-03 15:15:02 +00:00
|
|
|
|
|
|
|
io.stat
|
|
|
|
If the controller is enabled you will see extra stats in io.stat in
|
|
|
|
addition to the normal ones.
|
|
|
|
|
|
|
|
depth
|
|
|
|
This is the current queue depth for the group.
|
|
|
|
|
|
|
|
avg_lat
|
2018-08-02 06:15:41 +00:00
|
|
|
This is an exponential moving average with a decay rate of 1/exp
|
|
|
|
bound by the sampling interval. The decay rate interval can be
|
|
|
|
calculated by multiplying the win value in io.stat by the
|
|
|
|
corresponding number of samples based on the win value.
|
|
|
|
|
|
|
|
win
|
|
|
|
The sampling window size in milliseconds. This is the minimum
|
|
|
|
duration of time between evaluation events. Windows only elapse
|
|
|
|
with IO activity. Idle periods extend the most recent window.
|
2018-07-03 15:15:02 +00:00
|
|
|
|
2021-06-18 00:44:44 +00:00
|
|
|
IO Priority
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
A single attribute controls the behavior of the I/O priority cgroup policy,
|
2023-10-12 02:42:28 +00:00
|
|
|
namely the io.prio.class attribute. The following values are accepted for
|
2021-06-18 00:44:44 +00:00
|
|
|
that attribute:
|
|
|
|
|
|
|
|
no-change
|
|
|
|
Do not modify the I/O priority class.
|
|
|
|
|
2023-04-28 07:44:04 +00:00
|
|
|
promote-to-rt
|
|
|
|
For requests that have a non-RT I/O priority class, change it into RT.
|
|
|
|
Also change the priority level of these requests to 4. Do not modify
|
|
|
|
the I/O priority of requests that have priority class RT.
|
2021-06-18 00:44:44 +00:00
|
|
|
|
|
|
|
restrict-to-be
|
|
|
|
For requests that do not have an I/O priority class or that have I/O
|
2023-04-28 07:44:04 +00:00
|
|
|
priority class RT, change it into BE. Also change the priority level
|
|
|
|
of these requests to 0. Do not modify the I/O priority class of
|
|
|
|
requests that have priority class IDLE.
|
2021-06-18 00:44:44 +00:00
|
|
|
|
|
|
|
idle
|
|
|
|
Change the I/O priority class of all requests into IDLE, the lowest
|
|
|
|
I/O priority class.
|
|
|
|
|
2023-04-28 07:44:04 +00:00
|
|
|
none-to-rt
|
|
|
|
Deprecated. Just an alias for promote-to-rt.
|
|
|
|
|
2021-06-18 00:44:44 +00:00
|
|
|
The following numerical values are associated with the I/O priority policies:
|
|
|
|
|
2023-04-28 07:44:04 +00:00
|
|
|
+----------------+---+
|
|
|
|
| no-change | 0 |
|
|
|
|
+----------------+---+
|
2023-10-12 02:42:28 +00:00
|
|
|
| promote-to-rt | 1 |
|
2023-04-28 07:44:04 +00:00
|
|
|
+----------------+---+
|
2023-10-12 02:42:28 +00:00
|
|
|
| restrict-to-be | 2 |
|
|
|
|
+----------------+---+
|
|
|
|
| idle | 3 |
|
2023-04-28 07:44:04 +00:00
|
|
|
+----------------+---+
|
2021-06-18 00:44:44 +00:00
|
|
|
|
|
|
|
The numerical value that corresponds to each I/O priority class is as follows:
|
|
|
|
|
|
|
|
+-------------------------------+---+
|
|
|
|
| IOPRIO_CLASS_NONE | 0 |
|
|
|
|
+-------------------------------+---+
|
|
|
|
| IOPRIO_CLASS_RT (real-time) | 1 |
|
|
|
|
+-------------------------------+---+
|
|
|
|
| IOPRIO_CLASS_BE (best effort) | 2 |
|
|
|
|
+-------------------------------+---+
|
|
|
|
| IOPRIO_CLASS_IDLE | 3 |
|
|
|
|
+-------------------------------+---+
|
|
|
|
|
|
|
|
The algorithm to set the I/O priority class for a request is as follows:
|
|
|
|
|
2023-04-28 07:44:04 +00:00
|
|
|
- If I/O priority class policy is promote-to-rt, change the request I/O
|
|
|
|
priority class to IOPRIO_CLASS_RT and change the request I/O priority
|
|
|
|
level to 4.
|
2023-10-12 02:42:28 +00:00
|
|
|
- If I/O priority class policy is not promote-to-rt, translate the I/O priority
|
2023-04-28 07:44:04 +00:00
|
|
|
class policy into a number, then change the request I/O priority class
|
|
|
|
into the maximum of the I/O priority class policy number and the numerical
|
|
|
|
I/O priority class.
|
2021-06-18 00:44:44 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
PID
|
|
|
|
---
|
2017-01-10 17:42:34 +00:00
|
|
|
|
|
|
|
The process number controller is used to allow a cgroup to stop any
|
|
|
|
new tasks from being fork()'d or clone()'d after a specified limit is
|
|
|
|
reached.
|
|
|
|
|
|
|
|
The number of tasks in a cgroup can be exhausted in ways which other
|
|
|
|
controllers cannot prevent, thus warranting its own controller. For
|
|
|
|
example, a fork bomb is likely to exhaust the number of tasks before
|
|
|
|
hitting memory restrictions.
|
|
|
|
|
|
|
|
Note that PIDs used in this controller refer to TIDs, process IDs as
|
|
|
|
used by the kernel.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
PID Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2017-01-10 17:42:34 +00:00
|
|
|
|
|
|
|
pids.max
|
2017-02-17 17:44:11 +00:00
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cgroups. The default is "max".
|
2017-01-10 17:42:34 +00:00
|
|
|
|
2017-02-17 17:44:11 +00:00
|
|
|
Hard limit of number of processes.
|
2017-01-10 17:42:34 +00:00
|
|
|
|
|
|
|
pids.current
|
2024-04-18 12:30:12 +00:00
|
|
|
A read-only single value file which exists on non-root cgroups.
|
2017-01-10 17:42:34 +00:00
|
|
|
|
2017-02-17 17:44:11 +00:00
|
|
|
The number of processes currently in the cgroup and its
|
|
|
|
descendants.
|
2017-01-10 17:42:34 +00:00
|
|
|
|
2024-04-18 12:30:12 +00:00
|
|
|
pids.peak
|
|
|
|
A read-only single value file which exists on non-root cgroups.
|
|
|
|
|
|
|
|
The maximum value that the number of processes in the cgroup and its
|
|
|
|
descendants has ever reached.
|
|
|
|
|
|
|
|
pids.events
|
2024-05-21 09:21:26 +00:00
|
|
|
A read-only flat-keyed file which exists on non-root cgroups. Unless
|
|
|
|
specified otherwise, a value change in this file generates a file
|
|
|
|
modified event. The following entries are defined.
|
2024-04-18 12:30:12 +00:00
|
|
|
|
|
|
|
max
|
2024-05-21 09:21:27 +00:00
|
|
|
The number of times the cgroup's total number of processes hit the pids.max
|
2024-05-21 09:21:26 +00:00
|
|
|
limit (see also pids_localevents).
|
2024-04-18 12:30:12 +00:00
|
|
|
|
2024-05-21 09:21:28 +00:00
|
|
|
pids.events.local
|
|
|
|
Similar to pids.events but the fields in the file are local
|
|
|
|
to the cgroup i.e. not hierarchical. The file modified event
|
|
|
|
generated on this file reflects only the local events.
|
|
|
|
|
2017-01-10 17:42:34 +00:00
|
|
|
Organisational operations are not blocked by cgroup policies, so it is
|
|
|
|
possible to have pids.current > pids.max. This can be done by either
|
|
|
|
setting the limit to be smaller than pids.current, or attaching enough
|
|
|
|
processes to the cgroup such that pids.current is larger than
|
|
|
|
pids.max. However, it is not possible to violate a cgroup PID policy
|
|
|
|
through fork() or clone(). These will return -EAGAIN if the creation
|
|
|
|
of a new process would cause a cgroup policy to be violated.
|
|
|
|
|
|
|
|
|
2018-11-08 15:08:35 +00:00
|
|
|
Cpuset
|
|
|
|
------
|
|
|
|
|
|
|
|
The "cpuset" controller provides a mechanism for constraining
|
|
|
|
the CPU and memory node placement of tasks to only the resources
|
|
|
|
specified in the cpuset interface files in a task's current cgroup.
|
|
|
|
This is especially valuable on large NUMA systems where placing jobs
|
|
|
|
on properly sized subsets of the systems with careful processor and
|
|
|
|
memory placement to reduce cross-node memory access and contention
|
|
|
|
can improve overall system performance.
|
|
|
|
|
|
|
|
The "cpuset" controller is hierarchical. That means the controller
|
|
|
|
cannot use CPUs or memory nodes not allowed in its parent.
|
|
|
|
|
|
|
|
|
|
|
|
Cpuset Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
cpuset.cpus
|
|
|
|
A read-write multiple values file which exists on non-root
|
|
|
|
cpuset-enabled cgroups.
|
|
|
|
|
|
|
|
It lists the requested CPUs to be used by tasks within this
|
|
|
|
cgroup. The actual list of CPUs to be granted, however, is
|
|
|
|
subjected to constraints imposed by its parent and can differ
|
|
|
|
from the requested CPUs.
|
|
|
|
|
|
|
|
The CPU numbers are comma-separated numbers or ranges.
|
2020-02-28 00:06:52 +00:00
|
|
|
For example::
|
2018-11-08 15:08:35 +00:00
|
|
|
|
|
|
|
# cat cpuset.cpus
|
|
|
|
0-4,6,8-10
|
|
|
|
|
|
|
|
An empty value indicates that the cgroup is using the same
|
|
|
|
setting as the nearest cgroup ancestor with a non-empty
|
|
|
|
"cpuset.cpus" or all the available CPUs if none is found.
|
|
|
|
|
|
|
|
The value of "cpuset.cpus" stays constant until the next update
|
|
|
|
and won't be affected by any CPU hotplug events.
|
|
|
|
|
|
|
|
cpuset.cpus.effective
|
2018-11-08 15:08:43 +00:00
|
|
|
A read-only multiple values file which exists on all
|
2018-11-08 15:08:35 +00:00
|
|
|
cpuset-enabled cgroups.
|
|
|
|
|
|
|
|
It lists the onlined CPUs that are actually granted to this
|
|
|
|
cgroup by its parent. These CPUs are allowed to be used by
|
|
|
|
tasks within the current cgroup.
|
|
|
|
|
|
|
|
If "cpuset.cpus" is empty, the "cpuset.cpus.effective" file shows
|
|
|
|
all the CPUs from the parent cgroup that can be available to
|
|
|
|
be used by this cgroup. Otherwise, it should be a subset of
|
|
|
|
"cpuset.cpus" unless none of the CPUs listed in "cpuset.cpus"
|
|
|
|
can be granted. In this case, it will be treated just like an
|
|
|
|
empty "cpuset.cpus".
|
|
|
|
|
|
|
|
Its value will be affected by CPU hotplug events.
|
|
|
|
|
|
|
|
cpuset.mems
|
|
|
|
A read-write multiple values file which exists on non-root
|
|
|
|
cpuset-enabled cgroups.
|
|
|
|
|
|
|
|
It lists the requested memory nodes to be used by tasks within
|
|
|
|
this cgroup. The actual list of memory nodes granted, however,
|
|
|
|
is subjected to constraints imposed by its parent and can differ
|
|
|
|
from the requested memory nodes.
|
|
|
|
|
|
|
|
The memory node numbers are comma-separated numbers or ranges.
|
2020-02-28 00:06:52 +00:00
|
|
|
For example::
|
2018-11-08 15:08:35 +00:00
|
|
|
|
|
|
|
# cat cpuset.mems
|
|
|
|
0-1,3
|
|
|
|
|
|
|
|
An empty value indicates that the cgroup is using the same
|
|
|
|
setting as the nearest cgroup ancestor with a non-empty
|
|
|
|
"cpuset.mems" or all the available memory nodes if none
|
|
|
|
is found.
|
|
|
|
|
|
|
|
The value of "cpuset.mems" stays constant until the next update
|
|
|
|
and won't be affected by any memory nodes hotplug events.
|
|
|
|
|
2021-08-11 19:57:07 +00:00
|
|
|
Setting a non-empty value to "cpuset.mems" causes memory of
|
|
|
|
tasks within the cgroup to be migrated to the designated nodes if
|
|
|
|
they are currently using memory outside of the designated nodes.
|
|
|
|
|
|
|
|
There is a cost for this memory migration. The migration
|
|
|
|
may not be complete and some memory pages may be left behind.
|
|
|
|
So it is recommended that "cpuset.mems" should be set properly
|
|
|
|
before spawning new tasks into the cpuset. Even if there is
|
|
|
|
a need to change "cpuset.mems" with active tasks, it shouldn't
|
|
|
|
be done frequently.
|
|
|
|
|
2018-11-08 15:08:35 +00:00
|
|
|
cpuset.mems.effective
|
2018-11-08 15:08:43 +00:00
|
|
|
A read-only multiple values file which exists on all
|
2018-11-08 15:08:35 +00:00
|
|
|
cpuset-enabled cgroups.
|
|
|
|
|
|
|
|
It lists the onlined memory nodes that are actually granted to
|
|
|
|
this cgroup by its parent. These memory nodes are allowed to
|
|
|
|
be used by tasks within the current cgroup.
|
|
|
|
|
|
|
|
If "cpuset.mems" is empty, it shows all the memory nodes from the
|
|
|
|
parent cgroup that will be available to be used by this cgroup.
|
|
|
|
Otherwise, it should be a subset of "cpuset.mems" unless none of
|
|
|
|
the memory nodes listed in "cpuset.mems" can be granted. In this
|
|
|
|
case, it will be treated just like an empty "cpuset.mems".
|
|
|
|
|
|
|
|
Its value will be affected by memory nodes hotplug events.
|
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
cpuset.cpus.exclusive
|
|
|
|
A read-write multiple values file which exists on non-root
|
|
|
|
cpuset-enabled cgroups.
|
|
|
|
|
|
|
|
It lists all the exclusive CPUs that are allowed to be used
|
|
|
|
to create a new cpuset partition. Its value is not used
|
|
|
|
unless the cgroup becomes a valid partition root. See the
|
|
|
|
"cpuset.cpus.partition" section below for a description of what
|
|
|
|
a cpuset partition is.
|
|
|
|
|
|
|
|
When the cgroup becomes a partition root, the actual exclusive
|
|
|
|
CPUs that are allocated to that partition are listed in
|
|
|
|
"cpuset.cpus.exclusive.effective" which may be different
|
|
|
|
from "cpuset.cpus.exclusive". If "cpuset.cpus.exclusive"
|
|
|
|
has previously been set, "cpuset.cpus.exclusive.effective"
|
|
|
|
is always a subset of it.
|
|
|
|
|
|
|
|
Users can manually set it to a value that is different from
|
2024-06-17 14:39:43 +00:00
|
|
|
"cpuset.cpus". One constraint in setting it is that the list of
|
|
|
|
CPUs must be exclusive with respect to "cpuset.cpus.exclusive"
|
|
|
|
of its sibling. If "cpuset.cpus.exclusive" of a sibling cgroup
|
|
|
|
isn't set, its "cpuset.cpus" value, if set, cannot be a subset
|
|
|
|
of it to leave at least one CPU available when the exclusive
|
|
|
|
CPUs are taken away.
|
2023-09-05 13:32:42 +00:00
|
|
|
|
|
|
|
For a parent cgroup, any one of its exclusive CPUs can only
|
|
|
|
be distributed to at most one of its child cgroups. Having an
|
|
|
|
exclusive CPU appearing in two or more of its child cgroups is
|
|
|
|
not allowed (the exclusivity rule). A value that violates the
|
|
|
|
exclusivity rule will be rejected with a write error.
|
|
|
|
|
|
|
|
The root cgroup is a partition root and all its available CPUs
|
|
|
|
are in its exclusive CPU set.
|
|
|
|
|
|
|
|
cpuset.cpus.exclusive.effective
|
|
|
|
A read-only multiple values file which exists on all non-root
|
|
|
|
cpuset-enabled cgroups.
|
|
|
|
|
|
|
|
This file shows the effective set of exclusive CPUs that
|
2024-06-17 14:39:44 +00:00
|
|
|
can be used to create a partition root. The content
|
|
|
|
of this file will always be a subset of its parent's
|
2023-09-05 13:32:42 +00:00
|
|
|
"cpuset.cpus.exclusive.effective" if its parent is not the root
|
|
|
|
cgroup. It will also be a subset of "cpuset.cpus.exclusive"
|
|
|
|
if it is set. If "cpuset.cpus.exclusive" is not set, it is
|
|
|
|
treated to have an implicit value of "cpuset.cpus" in the
|
|
|
|
formation of local partition.
|
|
|
|
|
2023-11-27 19:51:05 +00:00
|
|
|
cpuset.cpus.isolated
|
|
|
|
A read-only and root cgroup only multiple values file.
|
|
|
|
|
|
|
|
This file shows the set of all isolated CPUs used in existing
|
|
|
|
isolated partitions. It will be empty if no isolated partition
|
|
|
|
is created.
|
|
|
|
|
2018-11-13 20:03:33 +00:00
|
|
|
cpuset.cpus.partition
|
2018-11-08 15:08:45 +00:00
|
|
|
A read-write single value file which exists on non-root
|
|
|
|
cpuset-enabled cgroups. This flag is owned by the parent cgroup
|
|
|
|
and is not delegatable.
|
|
|
|
|
2021-01-20 00:18:22 +00:00
|
|
|
It accepts only the following input values when written to.
|
2018-11-08 15:08:45 +00:00
|
|
|
|
2022-09-01 20:57:44 +00:00
|
|
|
========== =====================================
|
|
|
|
"member" Non-root member of a partition
|
|
|
|
"root" Partition root
|
|
|
|
"isolated" Partition root without load balancing
|
|
|
|
========== =====================================
|
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
A cpuset partition is a collection of cpuset-enabled cgroups with
|
|
|
|
a partition root at the top of the hierarchy and its descendants
|
|
|
|
except those that are separate partition roots themselves and
|
|
|
|
their descendants. A partition has exclusive access to the
|
|
|
|
set of exclusive CPUs allocated to it. Other cgroups outside
|
|
|
|
of that partition cannot use any CPUs in that set.
|
|
|
|
|
|
|
|
There are two types of partitions - local and remote. A local
|
|
|
|
partition is one whose parent cgroup is also a valid partition
|
|
|
|
root. A remote partition is one whose parent cgroup is not a
|
|
|
|
valid partition root itself. Writing to "cpuset.cpus.exclusive"
|
|
|
|
is optional for the creation of a local partition as its
|
|
|
|
"cpuset.cpus.exclusive" file will assume an implicit value that
|
|
|
|
is the same as "cpuset.cpus" if it is not set. Writing the
|
|
|
|
proper "cpuset.cpus.exclusive" values down the cgroup hierarchy
|
|
|
|
before the target partition root is mandatory for the creation
|
|
|
|
of a remote partition.
|
|
|
|
|
|
|
|
Currently, a remote partition cannot be created under a local
|
|
|
|
partition. All the ancestors of a remote partition root except
|
|
|
|
the root cgroup cannot be a partition root.
|
|
|
|
|
|
|
|
The root cgroup is always a partition root and its state cannot
|
|
|
|
be changed. All other non-root cgroups start out as "member".
|
2022-09-01 20:57:44 +00:00
|
|
|
|
|
|
|
When set to "root", the current cgroup is the root of a new
|
2023-09-05 13:32:42 +00:00
|
|
|
partition or scheduling domain. The set of exclusive CPUs is
|
|
|
|
determined by the value of its "cpuset.cpus.exclusive.effective".
|
2022-09-01 20:57:44 +00:00
|
|
|
|
2023-10-25 18:25:55 +00:00
|
|
|
When set to "isolated", the CPUs in that partition will be in
|
|
|
|
an isolated state without any load balancing from the scheduler
|
|
|
|
and excluded from the unbound workqueues. Tasks placed in such
|
|
|
|
a partition with multiple CPUs should be carefully distributed
|
|
|
|
and bound to each of the individual CPUs for optimal performance.
|
2022-09-01 20:57:44 +00:00
|
|
|
|
|
|
|
A partition root ("root" or "isolated") can be in one of the
|
|
|
|
two possible states - valid or invalid. An invalid partition
|
|
|
|
root is in a degraded state where some state information may
|
|
|
|
be retained, but behaves more like a "member".
|
|
|
|
|
|
|
|
All possible state transitions among "member", "root" and
|
|
|
|
"isolated" are allowed.
|
|
|
|
|
|
|
|
On read, the "cpuset.cpus.partition" file can show the following
|
|
|
|
values.
|
|
|
|
|
|
|
|
============================= =====================================
|
|
|
|
"member" Non-root member of a partition
|
|
|
|
"root" Partition root
|
|
|
|
"isolated" Partition root without load balancing
|
|
|
|
"root invalid (<reason>)" Invalid partition root
|
|
|
|
"isolated invalid (<reason>)" Invalid isolated partition root
|
|
|
|
============================= =====================================
|
|
|
|
|
|
|
|
In the case of an invalid partition root, a descriptive string on
|
|
|
|
why the partition is invalid is included within parentheses.
|
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
For a local partition root to be valid, the following conditions
|
2022-09-01 20:57:44 +00:00
|
|
|
must be met.
|
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
1) The parent cgroup is a valid partition root.
|
|
|
|
2) The "cpuset.cpus.exclusive.effective" file cannot be empty,
|
|
|
|
though it may contain offline CPUs.
|
|
|
|
3) The "cpuset.cpus.effective" cannot be empty unless there is
|
2022-09-01 20:57:44 +00:00
|
|
|
no task associated with this partition.
|
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
For a remote partition root to be valid, all the above conditions
|
|
|
|
except the first one must be met.
|
2022-09-01 20:57:44 +00:00
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
External events like hotplug or changes to "cpuset.cpus" or
|
|
|
|
"cpuset.cpus.exclusive" can cause a valid partition root to
|
|
|
|
become invalid and vice versa. Note that a task cannot be
|
|
|
|
moved to a cgroup with empty "cpuset.cpus.effective".
|
2022-09-01 20:57:44 +00:00
|
|
|
|
|
|
|
A valid non-root parent partition may distribute out all its CPUs
|
2023-09-05 13:32:42 +00:00
|
|
|
to its child local partitions when there is no task associated
|
|
|
|
with it.
|
2022-09-01 20:57:44 +00:00
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
Care must be taken to change a valid partition root to "member"
|
|
|
|
as all its child local partitions, if present, will become
|
2022-09-01 20:57:44 +00:00
|
|
|
invalid causing disruption to tasks running in those child
|
|
|
|
partitions. These inactivated partitions could be recovered if
|
|
|
|
their parent is switched back to a partition root with a proper
|
2023-09-05 13:32:42 +00:00
|
|
|
value in "cpuset.cpus" or "cpuset.cpus.exclusive".
|
2022-09-01 20:57:44 +00:00
|
|
|
|
|
|
|
Poll and inotify events are triggered whenever the state of
|
|
|
|
"cpuset.cpus.partition" changes. That includes changes caused
|
|
|
|
by write to "cpuset.cpus.partition", cpu hotplug or other
|
|
|
|
changes that modify the validity status of the partition.
|
|
|
|
This will allow user space agents to monitor unexpected changes
|
|
|
|
to "cpuset.cpus.partition" without the need to do continuous
|
|
|
|
polling.
|
2018-11-08 15:08:45 +00:00
|
|
|
|
2023-09-05 13:32:42 +00:00
|
|
|
A user can pre-configure certain CPUs to an isolated state
|
|
|
|
with load balancing disabled at boot time with the "isolcpus"
|
|
|
|
kernel boot command line option. If those CPUs are to be put
|
|
|
|
into a partition, they have to be used in an isolated partition.
|
|
|
|
|
2018-11-08 15:08:35 +00:00
|
|
|
|
2017-12-13 19:49:03 +00:00
|
|
|
Device controller
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
Device controller manages access to device files. It includes both
|
|
|
|
creation of new device files (using mknod), and access to the
|
|
|
|
existing device files.
|
|
|
|
|
|
|
|
Cgroup v2 device controller has no interface files and is implemented
|
|
|
|
on top of cgroup BPF. To control access to device files, a user may
|
2021-09-08 08:08:15 +00:00
|
|
|
create bpf programs of type BPF_PROG_TYPE_CGROUP_DEVICE and attach
|
|
|
|
them to cgroups with BPF_CGROUP_DEVICE flag. On an attempt to access a
|
|
|
|
device file, corresponding BPF programs will be executed, and depending
|
|
|
|
on the return value the attempt will succeed or fail with -EPERM.
|
|
|
|
|
|
|
|
A BPF_PROG_TYPE_CGROUP_DEVICE program takes a pointer to the
|
|
|
|
bpf_cgroup_dev_ctx structure, which describes the device access attempt:
|
|
|
|
access type (mknod/read/write) and device (type, major and minor numbers).
|
|
|
|
If the program returns 0, the attempt fails with -EPERM, otherwise it
|
|
|
|
succeeds.
|
|
|
|
|
|
|
|
An example of BPF_PROG_TYPE_CGROUP_DEVICE program may be found in
|
|
|
|
tools/testing/selftests/bpf/progs/dev_cgroup.c in the kernel source tree.
|
2017-12-13 19:49:03 +00:00
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
RDMA
|
|
|
|
----
|
2017-01-29 19:35:20 +00:00
|
|
|
|
2017-01-10 00:02:15 +00:00
|
|
|
The "rdma" controller regulates the distribution and accounting of
|
2020-07-04 03:20:08 +00:00
|
|
|
RDMA resources.
|
2017-01-10 00:02:15 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
RDMA Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
2017-01-10 00:02:15 +00:00
|
|
|
|
|
|
|
rdma.max
|
|
|
|
A readwrite nested-keyed file that exists for all the cgroups
|
|
|
|
except root that describes current configured resource limit
|
|
|
|
for a RDMA/IB device.
|
|
|
|
|
|
|
|
Lines are keyed by device name and are not ordered.
|
|
|
|
Each line contains space separated resource name and its configured
|
|
|
|
limit that can be distributed.
|
|
|
|
|
|
|
|
The following nested keys are defined.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
========== =============================
|
2017-01-10 00:02:15 +00:00
|
|
|
hca_handle Maximum number of HCA Handles
|
|
|
|
hca_object Maximum number of HCA Objects
|
2017-05-14 11:48:40 +00:00
|
|
|
========== =============================
|
2017-01-10 00:02:15 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
An example for mlx4 and ocrdma device follows::
|
2017-01-10 00:02:15 +00:00
|
|
|
|
|
|
|
mlx4_0 hca_handle=2 hca_object=2000
|
|
|
|
ocrdma1 hca_handle=3 hca_object=max
|
|
|
|
|
|
|
|
rdma.current
|
|
|
|
A read-only file that describes current resource usage.
|
|
|
|
It exists for all the cgroup except root.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
An example for mlx4 and ocrdma device follows::
|
2017-01-10 00:02:15 +00:00
|
|
|
|
|
|
|
mlx4_0 hca_handle=1 hca_object=20
|
|
|
|
ocrdma1 hca_handle=1 hca_object=23
|
|
|
|
|
2019-12-16 19:38:31 +00:00
|
|
|
HugeTLB
|
|
|
|
-------
|
|
|
|
|
|
|
|
The HugeTLB controller allows to limit the HugeTLB usage per control group and
|
|
|
|
enforces the controller limit during page fault.
|
|
|
|
|
|
|
|
HugeTLB Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
hugetlb.<hugepagesize>.current
|
|
|
|
Show current usage for "hugepagesize" hugetlb. It exists for all
|
|
|
|
the cgroup except root.
|
|
|
|
|
|
|
|
hugetlb.<hugepagesize>.max
|
|
|
|
Set/show the hard limit of "hugepagesize" hugetlb usage.
|
|
|
|
The default value is "max". It exists for all the cgroup except root.
|
|
|
|
|
|
|
|
hugetlb.<hugepagesize>.events
|
|
|
|
A read-only flat-keyed file which exists on non-root cgroups.
|
|
|
|
|
|
|
|
max
|
|
|
|
The number of allocation failure due to HugeTLB limit
|
|
|
|
|
|
|
|
hugetlb.<hugepagesize>.events.local
|
|
|
|
Similar to hugetlb.<hugepagesize>.events but the fields in the file
|
|
|
|
are local to the cgroup i.e. not hierarchical. The file modified event
|
|
|
|
generated on this file reflects only the local events.
|
2017-01-10 00:02:15 +00:00
|
|
|
|
2022-01-14 22:07:48 +00:00
|
|
|
hugetlb.<hugepagesize>.numa_stat
|
|
|
|
Similar to memory.numa_stat, it shows the numa information of the
|
|
|
|
hugetlb pages of <hugepagesize> in this cgroup. Only active in
|
|
|
|
use hugetlb pages are included. The per-node values are in bytes.
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Misc
|
|
|
|
----
|
2017-02-02 18:50:35 +00:00
|
|
|
|
2021-03-30 04:42:05 +00:00
|
|
|
The Miscellaneous cgroup provides the resource limiting and tracking
|
|
|
|
mechanism for the scalar resources which cannot be abstracted like the other
|
|
|
|
cgroup resources. Controller is enabled by the CONFIG_CGROUP_MISC config
|
|
|
|
option.
|
|
|
|
|
|
|
|
A resource can be added to the controller via enum misc_res_type{} in the
|
|
|
|
include/linux/misc_cgroup.h file and the corresponding name via misc_res_name[]
|
|
|
|
in the kernel/cgroup/misc.c file. Provider of the resource must set its
|
|
|
|
capacity prior to using the resource by calling misc_cg_set_capacity().
|
|
|
|
|
|
|
|
Once a capacity is set then the resource usage can be updated using charge and
|
|
|
|
uncharge APIs. All of the APIs to interact with misc controller are in
|
|
|
|
include/linux/misc_cgroup.h.
|
|
|
|
|
|
|
|
Misc Interface Files
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Miscellaneous controller provides 3 interface files. If two misc resources (res_a and res_b) are registered then:
|
|
|
|
|
|
|
|
misc.capacity
|
|
|
|
A read-only flat-keyed file shown only in the root cgroup. It shows
|
|
|
|
miscellaneous scalar resources available on the platform along with
|
|
|
|
their quantities::
|
|
|
|
|
|
|
|
$ cat misc.capacity
|
|
|
|
res_a 50
|
|
|
|
res_b 10
|
|
|
|
|
|
|
|
misc.current
|
2023-06-13 10:59:29 +00:00
|
|
|
A read-only flat-keyed file shown in the all cgroups. It shows
|
2021-03-30 04:42:05 +00:00
|
|
|
the current usage of the resources in the cgroup and its children.::
|
|
|
|
|
|
|
|
$ cat misc.current
|
|
|
|
res_a 3
|
|
|
|
res_b 0
|
|
|
|
|
2024-07-03 00:36:46 +00:00
|
|
|
misc.peak
|
|
|
|
A read-only flat-keyed file shown in all cgroups. It shows the
|
|
|
|
historical maximum usage of the resources in the cgroup and its
|
|
|
|
children.::
|
|
|
|
|
|
|
|
$ cat misc.peak
|
|
|
|
res_a 10
|
|
|
|
res_b 8
|
|
|
|
|
2021-03-30 04:42:05 +00:00
|
|
|
misc.max
|
|
|
|
A read-write flat-keyed file shown in the non root cgroups. Allowed
|
|
|
|
maximum usage of the resources in the cgroup and its children.::
|
|
|
|
|
|
|
|
$ cat misc.max
|
|
|
|
res_a max
|
|
|
|
res_b 4
|
|
|
|
|
|
|
|
Limit can be set by::
|
|
|
|
|
|
|
|
# echo res_a 1 > misc.max
|
|
|
|
|
|
|
|
Limit can be set to max by::
|
|
|
|
|
|
|
|
# echo res_a max > misc.max
|
|
|
|
|
|
|
|
Limits can be set higher than the capacity value in the misc.capacity
|
|
|
|
file.
|
|
|
|
|
2021-09-17 12:44:16 +00:00
|
|
|
misc.events
|
|
|
|
A read-only flat-keyed file which exists on non-root cgroups. The
|
|
|
|
following entries are defined. Unless specified otherwise, a value
|
|
|
|
change in this file generates a file modified event. All fields in
|
|
|
|
this file are hierarchical.
|
|
|
|
|
|
|
|
max
|
|
|
|
The number of times the cgroup's resource usage was
|
|
|
|
about to go over the max boundary.
|
|
|
|
|
2024-07-11 10:14:57 +00:00
|
|
|
misc.events.local
|
|
|
|
Similar to misc.events but the fields in the file are local to the
|
|
|
|
cgroup i.e. not hierarchical. The file modified event generated on
|
|
|
|
this file reflects only the local events.
|
|
|
|
|
2021-03-30 04:42:05 +00:00
|
|
|
Migration and Ownership
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
A miscellaneous scalar resource is charged to the cgroup in which it is used
|
|
|
|
first, and stays charged to that cgroup until that resource is freed. Migrating
|
|
|
|
a process to a different cgroup does not move the charge to the destination
|
|
|
|
cgroup where the process has moved.
|
|
|
|
|
|
|
|
Others
|
|
|
|
------
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
perf_event
|
|
|
|
~~~~~~~~~~
|
2017-01-29 19:35:20 +00:00
|
|
|
|
|
|
|
perf_event controller, if not mounted on a legacy hierarchy, is
|
|
|
|
automatically enabled on the v2 hierarchy so that perf events can
|
|
|
|
always be filtered by cgroup v2 path. The controller can still be
|
|
|
|
moved to a legacy hierarchy after v2 hierarchy is populated.
|
|
|
|
|
|
|
|
|
2018-01-10 22:33:19 +00:00
|
|
|
Non-normative information
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
This section contains information that isn't considered to be a part of
|
|
|
|
the stable kernel API and so is subject to change.
|
|
|
|
|
|
|
|
|
|
|
|
CPU controller root cgroup process behaviour
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
When distributing CPU cycles in the root cgroup each thread in this
|
|
|
|
cgroup is treated as if it was hosted in a separate child cgroup of the
|
|
|
|
root cgroup. This child cgroup weight is dependent on its thread nice
|
|
|
|
level.
|
|
|
|
|
|
|
|
For details of this mapping see sched_prio_to_weight array in
|
|
|
|
kernel/sched/core.c file (values from this array should be scaled
|
|
|
|
appropriately so the neutral - nice 0 - value is 100 instead of 1024).
|
|
|
|
|
|
|
|
|
|
|
|
IO controller root cgroup process behaviour
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Root cgroup processes are hosted in an implicit leaf child node.
|
|
|
|
When distributing IO resources this implicit child node is taken into
|
|
|
|
account as if it was a normal child cgroup of the root cgroup with a
|
|
|
|
weight value of 200.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Namespace
|
|
|
|
=========
|
2016-01-29 08:54:10 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Basics
|
|
|
|
------
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
cgroup namespace provides a mechanism to virtualize the view of the
|
|
|
|
"/proc/$PID/cgroup" file and cgroup mounts. The CLONE_NEWCGROUP clone
|
|
|
|
flag can be used with clone(2) and unshare(2) to create a new cgroup
|
|
|
|
namespace. The process running inside the cgroup namespace will have
|
|
|
|
its "/proc/$PID/cgroup" output restricted to cgroupns root. The
|
|
|
|
cgroupns root is the cgroup of the process at the time of creation of
|
|
|
|
the cgroup namespace.
|
|
|
|
|
|
|
|
Without cgroup namespace, the "/proc/$PID/cgroup" file shows the
|
|
|
|
complete path of the cgroup of a process. In a container setup where
|
|
|
|
a set of cgroups and namespaces are intended to isolate processes the
|
|
|
|
"/proc/$PID/cgroup" file may leak potential system level information
|
2021-01-20 00:18:23 +00:00
|
|
|
to the isolated processes. For example::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# cat /proc/self/cgroup
|
|
|
|
0::/batchjobs/container_id1
|
|
|
|
|
|
|
|
The path '/batchjobs/container_id1' can be considered as system-data
|
|
|
|
and undesirable to expose to the isolated processes. cgroup namespace
|
|
|
|
can be used to restrict visibility of this path. For example, before
|
2017-05-14 11:48:40 +00:00
|
|
|
creating a cgroup namespace, one would see::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# ls -l /proc/self/ns/cgroup
|
|
|
|
lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835]
|
|
|
|
# cat /proc/self/cgroup
|
|
|
|
0::/batchjobs/container_id1
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
After unsharing a new namespace, the view changes::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# ls -l /proc/self/ns/cgroup
|
|
|
|
lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183]
|
|
|
|
# cat /proc/self/cgroup
|
|
|
|
0::/
|
|
|
|
|
|
|
|
When some thread from a multi-threaded process unshares its cgroup
|
|
|
|
namespace, the new cgroupns gets applied to the entire process (all
|
|
|
|
the threads). This is natural for the v2 hierarchy; however, for the
|
|
|
|
legacy hierarchies, this may be unexpected.
|
|
|
|
|
|
|
|
A cgroup namespace is alive as long as there are processes inside or
|
|
|
|
mounts pinning it. When the last usage goes away, the cgroup
|
|
|
|
namespace is destroyed. The cgroupns root and the actual cgroups
|
|
|
|
remain.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
The Root and Views
|
|
|
|
------------------
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
The 'cgroupns root' for a cgroup namespace is the cgroup in which the
|
|
|
|
process calling unshare(2) is running. For example, if a process in
|
|
|
|
/batchjobs/container_id1 cgroup calls unshare, cgroup
|
|
|
|
/batchjobs/container_id1 becomes the cgroupns root. For the
|
|
|
|
init_cgroup_ns, this is the real root ('/') cgroup.
|
|
|
|
|
|
|
|
The cgroupns root cgroup does not change even if the namespace creator
|
2017-05-14 11:48:40 +00:00
|
|
|
process later moves to a different cgroup::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# ~/unshare -c # unshare cgroupns in some cgroup
|
|
|
|
# cat /proc/self/cgroup
|
|
|
|
0::/
|
|
|
|
# mkdir sub_cgrp_1
|
|
|
|
# echo 0 > sub_cgrp_1/cgroup.procs
|
|
|
|
# cat /proc/self/cgroup
|
|
|
|
0::/sub_cgrp_1
|
|
|
|
|
|
|
|
Each process gets its namespace-specific view of "/proc/$PID/cgroup"
|
|
|
|
|
|
|
|
Processes running inside the cgroup namespace will be able to see
|
|
|
|
cgroup paths (in /proc/self/cgroup) only inside their root cgroup.
|
2017-05-14 11:48:40 +00:00
|
|
|
From within an unshared cgroupns::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# sleep 100000 &
|
|
|
|
[1] 7353
|
|
|
|
# echo 7353 > sub_cgrp_1/cgroup.procs
|
|
|
|
# cat /proc/7353/cgroup
|
|
|
|
0::/sub_cgrp_1
|
|
|
|
|
|
|
|
From the initial cgroup namespace, the real cgroup path will be
|
2017-05-14 11:48:40 +00:00
|
|
|
visible::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
$ cat /proc/7353/cgroup
|
|
|
|
0::/batchjobs/container_id1/sub_cgrp_1
|
|
|
|
|
|
|
|
From a sibling cgroup namespace (that is, a namespace rooted at a
|
|
|
|
different cgroup), the cgroup path relative to its own cgroup
|
|
|
|
namespace root will be shown. For instance, if PID 7353's cgroup
|
2017-05-14 11:48:40 +00:00
|
|
|
namespace root is at '/batchjobs/container_id2', then it will see::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# cat /proc/7353/cgroup
|
|
|
|
0::/../container_id2/sub_cgrp_1
|
|
|
|
|
|
|
|
Note that the relative path always starts with '/' to indicate that
|
|
|
|
its relative to the cgroup namespace root of the caller.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Migration and setns(2)
|
|
|
|
----------------------
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
Processes inside a cgroup namespace can move into and out of the
|
|
|
|
namespace root if they have proper access to external cgroups. For
|
|
|
|
example, from inside a namespace with cgroupns root at
|
|
|
|
/batchjobs/container_id1, and assuming that the global hierarchy is
|
2017-05-14 11:48:40 +00:00
|
|
|
still accessible inside cgroupns::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# cat /proc/7353/cgroup
|
|
|
|
0::/sub_cgrp_1
|
|
|
|
# echo 7353 > batchjobs/container_id2/cgroup.procs
|
|
|
|
# cat /proc/7353/cgroup
|
|
|
|
0::/../container_id2
|
|
|
|
|
|
|
|
Note that this kind of setup is not encouraged. A task inside cgroup
|
|
|
|
namespace should only be exposed to its own cgroupns hierarchy.
|
|
|
|
|
|
|
|
setns(2) to another cgroup namespace is allowed when:
|
|
|
|
|
|
|
|
(a) the process has CAP_SYS_ADMIN against its current user namespace
|
|
|
|
(b) the process has CAP_SYS_ADMIN against the target cgroup
|
|
|
|
namespace's userns
|
|
|
|
|
|
|
|
No implicit cgroup changes happen with attaching to another cgroup
|
|
|
|
namespace. It is expected that the someone moves the attaching
|
|
|
|
process under the target cgroup namespace root.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Interaction with Other Namespaces
|
|
|
|
---------------------------------
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
Namespace specific cgroup hierarchy can be mounted by a process
|
2017-05-14 11:48:40 +00:00
|
|
|
running inside a non-init cgroup namespace::
|
2016-01-29 08:54:10 +00:00
|
|
|
|
|
|
|
# mount -t cgroup2 none $MOUNT_POINT
|
|
|
|
|
|
|
|
This will mount the unified cgroup hierarchy with cgroupns root as the
|
|
|
|
filesystem root. The process needs CAP_SYS_ADMIN against its user and
|
|
|
|
mount namespaces.
|
|
|
|
|
|
|
|
The virtualization of /proc/self/cgroup file combined with restricting
|
|
|
|
the view of cgroup hierarchy by namespace-private cgroupfs mount
|
|
|
|
provides a properly isolated cgroup view inside the container.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Information on Kernel Programming
|
|
|
|
=================================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
This section contains kernel programming information in the areas
|
|
|
|
where interacting with cgroup is necessary. cgroup core and
|
|
|
|
controllers are not covered.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Filesystem Support for Writeback
|
|
|
|
--------------------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
A filesystem can support cgroup writeback by updating
|
|
|
|
address_space_operations->writepage[s]() to annotate bio's using the
|
|
|
|
following two functions.
|
|
|
|
|
|
|
|
wbc_init_bio(@wbc, @bio)
|
|
|
|
Should be called for each bio carrying writeback data and
|
2018-12-05 17:10:34 +00:00
|
|
|
associates the bio with the inode's owner cgroup and the
|
|
|
|
corresponding request queue. This must be called after
|
|
|
|
a queue (device) has been associated with the bio and
|
|
|
|
before submission.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2024-09-26 14:01:21 +00:00
|
|
|
wbc_account_cgroup_owner(@wbc, @folio, @bytes)
|
2015-11-16 16:13:34 +00:00
|
|
|
Should be called for each data segment being written out.
|
|
|
|
While this function doesn't care exactly when it's called
|
|
|
|
during the writeback session, it's the easiest and most
|
|
|
|
natural to call it as data segments are added to a bio.
|
|
|
|
|
|
|
|
With writeback bio's annotated, cgroup support can be enabled per
|
|
|
|
super_block by setting SB_I_CGROUPWB in ->s_iflags. This allows for
|
|
|
|
selective disabling of cgroup writeback support which is helpful when
|
|
|
|
certain filesystem features, e.g. journaled data mode, are
|
|
|
|
incompatible.
|
|
|
|
|
|
|
|
wbc_init_bio() binds the specified bio to its cgroup. Depending on
|
|
|
|
the configuration, the bio may be executed at a lower priority and if
|
|
|
|
the writeback session is holding shared resources, e.g. a journal
|
|
|
|
entry, may lead to priority inversion. There is no one easy solution
|
|
|
|
for the problem. Filesystems can try to work around specific problem
|
2018-12-05 17:10:34 +00:00
|
|
|
cases by skipping wbc_init_bio() and using bio_associate_blkg()
|
2015-11-16 16:13:34 +00:00
|
|
|
directly.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Deprecated v1 Core Features
|
|
|
|
===========================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
- Multiple hierarchies including named ones are not supported.
|
|
|
|
|
2017-06-27 18:30:28 +00:00
|
|
|
- All v1 mount options are not supported.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
- The "tasks" file is removed and "cgroup.procs" is not sorted.
|
|
|
|
|
|
|
|
- "cgroup.clone_children" is removed.
|
|
|
|
|
2024-07-15 15:00:34 +00:00
|
|
|
- /proc/cgroups is meaningless for v2. Use "cgroup.controllers" or
|
|
|
|
"cgroup.stat" files at the root instead.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Issues with v1 and Rationales for v2
|
|
|
|
====================================
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Multiple Hierarchies
|
|
|
|
--------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cgroup v1 allowed an arbitrary number of hierarchies and each
|
|
|
|
hierarchy could host any number of controllers. While this seemed to
|
|
|
|
provide a high level of flexibility, it wasn't useful in practice.
|
|
|
|
|
|
|
|
For example, as there is only one instance of each controller, utility
|
|
|
|
type controllers such as freezer which can be useful in all
|
|
|
|
hierarchies could only be used in one. The issue is exacerbated by
|
|
|
|
the fact that controllers couldn't be moved to another hierarchy once
|
|
|
|
hierarchies were populated. Another issue was that all controllers
|
|
|
|
bound to a hierarchy were forced to have exactly the same view of the
|
|
|
|
hierarchy. It wasn't possible to vary the granularity depending on
|
|
|
|
the specific controller.
|
|
|
|
|
|
|
|
In practice, these issues heavily limited which controllers could be
|
|
|
|
put on the same hierarchy and most configurations resorted to putting
|
|
|
|
each controller on its own hierarchy. Only closely related ones, such
|
|
|
|
as the cpu and cpuacct controllers, made sense to be put on the same
|
|
|
|
hierarchy. This often meant that userland ended up managing multiple
|
|
|
|
similar hierarchies repeating the same steps on each hierarchy
|
|
|
|
whenever a hierarchy management operation was necessary.
|
|
|
|
|
|
|
|
Furthermore, support for multiple hierarchies came at a steep cost.
|
|
|
|
It greatly complicated cgroup core implementation but more importantly
|
|
|
|
the support for multiple hierarchies restricted how cgroup could be
|
|
|
|
used in general and what controllers was able to do.
|
|
|
|
|
|
|
|
There was no limit on how many hierarchies there might be, which meant
|
|
|
|
that a thread's cgroup membership couldn't be described in finite
|
|
|
|
length. The key might contain any number of entries and was unlimited
|
|
|
|
in length, which made it highly awkward to manipulate and led to
|
|
|
|
addition of controllers which existed only to identify membership,
|
|
|
|
which in turn exacerbated the original problem of proliferating number
|
|
|
|
of hierarchies.
|
|
|
|
|
|
|
|
Also, as a controller couldn't have any expectation regarding the
|
|
|
|
topologies of hierarchies other controllers might be on, each
|
|
|
|
controller had to assume that all other controllers were attached to
|
|
|
|
completely orthogonal hierarchies. This made it impossible, or at
|
|
|
|
least very cumbersome, for controllers to cooperate with each other.
|
|
|
|
|
|
|
|
In most use cases, putting controllers on hierarchies which are
|
|
|
|
completely orthogonal to each other isn't necessary. What usually is
|
|
|
|
called for is the ability to have differing levels of granularity
|
|
|
|
depending on the specific controller. In other words, hierarchy may
|
|
|
|
be collapsed from leaf towards root when viewed from specific
|
|
|
|
controllers. For example, a given configuration might not care about
|
|
|
|
how memory is distributed beyond a certain level while still wanting
|
|
|
|
to control how CPU cycles are distributed.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Thread Granularity
|
|
|
|
------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cgroup v1 allowed threads of a process to belong to different cgroups.
|
|
|
|
This didn't make sense for some controllers and those controllers
|
|
|
|
ended up implementing different ways to ignore such situations but
|
|
|
|
much more importantly it blurred the line between API exposed to
|
|
|
|
individual applications and system management interface.
|
|
|
|
|
|
|
|
Generally, in-process knowledge is available only to the process
|
|
|
|
itself; thus, unlike service-level organization of processes,
|
|
|
|
categorizing threads of a process requires active participation from
|
|
|
|
the application which owns the target process.
|
|
|
|
|
|
|
|
cgroup v1 had an ambiguously defined delegation model which got abused
|
|
|
|
in combination with thread granularity. cgroups were delegated to
|
|
|
|
individual applications so that they can create and manage their own
|
|
|
|
sub-hierarchies and control resource distributions along them. This
|
|
|
|
effectively raised cgroup to the status of a syscall-like API exposed
|
|
|
|
to lay programs.
|
|
|
|
|
|
|
|
First of all, cgroup has a fundamentally inadequate interface to be
|
|
|
|
exposed this way. For a process to access its own knobs, it has to
|
|
|
|
extract the path on the target hierarchy from /proc/self/cgroup,
|
|
|
|
construct the path by appending the name of the knob to the path, open
|
|
|
|
and then read and/or write to it. This is not only extremely clunky
|
|
|
|
and unusual but also inherently racy. There is no conventional way to
|
|
|
|
define transaction across the required steps and nothing can guarantee
|
|
|
|
that the process would actually be operating on its own sub-hierarchy.
|
|
|
|
|
|
|
|
cgroup controllers implemented a number of knobs which would never be
|
|
|
|
accepted as public APIs because they were just adding control knobs to
|
|
|
|
system-management pseudo filesystem. cgroup ended up with interface
|
|
|
|
knobs which were not properly abstracted or refined and directly
|
|
|
|
revealed kernel internal details. These knobs got exposed to
|
|
|
|
individual applications through the ill-defined delegation mechanism
|
|
|
|
effectively abusing cgroup as a shortcut to implementing public APIs
|
|
|
|
without going through the required scrutiny.
|
|
|
|
|
|
|
|
This was painful for both userland and kernel. Userland ended up with
|
|
|
|
misbehaving and poorly abstracted interfaces and kernel exposing and
|
|
|
|
locked into constructs inadvertently.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Competition Between Inner Nodes and Threads
|
|
|
|
-------------------------------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cgroup v1 allowed threads to be in any cgroups which created an
|
|
|
|
interesting problem where threads belonging to a parent cgroup and its
|
|
|
|
children cgroups competed for resources. This was nasty as two
|
|
|
|
different types of entities competed and there was no obvious way to
|
|
|
|
settle it. Different controllers did different things.
|
|
|
|
|
|
|
|
The cpu controller considered threads and cgroups as equivalents and
|
|
|
|
mapped nice levels to cgroup weights. This worked for some cases but
|
|
|
|
fell flat when children wanted to be allocated specific ratios of CPU
|
|
|
|
cycles and the number of internal threads fluctuated - the ratios
|
|
|
|
constantly changed as the number of competing entities fluctuated.
|
|
|
|
There also were other issues. The mapping from nice level to weight
|
|
|
|
wasn't obvious or universal, and there were various other knobs which
|
|
|
|
simply weren't available for threads.
|
|
|
|
|
|
|
|
The io controller implicitly created a hidden leaf node for each
|
|
|
|
cgroup to host the threads. The hidden leaf had its own copies of all
|
2017-05-14 11:48:40 +00:00
|
|
|
the knobs with ``leaf_`` prefixed. While this allowed equivalent
|
2015-11-16 16:13:34 +00:00
|
|
|
control over internal threads, it was with serious drawbacks. It
|
|
|
|
always added an extra layer of nesting which wouldn't be necessary
|
|
|
|
otherwise, made the interface messy and significantly complicated the
|
|
|
|
implementation.
|
|
|
|
|
|
|
|
The memory controller didn't have a way to control what happened
|
|
|
|
between internal tasks and child cgroups and the behavior was not
|
|
|
|
clearly defined. There were attempts to add ad-hoc behaviors and
|
|
|
|
knobs to tailor the behavior to specific workloads which would have
|
|
|
|
led to problems extremely difficult to resolve in the long term.
|
|
|
|
|
|
|
|
Multiple controllers struggled with internal tasks and came up with
|
|
|
|
different ways to deal with it; unfortunately, all the approaches were
|
|
|
|
severely flawed and, furthermore, the widely different behaviors
|
|
|
|
made cgroup as a whole highly inconsistent.
|
|
|
|
|
|
|
|
This clearly is a problem which needs to be addressed from cgroup core
|
|
|
|
in a uniform way.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Other Interface Issues
|
|
|
|
----------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
cgroup v1 grew without oversight and developed a large number of
|
|
|
|
idiosyncrasies and inconsistencies. One issue on the cgroup core side
|
|
|
|
was how an empty cgroup was notified - a userland helper binary was
|
|
|
|
forked and executed for each event. The event delivery wasn't
|
|
|
|
recursive or delegatable. The limitations of the mechanism also led
|
|
|
|
to in-kernel event delivery filtering mechanism further complicating
|
|
|
|
the interface.
|
|
|
|
|
|
|
|
Controller interfaces were problematic too. An extreme example is
|
|
|
|
controllers completely ignoring hierarchical organization and treating
|
|
|
|
all cgroups as if they were all located directly under the root
|
|
|
|
cgroup. Some controllers exposed a large amount of inconsistent
|
|
|
|
implementation details to userland.
|
|
|
|
|
|
|
|
There also was no consistency across controllers. When a new cgroup
|
|
|
|
was created, some controllers defaulted to not imposing extra
|
|
|
|
restrictions while others disallowed any resource usage until
|
|
|
|
explicitly configured. Configuration knobs for the same type of
|
|
|
|
control used widely differing naming schemes and formats. Statistics
|
|
|
|
and information knobs were named arbitrarily and used different
|
|
|
|
formats and units even in the same controller.
|
|
|
|
|
|
|
|
cgroup v2 establishes common conventions where appropriate and updates
|
|
|
|
controllers so that they expose minimal and consistent interfaces.
|
|
|
|
|
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Controller Issues and Remedies
|
|
|
|
------------------------------
|
2015-11-16 16:13:34 +00:00
|
|
|
|
2017-05-14 11:48:40 +00:00
|
|
|
Memory
|
|
|
|
~~~~~~
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
The original lower boundary, the soft limit, is defined as a limit
|
|
|
|
that is per default unset. As a result, the set of cgroups that
|
|
|
|
global reclaim prefers is opt-in, rather than opt-out. The costs for
|
|
|
|
optimizing these mostly negative lookups are so high that the
|
|
|
|
implementation, despite its enormous size, does not even provide the
|
|
|
|
basic desirable behavior. First off, the soft limit has no
|
|
|
|
hierarchical meaning. All configured groups are organized in a global
|
|
|
|
rbtree and treated like equal peers, regardless where they are located
|
|
|
|
in the hierarchy. This makes subtree delegation impossible. Second,
|
|
|
|
the soft limit reclaim pass is so aggressive that it not just
|
|
|
|
introduces high allocation latencies into the system, but also impacts
|
|
|
|
system performance due to overreclaim, to the point where the feature
|
|
|
|
becomes self-defeating.
|
|
|
|
|
|
|
|
The memory.low boundary on the other hand is a top-down allocated
|
mm, memcg: proportional memory.{low,min} reclaim
cgroup v2 introduces two memory protection thresholds: memory.low
(best-effort) and memory.min (hard protection). While they generally do
what they say on the tin, there is a limitation in their implementation
that makes them difficult to use effectively: that cliff behaviour often
manifests when they become eligible for reclaim. This patch implements
more intuitive and usable behaviour, where we gradually mount more
reclaim pressure as cgroups further and further exceed their protection
thresholds.
This cliff edge behaviour happens because we only choose whether or not
to reclaim based on whether the memcg is within its protection limits
(see the use of mem_cgroup_protected in shrink_node), but we don't vary
our reclaim behaviour based on this information. Imagine the following
timeline, with the numbers the lruvec size in this zone:
1. memory.low=1000000, memory.current=999999. 0 pages may be scanned.
2. memory.low=1000000, memory.current=1000000. 0 pages may be scanned.
3. memory.low=1000000, memory.current=1000001. 1000001* pages may be
scanned. (?!)
* Of course, we won't usually scan all available pages in the zone even
without this patch because of scan control priority, over-reclaim
protection, etc. However, as shown by the tests at the end, these
techniques don't sufficiently throttle such an extreme change in input,
so cliff-like behaviour isn't really averted by their existence alone.
Here's an example of how this plays out in practice. At Facebook, we are
trying to protect various workloads from "system" software, like
configuration management tools, metric collectors, etc (see this[0] case
study). In order to find a suitable memory.low value, we start by
determining the expected memory range within which the workload will be
comfortable operating. This isn't an exact science -- memory usage deemed
"comfortable" will vary over time due to user behaviour, differences in
composition of work, etc, etc. As such we need to ballpark memory.low,
but doing this is currently problematic:
1. If we end up setting it too low for the workload, it won't have
*any* effect (see discussion above). The group will receive the full
weight of reclaim and won't have any priority while competing with the
less important system software, as if we had no memory.low configured
at all.
2. Because of this behaviour, we end up erring on the side of setting
it too high, such that the comfort range is reliably covered. However,
protected memory is completely unavailable to the rest of the system,
so we might cause undue memory and IO pressure there when we *know* we
have some elasticity in the workload.
3. Even if we get the value totally right, smack in the middle of the
comfort zone, we get extreme jumps between no pressure and full
pressure that cause unpredictable pressure spikes in the workload due
to the current binary reclaim behaviour.
With this patch, we can set it to our ballpark estimation without too much
worry. Any undesirable behaviour, such as too much or too little reclaim
pressure on the workload or system will be proportional to how far our
estimation is off. This means we can set memory.low much more
conservatively and thus waste less resources *without* the risk of the
workload falling off a cliff if we overshoot.
As a more abstract technical description, this unintuitive behaviour
results in having to give high-priority workloads a large protection
buffer on top of their expected usage to function reliably, as otherwise
we have abrupt periods of dramatically increased memory pressure which
hamper performance. Having to set these thresholds so high wastes
resources and generally works against the principle of work conservation.
In addition, having proportional memory reclaim behaviour has other
benefits. Most notably, before this patch it's basically mandatory to set
memory.low to a higher than desirable value because otherwise as soon as
you exceed memory.low, all protection is lost, and all pages are eligible
to scan again. By contrast, having a gradual ramp in reclaim pressure
means that you now still get some protection when thresholds are exceeded,
which means that one can now be more comfortable setting memory.low to
lower values without worrying that all protection will be lost. This is
important because workingset size is really hard to know exactly,
especially with variable workloads, so at least getting *some* protection
if your workingset size grows larger than you expect increases user
confidence in setting memory.low without a huge buffer on top being
needed.
Thanks a lot to Johannes Weiner and Tejun Heo for their advice and
assistance in thinking about how to make this work better.
In testing these changes, I intended to verify that:
1. Changes in page scanning become gradual and proportional instead of
binary.
To test this, I experimented stepping further and further down
memory.low protection on a workload that floats around 19G workingset
when under memory.low protection, watching page scan rates for the
workload cgroup:
+------------+-----------------+--------------------+--------------+
| memory.low | test (pgscan/s) | control (pgscan/s) | % of control |
+------------+-----------------+--------------------+--------------+
| 21G | 0 | 0 | N/A |
| 17G | 867 | 3799 | 23% |
| 12G | 1203 | 3543 | 34% |
| 8G | 2534 | 3979 | 64% |
| 4G | 3980 | 4147 | 96% |
| 0 | 3799 | 3980 | 95% |
+------------+-----------------+--------------------+--------------+
As you can see, the test kernel (with a kernel containing this
patch) ramps up page scanning significantly more gradually than the
control kernel (without this patch).
2. More gradual ramp up in reclaim aggression doesn't result in
premature OOMs.
To test this, I wrote a script that slowly increments the number of
pages held by stress(1)'s --vm-keep mode until a production system
entered severe overall memory contention. This script runs in a highly
protected slice taking up the majority of available system memory.
Watching vmstat revealed that page scanning continued essentially
nominally between test and control, without causing forward reclaim
progress to become arrested.
[0]: https://facebookmicrosites.github.io/cgroup2/docs/overview.html#case-study-the-fbtax2-project
[akpm@linux-foundation.org: reflow block comments to fit in 80 cols]
[chris@chrisdown.name: handle cgroup_disable=memory when getting memcg protection]
Link: http://lkml.kernel.org/r/20190201045711.GA18302@chrisdown.name
Link: http://lkml.kernel.org/r/20190124014455.GA6396@chrisdown.name
Signed-off-by: Chris Down <chris@chrisdown.name>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-07 00:58:32 +00:00
|
|
|
reserve. A cgroup enjoys reclaim protection when it's within its
|
|
|
|
effective low, which makes delegation of subtrees possible. It also
|
|
|
|
enjoys having reclaim pressure proportional to its overage when
|
|
|
|
above its effective low.
|
2015-11-16 16:13:34 +00:00
|
|
|
|
|
|
|
The original high boundary, the hard limit, is defined as a strict
|
|
|
|
limit that can not budge, even if the OOM killer has to be called.
|
|
|
|
But this generally goes against the goal of making the most out of the
|
|
|
|
available memory. The memory consumption of workloads varies during
|
|
|
|
runtime, and that requires users to overcommit. But doing that with a
|
|
|
|
strict upper limit requires either a fairly accurate prediction of the
|
|
|
|
working set size or adding slack to the limit. Since working set size
|
|
|
|
estimation is hard and error prone, and getting it wrong results in
|
|
|
|
OOM kills, most users tend to err on the side of a looser limit and
|
|
|
|
end up wasting precious resources.
|
|
|
|
|
|
|
|
The memory.high boundary on the other hand can be set much more
|
|
|
|
conservatively. When hit, it throttles allocations by forcing them
|
|
|
|
into direct reclaim to work off the excess, but it never invokes the
|
|
|
|
OOM killer. As a result, a high boundary that is chosen too
|
|
|
|
aggressively will not terminate the processes, but instead it will
|
|
|
|
lead to gradual performance degradation. The user can monitor this
|
|
|
|
and make corrections until the minimal memory footprint that still
|
|
|
|
gives acceptable performance is found.
|
|
|
|
|
|
|
|
In extreme cases, with many concurrent allocations and a complete
|
|
|
|
breakdown of reclaim progress within the group, the high boundary can
|
|
|
|
be exceeded. But even then it's mostly better to satisfy the
|
|
|
|
allocation from the slack available in other groups or the rest of the
|
|
|
|
system than killing the group. Otherwise, memory.max is there to
|
|
|
|
limit this type of spillover and ultimately contain buggy or even
|
|
|
|
malicious applications.
|
2016-01-20 23:03:13 +00:00
|
|
|
|
2016-03-17 21:20:28 +00:00
|
|
|
Setting the original memory.limit_in_bytes below the current usage was
|
|
|
|
subject to a race condition, where concurrent charges could cause the
|
|
|
|
limit setting to fail. memory.max on the other hand will first set the
|
|
|
|
limit to prevent new charges, and then reclaim and OOM kill until the
|
|
|
|
new limit is met - or the task writing to memory.max is killed.
|
|
|
|
|
2016-01-20 23:03:13 +00:00
|
|
|
The combined memory+swap accounting and limiting is replaced by real
|
|
|
|
control over swap space.
|
|
|
|
|
|
|
|
The main argument for a combined memory+swap facility in the original
|
|
|
|
cgroup design was that global or parental pressure would always be
|
|
|
|
able to swap all anonymous memory of a child group, regardless of the
|
|
|
|
child's own (possibly untrusted) configuration. However, untrusted
|
|
|
|
groups can sabotage swapping by other means - such as referencing its
|
|
|
|
anonymous memory in a tight loop - and an admin can not assume full
|
|
|
|
swappability when overcommitting untrusted jobs.
|
|
|
|
|
|
|
|
For trusted jobs, on the other hand, a combined counter is not an
|
|
|
|
intuitive userspace interface, and it flies in the face of the idea
|
|
|
|
that cgroup controllers should account and limit specific physical
|
|
|
|
resources. Swap space is a resource like all others in the system,
|
|
|
|
and that's why unified hierarchy allows distributing it separately.
|