summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren Baghdasaryan2018-05-23 14:30:44 -0500
committerSuren Baghdasaryan2018-05-24 17:13:00 -0500
commitbc131c3244a6aa4961092ba08285f9d0435a8882 (patch)
tree8fc79f4c24531bedf8240e68ba7f77fe40cfb5a4
parent6e9289013560484e17b995dbe51bd4d3ba61ab34 (diff)
downloadplatform-system-core-bc131c3244a6aa4961092ba08285f9d0435a8882.tar.gz
platform-system-core-bc131c3244a6aa4961092ba08285f9d0435a8882.tar.xz
platform-system-core-bc131c3244a6aa4961092ba08285f9d0435a8882.zip
Make per-application memcg hierarchy configurable via a property
Introduce ro.config.per_app_memcg Android property to enable/disable per-application memcg hierarchy. On low-ram devices (ro.config.low_ram=true) ro.config.per_app_memcg defaults to true, otherwise it defaults to false. Bug: 80201565 Test: set ro.config.per_app_memcg=true and verify /proc/<app_pid>/cgroup membership (memory:/apps/uid_xxx/pid_xxx) Test: set ro.config.per_app_memcg=false and verify /proc/<app_pid>/cgroup membership (memory:/) Change-Id: Iabd3ef6c9c16c774b9da959a7f43b5f66df120a3 Merged-In: Iabd3ef6c9c16c774b9da959a7f43b5f66df120a3 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
-rw-r--r--libprocessgroup/processgroup.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 6dfa697de..58295fadb 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -39,12 +39,18 @@
39 39
40#include <android-base/file.h> 40#include <android-base/file.h>
41#include <android-base/logging.h> 41#include <android-base/logging.h>
42#ifdef __ANDROID__
43#include <android-base/properties.h>
44#endif
42#include <android-base/stringprintf.h> 45#include <android-base/stringprintf.h>
43#include <android-base/strings.h> 46#include <android-base/strings.h>
44#include <private/android_filesystem_config.h> 47#include <private/android_filesystem_config.h>
45 48
46#include <processgroup/processgroup.h> 49#include <processgroup/processgroup.h>
47 50
51#ifdef __ANDROID__
52using android::base::GetBoolProperty;
53#endif
48using android::base::StartsWith; 54using android::base::StartsWith;
49using android::base::StringPrintf; 55using android::base::StringPrintf;
50using android::base::WriteStringToFile; 56using android::base::WriteStringToFile;
@@ -62,12 +68,25 @@ std::once_flag init_path_flag;
62static const std::string& GetCgroupRootPath() { 68static const std::string& GetCgroupRootPath() {
63 static std::string cgroup_root_path; 69 static std::string cgroup_root_path;
64 std::call_once(init_path_flag, [&]() { 70 std::call_once(init_path_flag, [&]() {
65 // Check if mem cgroup is mounted, only then check for write-access to avoid 71#ifdef __ANDROID__
66 // SELinux denials 72 // low-ram devices use per-app memcg by default, unlike high-end ones
73 bool low_ram_device = GetBoolProperty("ro.config.low_ram", false);
74 bool per_app_memcg =
75 GetBoolProperty("ro.config.per_app_memcg", low_ram_device);
76#else
77 // host does not support Android properties
78 bool per_app_memcg = false;
79#endif
80 if (per_app_memcg) {
81 // Check if mem cgroup is mounted, only then check for
82 // write-access to avoid SELinux denials
67 cgroup_root_path = 83 cgroup_root_path =
68 (access(MEM_CGROUP_TASKS, F_OK) || access(MEM_CGROUP_PATH, W_OK) ? ACCT_CGROUP_PATH 84 (access(MEM_CGROUP_TASKS, F_OK) || access(MEM_CGROUP_PATH, W_OK) ?
69 : MEM_CGROUP_PATH); 85 ACCT_CGROUP_PATH : MEM_CGROUP_PATH);
70 }); 86 } else {
87 cgroup_root_path = ACCT_CGROUP_PATH;
88 }
89 });
71 return cgroup_root_path; 90 return cgroup_root_path;
72} 91}
73 92