android_system_core/libprocessgroup/profiles
T.J. Mercier 28b37f2704 libprocessgroup: Add MaxActivationDepth
Cgroup v2 controllers can be enabled in a subtree of the shared
hierarchy. That allows users to limit the number of cgroups with a
controller enabled to less than the total number of cgroups. [1]

There are costs for each cgroup. Kernel memory is used for each cgroup,
plus additional memory for each active controller in each cgroup. Some
kernel operations scale with the number of cgroups (with a given
controller enabled), so it can be desirable to minimize the number of
cgroups with that controller enabled.

This change allows each v2 controller configuration to specify a maximum
activation depth, past which the controller will not be activated deeper
in the Android cgroup v2 hierarchy. The hierarchy root is defined as
depth 0. MaxActivationDepth is the field name for this purpose for
controllers in the Controllers array under Cgroups2 in cgroups.json.

Here are two examples:

"MaxActivationDepth": 1
This will activate the controller in every per-application cgroup, but
not in the per-process cgroups below.

/sys/fs/cgroup                depth=0  active=true  (controller listed in cgroup.subtree_control)
/sys/fs/cgroup/uid_0          depth=1  active=true  (controller NOT listed in cgroup.subtree_control)
/sys/fs/cgroup/uid_0/pid_100  depth=2  active=false (controller NOT listed in cgroup.subtree_control)

This can also be used with
PRODUCT_CGROUP_V2_SYS_APP_ISOLATION_ENABLED := true.

"MaxActivationDepth": 1
This will activate the controller only at the app / system level, but
not in per-application cgroups below. This results in a total of only
3 cgroups with the controller enabled (root, apps, system).

/sys/fs/cgroup                         depth=0  active=true  (controller listed in cgroup.subtree_control)
/sys/fs/cgroup/apps                    depth=1  active=true  (controller NOT listed in cgroup.subtree_control)
/sys/fs/cgroup/apps/uid_10000          depth=2  active=false (controller NOT listed in cgroup.subtree_control)
/sys/fs/cgroup/apps/uid_10000/pid_100  depth=3  active=false (controller NOT listed in cgroup.subtree_control)

[1] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#enabling-and-disabling

Bug: 346584259
Test: Cuttlefish with memcg v2
Change-Id: I62109ea935261c51fc30b2054c4d28d0360f7985
2024-06-18 15:50:21 +00:00
..
Android.bp [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
cgroups.json Revert "Migrate the blkio controller to the v2 cgroup hierarchy" 2024-01-26 03:54:47 +00:00
cgroups.proto libprocessgroup: Add MaxActivationDepth 2024-06-18 15:50:21 +00:00
cgroups.recovery.json libprocessgroup: fix uid/pid hierarchy for recovery mode 2021-02-11 17:03:19 -08:00
cgroups_28.json libprocessgroup: Change per-API level task profiles to override the diffs 2020-12-03 19:39:31 +00:00
cgroups_29.json libprocessgroup: Change per-API level task profiles to override the diffs 2020-12-03 19:39:31 +00:00
cgroups_30.json libprocessgroup: introduce optional attribute for cgroup controllers 2021-03-11 17:42:30 +00:00
cgroups_test.h libprocessgroup_proto_test split into multiple files 2019-03-15 12:34:42 -07:00
task_profiles.json Revert "Migrate the blkio controller to the v2 cgroup hierarchy" 2024-01-26 03:54:47 +00:00
task_profiles.proto Add support for memcg v2 attributes 2022-03-17 14:18:14 -07:00
task_profiles_28.json init.rc: Create a new group for dex2oat 2021-10-22 22:20:07 +08:00
task_profiles_29.json init.rc: Create a new group for dex2oat 2021-10-22 22:20:07 +08:00
task_profiles_30.json init.rc: Create a new group for dex2oat 2021-10-22 22:20:07 +08:00
task_profiles_test.h libprocessgroup_proto_test split into multiple files 2019-03-15 12:34:42 -07:00
test.cpp Fix build with new googletest 2019-11-10 04:08:25 +00:00
test_vendor.cpp libprocessgroup: Add VTS tests for vendor JSON files 2019-03-15 16:28:42 -07:00