From c2e05b6ffa8bc24b6ec7688d2b46993dba5e3a1e Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Wed, 4 Sep 2019 16:44:47 -0700 Subject: [PATCH] lmkd: Fix kill failure handling When lmkd fails to kill it should log the error, remove the process record and exit immediately. Bug: 74119935 Test: lmkd_unit_test Change-Id: I26b0fd873eeed325f7dd56097ec31abc0d63f3a1 Signed-off-by: Suren Baghdasaryan --- lmkd.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lmkd.c b/lmkd.c index 2ba3f44..661fd8b 100644 --- a/lmkd.c +++ b/lmkd.c @@ -1793,6 +1793,14 @@ static int kill_one_process(struct proc* procp, int min_oom_score, const char *r /* CAP_KILL required */ r = kill(pid, SIGKILL); + TRACE_KILL_END(); + + if (r) { + ALOGE("kill(%d): errno=%d", pid, errno); + /* Delete process record even when we fail to kill so that we don't get stuck on it */ + goto out; + } + set_process_group_and_prio(pid, SP_FOREGROUND, ANDROID_PRIORITY_HIGHEST); inc_killcnt(procp->oomadj); @@ -1804,28 +1812,21 @@ static int kill_one_process(struct proc* procp, int min_oom_score, const char *r uid, procp->oomadj, tasksize * page_k); } - TRACE_KILL_END(); - last_killed_pid = pid; - if (r) { - ALOGE("kill(%d): errno=%d", pid, errno); - goto out; - } else { #ifdef LMKD_LOG_STATS - if (memory_stat_parse_result == 0) { - stats_write_lmk_kill_occurred(log_ctx, LMK_KILL_OCCURRED, uid, taskname, - procp->oomadj, mem_st.pgfault, mem_st.pgmajfault, mem_st.rss_in_bytes, - mem_st.cache_in_bytes, mem_st.swap_in_bytes, mem_st.process_start_time_ns, - min_oom_score); - } else if (enable_stats_log) { - stats_write_lmk_kill_occurred(log_ctx, LMK_KILL_OCCURRED, uid, taskname, procp->oomadj, - -1, -1, tasksize * BYTES_IN_KILOBYTE, -1, -1, -1, - min_oom_score); - } -#endif - result = tasksize; + if (memory_stat_parse_result == 0) { + stats_write_lmk_kill_occurred(log_ctx, LMK_KILL_OCCURRED, uid, taskname, + procp->oomadj, mem_st.pgfault, mem_st.pgmajfault, mem_st.rss_in_bytes, + mem_st.cache_in_bytes, mem_st.swap_in_bytes, mem_st.process_start_time_ns, + min_oom_score); + } else if (enable_stats_log) { + stats_write_lmk_kill_occurred(log_ctx, LMK_KILL_OCCURRED, uid, taskname, procp->oomadj, + -1, -1, tasksize * BYTES_IN_KILOBYTE, -1, -1, -1, + min_oom_score); } +#endif + result = tasksize; out: /*