summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@google.com>2022-03-22 21:42:19 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-03-22 21:42:19 +0000
commitd92ed273a1a8c726e6c435c892f0be7de2625e03 (patch)
treeae178146bf6f2a90336aeb7d82ff9b105c974411
parent650bcb90583af04b5c201dad8044013807b14b74 (diff)
parentff3d9f7746ddb057f7fdc0bb235d37465bf23022 (diff)
downloadextras-d92ed273a1a8c726e6c435c892f0be7de2625e03.tar.gz
Merge "Use createProcessGroup() from libprocessgroup" am: 49dc2148a1 am: ff3d9f7746
Original change: https://android-review.googlesource.com/c/platform/system/extras/+/1971549 Change-Id: I5a30b54781ccd5d3b7e9ba7255dc626cbdee5823
-rw-r--r--alloc-stress/Android.bp1
-rw-r--r--alloc-stress/alloc-stress.cpp34
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]));