Hello. Should selected_tasksize be added to rem even when TIF_MEMDIE was not set? Please see a thread from http://www.spinics.net/lists/linux-mm/msg93246.html if you want to know why to reverse the order. ---------------------------------------- >From 2d4cc11d8128e4c1397631b91fea78da3eaefb47 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Date: Wed, 26 Aug 2015 20:52:39 +0900 Subject: [PATCH 2/2] android, lmk: Reverse the order of setting TIF_MEMDIE and sending SIGKILL. If we set TIF_MEMDIE before sending SIGKILL, memory reserves could be spent for allocations which are not needed for terminating the victim. Reverse the order as with oom_kill_process() does. Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/android/lowmemorykiller.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c index d5d25e4..c39b6a2 100644 --- a/drivers/staging/android/lowmemorykiller.c +++ b/drivers/staging/android/lowmemorykiller.c @@ -156,26 +156,24 @@ next: } if (selected) { task_lock(selected); - if (!selected->mm) { - /* Already exited, cannot do mark_tsk_oom_victim() */ - task_unlock(selected); - goto out; - } + lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n", + selected->pid, selected->comm, + selected_oom_score_adj, selected_tasksize); + task_unlock(selected); + send_sig(SIGKILL, selected, 0); /* * FIXME: lowmemorykiller shouldn't abuse global OOM killer * infrastructure. There is no real reason why the selected * task should have access to the memory reserves. */ - mark_oom_victim(selected); - lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n", - selected->pid, selected->comm, - selected_oom_score_adj, selected_tasksize); + task_lock(selected); + if (selected->mm) { + mark_oom_victim(selected); + lowmem_deathpending_timeout = jiffies + HZ; + rem += selected_tasksize; + } task_unlock(selected); - lowmem_deathpending_timeout = jiffies + HZ; - send_sig(SIGKILL, selected, 0); - rem += selected_tasksize; } -out: lowmem_print(4, "lowmem_scan %lu, %x, return %lu\n", sc->nr_to_scan, sc->gfp_mask, rem); rcu_read_unlock(); -- 1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>