diff options
author | Suren Baghdasaryan <surenb@google.com> | 2017-11-22 14:06:20 -0800 |
---|---|---|
committer | Suren Baghdasaryan <surenb@google.com> | 2018-01-17 13:41:53 -0800 |
commit | 597f95eae7813532d1b99d92c788a170e6bed25f (patch) | |
tree | 4ad38f14f5f6ee4376d71cc78584ce15b0cf26ee /alloc-stress | |
parent | 56bd5583793d804def283f2a1d7d2bf29b4aa1bf (diff) | |
download | extras-597f95eae7813532d1b99d92c788a170e6bed25f.tar.gz |
alloc-stress: memcg fixes and additional tracing option
Fix memcg paths according to the latest memcg mount points, print
children PIDs for easy tracing and add an option to trace lifetime
of the children.
Change-Id: Iced821ef28b6c36598ca872a7115738b813baa90
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Diffstat (limited to 'alloc-stress')
-rw-r--r-- | alloc-stress/alloc-stress.cpp | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/alloc-stress/alloc-stress.cpp b/alloc-stress/alloc-stress.cpp index 7b0e89f1..7fd42b44 100644 --- a/alloc-stress/alloc-stress.cpp +++ b/alloc-stress/alloc-stress.cpp @@ -15,6 +15,13 @@ #include <sys/wait.h> #include <unistd.h> +//#define TRACE_CHILD_LIFETIME + +#ifdef TRACE_CHILD_LIFETIME +#define ATRACE_TAG ATRACE_TAG_ALWAYS +#include <utils/Trace.h> +#endif // TRACE_CHILD_LIFETIME + using namespace std; #define ASSERT_TRUE(cond) \ @@ -102,7 +109,7 @@ public: } }; -void createProcess(Pipe pipe, const char *exName, const char *arg) +pid_t createProcess(Pipe pipe, const char *exName, const char *arg) { pipe.preserveOverFork(true); pid_t pid = fork(); @@ -118,11 +125,11 @@ void createProcess(Pipe pipe, const char *exName, const char *arg) // parent process else if (pid > 0) { pipe.preserveOverFork(false); - return; } else { ASSERT_TRUE(0); } + return pid; } @@ -153,18 +160,27 @@ static void write_oomadj_to_lmkd(int oomadj) { #ifdef ENABLE_MEM_CGROUPS static void create_memcg() { char buf[256]; + uid_t uid = getuid(); pid_t pid = getpid(); - snprintf(buf, sizeof(buf), "/dev/memctl/apps/%u", pid); + 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) { - cout << "Failed to create memory cgroup" << endl; + cerr << "Failed to create memory cgroup under " << buf << endl; return; } - snprintf(buf, sizeof(buf), "/dev/memctl/apps/%u/tasks", pid); + + snprintf(buf, sizeof(buf), "/dev/memcg/apps/uid_%u/pid_%u/tasks", uid, pid); tasks = open(buf, O_WRONLY); if (tasks < 0) { - cout << "Unable to add process to memory cgroup" << endl; + cerr << "Unable to add process to memory cgroup" << endl; return; } snprintf(buf, sizeof(buf), "%u", pid); @@ -206,11 +222,18 @@ int main(int argc, char *argv[]) for (int i = 1000; i >= 0; i -= 100) { auto pipes = Pipe::createPipePair(); char arg[16]; + pid_t ch_pid; snprintf(arg, sizeof(arg), "%d", i); - createProcess(std::move(std::get<1>(pipes)), argv[0], arg); + ch_pid = createProcess(std::move(std::get<1>(pipes)), argv[0], arg); Pipe &p = std::get<0>(pipes); size_t t = 0; + +#ifdef TRACE_CHILD_LIFETIME + char trace_str[64]; + snprintf(trace_str, sizeof(trace_str), "alloc-stress, adj=%d, pid=%u", i, ch_pid); + ATRACE_INT(trace_str, i); +#endif while (1) { //;cout << getpid() << ":" << "parent signal" << endl; p.signal(); @@ -221,7 +244,10 @@ int main(int argc, char *argv[]) } t += s; } - cout << "adj: " << i << " sz: " << t / (1 << 20) << endl; + cout << "pid: " << ch_pid << " adj: " << i << " sz: " << t / (1 << 20) << endl; +#ifdef TRACE_CHILD_LIFETIME + ATRACE_INT(trace_str, 0); +#endif } } return 0; |