This flag adds "apps" and "system" cgroups underneath the v2 hierarchy
root. Cgroups with UIDs < 10000 (AID_APP_START) will be placed
under "system" and others will be placed under "apps". UIDs under 10000
are reserved for core Android subsystems. This allows us to
apply different cgroup controls collectively to system processes and
normal applications.
Bug: 327480673
Change-Id: I40837dee27a59691f81fef48e66a86c5eacda892
This flag prevents memcg from being mounted as a v1 hierarchy, even if
cgroups.json specifies it should be mounted as v1. It will activate
memcg in the v2 hierarchy even if cgroups.json does not specify that it
should be activated in the v2 hierarchy.
The cgroup_disable=memory kernel command line argument will still
prevent memcg from being activated, as this forced memcg controller
is marked as optional.
Bug: 327480673
Change-Id: Iad2491dd0c1576156ee2346928d041d85af890f0
Improve the readability of this function by splitting it.
This CL includes the following behavior changes:
- If changing the directory owner and/or mode fails for /sys/fs/cgroup,
this is considered as a fatal error instead of something that should
only fail if "Optional" has not been set.
- If mounting the v2 cgroup controller fails, this is considered as an
error.
- Activating/mounting a cgroup controller only fails if the controller
has not been marked as optional.
Bug: 213617178
Change-Id: If6908dfdbcb2e1c9637ab4ac8a7625f0a17dc9e0
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Fix the function name in a log message inside CgroupSetup().
Bug: 213617178
Change-Id: I897c831f5e53093df2664e0e8ceefadf9a89369c
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Make it possible to verify whether the memory cgroup controller has been
mounted in the v2 hierarchy by comparing its path with the cgroup v2
path. This patch changes the path of cgroup controllers mounted in the
v2 hierarchy from /sys/fs/cgroup/. into /sys/fs/cgroup (no trailing /.).
Bug: 213617178
Test: Added debug code that prints the path for the memory cgroup in the
Test: v2 hierarchy.
Change-Id: I8a2764a6daae84caecf360a918eab62778e3f546
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Introduce a local variable for an expression that occurs twice. Use
string append instead of string concatenation because the former is more
efficient.
Bug: 213617178
Test: Compile-tested only.
Change-Id: I6e8b9d63b10accb220216dc484dffd18f5c54ce7
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Enable the memory_recursiveprot mount option for v2 cgroups because the
v2 memcg documentation mentions the following: "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)."
Source: https://www.kernel.org/doc/Documentation/admin-guide/cgroup-v2.rst
Bug: 213617178
Test: Verified this change inside the Cuttlefish emulator.
Change-Id: Iecd86109d9ecb9d3354f9d28577b147edf7c50a8
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Memory cgroup controller is not used by high-end Android devices and is
disabled in Android kernels 5.10+, however Android Go devices still
require this controller.
Similarly schedtune controller is being replaced with cpu controller's
utilclamp feature, however some devices are using older kernels which
only support schedtune.
To prevent spamming logcat with errors we need a way to mark a
controller optional in such cases without removing it from
cgroups.json file.
Introduce "Optional" attribute to cgroup controller's cgroups.json
description to accomodate these cases. When an optional controller
fails to mount due to lack of support in the kernel it will log an
informational message without generating further errors.
Bug: 181866655
Test: boot and observe libprocessgroup messages in logcat
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ib5bcfdd8d338704f3f9d8b326d8ddd88b67915a1
Current per-API level task profiles replace the latest task profiles
rather than overriding the diffs. This poses an issue when a new
feature is added which is applicable to older devices as well we
have to change all per-API level profiles. Change the per-API task
profile support to load the latest task profiles first and then override
with per-API task profiles, similar to how vendor task profiles override
system task profiles. This minimizes the changes we need to do to the
per-API level task profiles going forward and is more consistent with
how vendor task profiles work.
Bug: 170507876
Test: boot with per-API task profiles
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I08cc4b374cede7363cf96a30ac96971d49bb7847
When task profiles changes happen, devices released under older API
levels might have to use the same profiles as before. This might be
due to for missing kernel features or some other reasons. Add support
for per-API task profiles to accommodate this scenario. With this
mechanism when ro.product.first_api_level is non-empty, the system
looks for /system/etc/profiles/task_profiles_<api level>.json file
and uses it if it exists. If ro.product.first_api_level is not defined
or per-API task profiles file does not exist the system falls back to
the default /system/etc/profiles/task_profiles.json file.
As before, these task profiles can be competely overwritten using
/vendor/etc/task_profiles.json if needed.
Bug: 172066799
Test: boot with per-API task profiles
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I1671b341b3a0fb5e99d0b0788315c61088326b09
for a first implementation the cgroup v2 freezer controller will be used in a
way similar to cgroup v1, that is a single child group will hold all frozen
processes. Some adjustments are needed for the new structure.
- Add support for cgroup v2 syntax under procfs.
- Separate creation of a directory with ownership/mode changes to allow changes
after mounting the cgroup kernfs root.
- Allow the creation of sub-groups under a cgroup v2 hierarchy.
Bug: 154548692
Test: manually verified that a proper cgroup v2 hierarchy is created and
accessible
Change-Id: I9af59e8214acaead3f520a94c95e75394c0df948
Controllers listed in cgroups.json file might fail to mount if kernel is
not configured to support them. We need a way to indicate whether a
controller was successfully mounted and is usable to avoid logging errors
and warnings when a controller that failed to mount is being used. Add
flags bitmask to cgrouprc controller descriptor and use a bit to indicate
that controller is successfully mounted. Modify cpusets_enabled() and
schedboost_enabled() functions to use this bit and report the actual
availability of the controller.
Bug: 124080437
Test: libcutils_test with cpuset and schedtune controllers disabled
Change-Id: I770cc39fe50465146e3205aacf77dc3c56923c5d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
- If file is unlinked, the mmapped region is still there.
- If file is truncated, a SIGBUS will be seen, and holding
the fd doesn't help.
Test: boots (sanity)
Bug: 123664216
Change-Id: I6683804bc795fab6798891a4471e5fe58fbffe13
Use CgroupController definition from libcgrouprc_format, not
libprocessgroup, because the wire format will be removed
from libprocessgroup later.
Bug: 123664216
Test: builds
Change-Id: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
Merged-In: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
Only init uses SetupCgroups. This functionality is
moved from libprocessgroup to its own library, and only
init links to it.
Also, merge CgroupSetupCgroups() with CgroupMap::SetupCgroups()
because the former is just an alias of the latter, and
CgroupMap does not belong to libcgrouprc_setup.
Test: boots
Bug: 123664216
Change-Id: I941dc0c415e2b22ae663d43e30dc7a464687325e
Merged-In: I941dc0c415e2b22ae663d43e30dc7a464687325e