From ffc1cc89f84675787ea0caac55e6198714f02420 Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Sat, 8 Feb 2020 03:21:01 -0800 Subject: [PATCH] simple_lmk: Ignore tasks that won't free memory Dying processes aren't going to help free memory, so ignore them. Signed-off-by: Sultan Alsawaf --- drivers/android/simple_lmk.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/android/simple_lmk.c b/drivers/android/simple_lmk.c index 224299997dd4..77695a763a05 100644 --- a/drivers/android/simple_lmk.c +++ b/drivers/android/simple_lmk.c @@ -77,18 +77,22 @@ static unsigned long find_victims(int *vindex, short target_adj) struct task_struct *tsk; for_each_process(tsk) { + struct signal_struct *sig; struct task_struct *vtsk; /* - * Search for tasks with the targeted importance (adj). Since - * only tasks with a positive adj can be targeted, that + * Search for suitable tasks with the targeted importance (adj). + * Since only tasks with a positive adj can be targeted, that * naturally excludes tasks which shouldn't be killed, like init * and kthreads. Although oom_score_adj can still be changed * while this code runs, it doesn't really matter. We just need * to make sure that if the adj changes, we won't deadlock * trying to lock a task that we locked earlier. */ - if (READ_ONCE(tsk->signal->oom_score_adj) != target_adj || + sig = tsk->signal; + if (READ_ONCE(sig->oom_score_adj) != target_adj || + sig->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP) || + (thread_group_empty(tsk) && tsk->flags & PF_EXITING) || vtsk_is_duplicate(*vindex, tsk)) continue;