From d256df3c5fd4e6785e72297f46a8dc2cbffc21a7 Mon Sep 17 00:00:00 2001 From: David Stevens Date: Fri, 23 Aug 2024 15:08:21 +0900 Subject: [PATCH] lmkd: Add hook for when there are no killable processes Add a hook that is invoked when there are no killable processes at any priority. This allows ARCVM to send VMMMS's no kill candidates message, which prevents thrashing without having to wait on a balloon stall. Bug: 362383831 Test: cq Change-Id: Iffb680a78025bd201932bd805ceeecfe07b1fac9 --- include/lmkd_hooks.h | 6 ++++++ lmkd.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/include/lmkd_hooks.h b/include/lmkd_hooks.h index 259a3fd..1656ea6 100644 --- a/include/lmkd_hooks.h +++ b/include/lmkd_hooks.h @@ -50,6 +50,11 @@ bool lmkd_init_hook(); */ int lmkd_free_memory_before_kill_hook(struct proc* procp, int proc_size_pages, int proc_oom_score, int kill_reason); +/* + * Invoked when LMKD has no more candidates to kill at any priority. The hook + * may attempt to free memory elsewhere to try to preserve system stability. + */ +void lmkd_no_kill_candidates_hook(); #else /* LMKD_USE_HOOKS */ @@ -59,6 +64,7 @@ static inline int lmkd_free_memory_before_kill_hook(struct proc*, int, int, int) { return 0; } +static inline void lmkd_no_kill_candidates_hook() {} #endif /* LMKD_USE_HOOKS */ diff --git a/lmkd.cpp b/lmkd.cpp index 44dde3a..1030147 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -3248,6 +3248,10 @@ do_kill: pages_freed = find_and_kill_process(min_score_adj, NULL, &mi, &wi, &curr_tm, NULL); + if (pages_freed == 0 && min_score_adj == 0) { + lmkd_no_kill_candidates_hook(); + } + if (pages_freed == 0) { /* Rate limit kill reports when nothing was reclaimed */ if (get_time_diff_ms(&last_report_tm, &curr_tm) < FAIL_REPORT_RLIMIT_MS) {