Commit graph

8 commits

Author SHA1 Message Date
T.J. Mercier
787ddbc8a5 Reapply "libprocessgroup: Combine all 3 ActivateControllers imple..."
This reverts commit 0fa49253a4.

Change-Id: I83121ff295caaabc0a2fd8a606ee2d52dacb0174
2024-10-08 23:42:55 +00:00
T.J. Mercier
a09ee8ece6 Reapply "libprocessgroup: Remove cgroup.rc file"
This reverts commit 972a2d30f8.

Change-Id: Icdf2824675e515ea3656b1c58ac55160ecc337df
2024-10-08 23:42:49 +00:00
Priyanka Advani (xWF)
972a2d30f8 Revert "libprocessgroup: Remove cgroup.rc file"
Revert submission 3212512

Reason for revert: Droidmonitor created revert due to b/372273614. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:3212512

Change-Id: I37568516e973cb940f1229d52f94b8dc801da2ab
2024-10-08 18:54:37 +00:00
Priyanka Advani (xWF)
0fa49253a4 Revert "libprocessgroup: Combine all 3 ActivateControllers imple..."
Revert submission 3212512

Reason for revert: Droidmonitor created revert due to b/372273614. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:3212512

Change-Id: I3dadc0b7bccfe28bb067a93df2acf2c3ea0f9920
2024-10-08 18:54:40 +00:00
T.J. Mercier
5161033f66 libprocessgroup: Combine all 3 ActivateControllers implementations into one
Remove this code duplication and use just one interface.

Bug: 349105928
Change-Id: Id8c7186d9665e9087a654f5781b7593b06349160
2024-10-03 17:01:34 +00:00
T.J. Mercier
ae4ce8ccc5 libprocessgroup: Remove cgroup.rc file
The cgroup.rc file was introduced in 192aee782 ("libprocessgroup: Add
support for task profiles") back with the initial support for task
profiles. It was intended to optimize performance associated with cgroup
operations. However over time, supporting this file led to making
libprocessgroup code more complicated (such as the cgrouprc LLNDK
interface), and the file ended up getting mmaped into nearly every
process on Android even though only a handful of them actually use it.
Replacing this file with reading and parsing of cgroup information on
demand allows us to simplify and shrink libprocessgroup, and eliminates
thousands of unused mappings without negatively affecting boot time or
other performance metrics.

Bug: 349105928
Test: Verified with memcg v2 and MaxActivationDepth 1 on Cuttlefish, Raven, and Mokey
Change-Id: Ic3f01fdf7fda89a56ab80657e1cf4573156273e6
2024-10-03 17:01:34 +00:00
T.J. Mercier
ae0b290387 libprocessgroup: Convert libprocessgroup_util to static library
To avoid duplicate symbol linker error and prep for addition of json
descriptor reading and activation functions in upcoming changes.

Bug: 349105928
Test: m
Change-Id: I5cd663d6007ef330b872b8cf8ed046ee68b6d736
2024-08-12 21:15:09 +00:00
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