libprocessgroup: Support memcg v1 per-app with PRODUCT_CGROUP_V2_SYS_APP_ISOLATION_ENABLED
We are enabling PRODUCT_CGROUP_V2_SYS_APP_ISOLATION_ENABLED by default
and also temporarily retaining support for overriding the new memcg v2
default back to v1. That means the default
PRODUCT_CGROUP_V2_SYS_APP_ISOLATION_ENABLED must work correctly with v1
per-application memcg paths, which is not currently the case. This
change uses knowledge about whether paths being generated are for a v1
cgroup or a v2 cgroup so that the common ConvertUid{Pid}ToPath functions
can continue to be used for both v1 and v2 cases.
Memcg v1 support will eventually be removed, so this change can be
reverted when that happens.
Test: boot cf_gwear_x86-trunk_staging-userdebug with
PRODUCT_CGROUP_V2_SYS_APP_ISOLATION_ENABLED = true.
cf_gwear_x86-trunk_staging-userdebug sets ro.config.low_ram
causing v1 per-app memcgs to be used.
Bug: 377579705
Change-Id: Iec26c02fd261bdec80a7e49fce4dc207d1996b1b
diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp
index dc6c8c0..c03c257 100644
--- a/libprocessgroup/task_profiles.cpp
+++ b/libprocessgroup/task_profiles.cpp
@@ -150,8 +150,8 @@
return uid < AID_APP_START;
}
-std::string ConvertUidToPath(const char* root_cgroup_path, uid_t uid) {
- if (android::libprocessgroup_flags::cgroup_v2_sys_app_isolation()) {
+std::string ConvertUidToPath(const char* root_cgroup_path, uid_t uid, bool v2_path) {
+ if (android::libprocessgroup_flags::cgroup_v2_sys_app_isolation() && v2_path) {
if (isSystemApp(uid))
return StringPrintf("%s/system/uid_%u", root_cgroup_path, uid);
else
@@ -160,14 +160,14 @@
return StringPrintf("%s/uid_%u", root_cgroup_path, uid);
}
-std::string ConvertUidPidToPath(const char* root_cgroup_path, uid_t uid, pid_t pid) {
- const std::string uid_path = ConvertUidToPath(root_cgroup_path, uid);
+std::string ConvertUidPidToPath(const char* root_cgroup_path, uid_t uid, pid_t pid, bool v2_path) {
+ const std::string uid_path = ConvertUidToPath(root_cgroup_path, uid, v2_path);
return StringPrintf("%s/pid_%d", uid_path.c_str(), pid);
}
bool ProfileAttribute::GetPathForProcess(uid_t uid, pid_t pid, std::string* path) const {
if (controller()->version() == 2) {
- const std::string cgroup_path = ConvertUidPidToPath(controller()->path(), uid, pid);
+ const std::string cgroup_path = ConvertUidPidToPath(controller()->path(), uid, pid, true);
*path = cgroup_path + "/" + file_name();
return true;
}
@@ -199,7 +199,7 @@
return true;
}
- const std::string cgroup_path = ConvertUidToPath(controller()->path(), uid);
+ const std::string cgroup_path = ConvertUidToPath(controller()->path(), uid, true);
*path = cgroup_path + "/" + file_name();
return true;
}