diff options
author | Bart Van Assche <bvanassche@google.com> | 2022-02-02 22:32:48 +0000 |
---|---|---|
committer | Bart Van Assche <bvanassche@google.com> | 2022-03-21 16:02:51 -0700 |
commit | 9b6a2cba83eac190da1e0a1d983302ea94eea776 (patch) | |
tree | ae178146bf6f2a90336aeb7d82ff9b105c974411 /alloc-stress | |
parent | 59f0820b83f0291b86207f37a0edb9ff944f159d (diff) | |
download | extras-9b6a2cba83eac190da1e0a1d983302ea94eea776.tar.gz |
Use createProcessGroup() from libprocessgroup
This patch prepares for migration of memcg to the v2 cgroup hierarchy by
removing code that hardcodes cgroup paths that will change as the result
of this migration.
Bug: 213617178
Test: Ran alloc-stress inside Cuttlefish.
Change-Id: Ib783d4b619250a2e90db5062cb32110e9f042c5f
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Diffstat (limited to 'alloc-stress')
-rw-r--r-- | alloc-stress/Android.bp | 1 | ||||
-rw-r--r-- | alloc-stress/alloc-stress.cpp | 34 |
2 files changed, 4 insertions, 31 deletions
diff --git a/alloc-stress/Android.bp b/alloc-stress/Android.bp index 4d74841a..e64c822b 100644 --- a/alloc-stress/Android.bp +++ b/alloc-stress/Android.bp @@ -24,6 +24,7 @@ cc_binary { shared_libs: [ "libhardware", "libcutils", + "libprocessgroup", ], cppflags: [ "-g", diff --git a/alloc-stress/alloc-stress.cpp b/alloc-stress/alloc-stress.cpp index 33c12635..ad2353cc 100644 --- a/alloc-stress/alloc-stress.cpp +++ b/alloc-stress/alloc-stress.cpp @@ -14,6 +14,8 @@ #include <tuple> #include <vector> +#include <processgroup/processgroup.h> + //#define TRACE_CHILD_LIFETIME #ifdef TRACE_CHILD_LIFETIME @@ -157,36 +159,6 @@ static void write_oomadj_to_lmkd(int oomadj) { cout << "Wrote " << written << " bytes to lmkd control socket." << endl; } -static void create_memcg() { - char buf[256]; - uid_t uid = getuid(); - pid_t pid = getpid(); - - snprintf(buf, sizeof(buf), "/dev/memcg/apps/uid_%u", uid); - int tasks = mkdir(buf, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (tasks < 0 && errno != EEXIST) { - cerr << "Failed to create memory cgroup under " << buf << endl; - return; - } - - snprintf(buf, sizeof(buf), "/dev/memcg/apps/uid_%u/pid_%u", uid, pid); - tasks = mkdir(buf, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (tasks < 0) { - cerr << "Failed to create memory cgroup under " << buf << endl; - return; - } - - snprintf(buf, sizeof(buf), "/dev/memcg/apps/uid_%u/pid_%u/tasks", uid, pid); - tasks = open(buf, O_WRONLY); - if (tasks < 0) { - cerr << "Unable to add process to memory cgroup" << endl; - return; - } - snprintf(buf, sizeof(buf), "%u", pid); - write(tasks, buf, strlen(buf)); - close(tasks); -} - void usage() { cout << "Application allocates memory until it's killed." << endl << "It starts at max oom_score_adj and gradually " @@ -202,7 +174,7 @@ int main(int argc, char* argv[]) { if ((argc > 1) && (std::string(argv[1]) == "--worker")) { if (std::string(argv[5]) == "1") { - create_memcg(); + createProcessGroup(getuid(), getpid(), true); } write_oomadj_to_lmkd(atoi(argv[2])); |