From 7afa46397875f76fa0eb9576872c7ab3e2895844 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Tue, 19 May 2020 12:59:18 -0700 Subject: [PATCH] lmkd: Do not kill perceptible apps due to low swap if above min wmark Prevent kills of perceptible apps due to swap shortages unless system free memory is below the min watermark. This prevents kills of important apps when the system is recovering from the memory pressure. Bug: 155709603 Test: memory stress test with multiple foreground apps Signed-off-by: Suren Baghdasaryan Merged-In: I6beb4b55f8b4f7bc22818b5a7bdfa3adc6cd31c1 Change-Id: I6beb4b55f8b4f7bc22818b5a7bdfa3adc6cd31c1 --- lmkd.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lmkd.cpp b/lmkd.cpp index 100b92e..098fe9f 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -2386,12 +2386,20 @@ static void mp_event_psi(int data, uint32_t events, struct polling_params *poll_ snprintf(kill_desc, sizeof(kill_desc), "device is low on swap (%" PRId64 "kB < %" PRId64 "kB) and thrashing (%" PRId64 "%%)", mi.field.free_swap * page_k, swap_low_threshold * page_k, thrashing); + /* Do not kill perceptible apps unless below min watermark */ + if (wmark < WMARK_LOW) { + min_score_adj = PERCEPTIBLE_APP_ADJ + 1; + } } else if (swap_is_low && wmark < WMARK_HIGH) { /* Both free memory and swap are low */ kill_reason = LOW_MEM_AND_SWAP; snprintf(kill_desc, sizeof(kill_desc), "%s watermark is breached and swap is low (%" PRId64 "kB < %" PRId64 "kB)", wmark > WMARK_LOW ? "min" : "low", mi.field.free_swap * page_k, swap_low_threshold * page_k); + /* Do not kill perceptible apps unless below min watermark */ + if (wmark < WMARK_LOW) { + min_score_adj = PERCEPTIBLE_APP_ADJ + 1; + } } else if (wmark < WMARK_HIGH && thrashing > thrashing_limit) { /* Page cache is thrashing while memory is low */ kill_reason = LOW_MEM_AND_THRASHING;