From 5fa8af2b10d24fb6c08099d258bf887baf68ffb0 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 27 Jun 2018 11:32:40 +0900 Subject: [PATCH] Add system_server to system group only if per_app_memcg is true P18 or other high-performance devices shouldn't use per-memcg so it was disabled on those devices[1]. However, we didn't turn off for system_server memcg so those devices still have two seperate LRU groups which would have less efficient memory reclaim. Therefore, this patch makes memcg use for system_server only if per_app_memcg is enabled. [1] https://googleplex-android-review.git.corp.google.com/c/platform/system/core/+/4178592 Bug: 110858093 Test: confirm via cat /dev/memcg/system/tasks is none Change-Id: Ic0e3157bf8ff5de69767797b5508946ca3efeb68 Signed-off-by: Minchan Kim --- core/jni/com_android_internal_os_Zygote.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index b2853c9f1c611..223af68b36b0c 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -45,6 +45,7 @@ #include #include "android-base/logging.h" +#include #include #include #include @@ -70,6 +71,7 @@ namespace { using android::String8; using android::base::StringPrintf; using android::base::WriteStringToFile; +using android::base::GetBoolProperty; #define CREATE_ERROR(...) StringPrintf("%s:%d: ", __FILE__, __LINE__). \ append(StringPrintf(__VA_ARGS__)) @@ -889,12 +891,16 @@ static jint com_android_internal_os_Zygote_nativeForkSystemServer( RuntimeAbort(env, __LINE__, "System server process has died. Restarting Zygote!"); } - // Assign system_server to the correct memory cgroup. - // Not all devices mount /dev/memcg so check for the file first - // to avoid unnecessarily printing errors and denials in the logs. - if (!access("/dev/memcg/system/tasks", F_OK) && + bool low_ram_device = GetBoolProperty("ro.config.low_ram", false); + bool per_app_memcg = GetBoolProperty("ro.config.per_app_memcg", low_ram_device); + if (per_app_memcg) { + // Assign system_server to the correct memory cgroup. + // Not all devices mount /dev/memcg so check for the file first + // to avoid unnecessarily printing errors and denials in the logs. + if (!access("/dev/memcg/system/tasks", F_OK) && !WriteStringToFile(StringPrintf("%d", pid), "/dev/memcg/system/tasks")) { - ALOGE("couldn't write %d to /dev/memcg/system/tasks", pid); + ALOGE("couldn't write %d to /dev/memcg/system/tasks", pid); + } } } return pid;