From 4311d1ed36902b301f91f60ab2643ee82cf779e0 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Tue, 20 Mar 2018 16:03:29 -0700 Subject: [PATCH] lmkd: Suppress error when accessing soft_limit_in_bytes for system_server system_server needs to register with lmkd, however it has no memory cgroup under /dev/memcg/apps. This change detects if the process being registered is system_server and suppresses the error message when /dev/memcg/apps/uid_%d/pid_%d/memory.soft_limit_in_bytes file can't be accessed. Bug: 73483785 Test: verified logcat output Change-Id: I03df7831f41f512ac8d3ebc46330546d08a3cbc6 --- lmkd/lmkd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c index 8dd4587ba..916317820 100644 --- a/lmkd/lmkd.c +++ b/lmkd/lmkd.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -72,6 +73,9 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) #define EIGHT_MEGA (1 << 23) +/* Defined as ProcessList.SYSTEM_ADJ in ProcessList.java */ +#define SYSTEM_ADJ (-900) + /* default to old in-kernel interface if no memory pressure events */ static int use_inkernel_interface = 1; static bool has_inkernel_module; @@ -302,6 +306,8 @@ static void cmd_procprio(LMKD_CTRL_PACKET packet) { char val[20]; int soft_limit_mult; struct lmk_procprio params; + bool is_system_server; + struct passwd *pwdrec; lmkd_pack_get_procprio(packet, ¶ms); @@ -355,7 +361,15 @@ static void cmd_procprio(LMKD_CTRL_PACKET packet) { "/dev/memcg/apps/uid_%d/pid_%d/memory.soft_limit_in_bytes", params.uid, params.pid); snprintf(val, sizeof(val), "%d", soft_limit_mult * EIGHT_MEGA); - writefilestring(path, val, true); + + /* + * system_server process has no memcg under /dev/memcg/apps but should be + * registered with lmkd. This is the best way so far to identify it. + */ + is_system_server = (params.oomadj == SYSTEM_ADJ && + (pwdrec = getpwnam("system")) != NULL && + params.uid == pwdrec->pw_uid); + writefilestring(path, val, !is_system_server); procp = pid_lookup(params.pid); if (!procp) {