summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libprocessgroup/processgroup.cpp')
-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