From 0ac96fcb1a17e22afd54c8fd6dd7b92576aef5c4 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Thu, 5 Oct 2023 00:51:14 +0000 Subject: [PATCH] lmkd: Kill cached apps when thrashing or below low watermark With Android U removing AMS kills, lmkd has additional duty to kill cached apps which previously were killed by AMS. The former logic is not proactive enough and leads to too many cached apps contributing to memory pressure. Implement additional logic to kill cached apps (excluding previous foreground apps) when low watermark is breached or when device is thrashing. Bug: 300660611 Change-Id: I356eac1fe6d44dad292a7ea2fadee69a5be61479 Signed-off-by: Suren Baghdasaryan --- lmkd.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lmkd.cpp b/lmkd.cpp index aa322cc..82f3e93 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -93,6 +93,7 @@ static inline void trace_kill_end() {} #define PROC_STATUS_SWAP_FIELD "VmSwap:" #define PERCEPTIBLE_APP_ADJ 200 +#define PREVIOUS_APP_ADJ 700 /* Android Logger event logtags (see event.logtags) */ #define KILLINFO_LOG_TAG 10195355 @@ -2847,6 +2848,15 @@ static void mp_event_psi(int data, uint32_t events, struct polling_params *poll_ } } + /* Check if a cached app should be killed */ + if (kill_reason == NONE && wmark < WMARK_HIGH) { + /* TODO: introduce a new kill reason */ + kill_reason = LOW_MEM_AND_SWAP; + snprintf(kill_desc, sizeof(kill_desc), "%s watermark is breached", + wmark < WMARK_LOW ? "min" : "low"); + min_score_adj = PREVIOUS_APP_ADJ + 1; + } + /* Kill a process if necessary */ if (kill_reason != NONE) { struct kill_info ki = {