From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753797AbbC3OsK (ORCPT ); Mon, 30 Mar 2015 10:48:10 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35862 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753262AbbC3OsI (ORCPT ); Mon, 30 Mar 2015 10:48:08 -0400 Date: Mon, 30 Mar 2015 16:48:04 +0200 From: Michal Hocko To: David Rientjes Cc: Johannes Weiner , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Andrew Morton , Tetsuo Handa , Huang Ying , Andrea Arcangeli , Dave Chinner , "Theodore Ts'o" Subject: Re: [patch 03/12] mm: oom_kill: switch test-and-clear of known TIF_MEMDIE to clear Message-ID: <20150330144804.GD3909@dhcp22.suse.cz> References: <1427264236-17249-1-git-send-email-hannes@cmpxchg.org> <1427264236-17249-4-git-send-email-hannes@cmpxchg.org> <20150326110532.GB18560@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 26-03-15 12:50:20, David Rientjes wrote: [...] > android, lmk: avoid setting TIF_MEMDIE if process has already exited > > TIF_MEMDIE should not be set on a process if it does not have a valid > ->mm, and this is protected by task_lock(). > > If TIF_MEMDIE gets set after the mm has detached, and the process fails to > exit, then the oom killer will defer forever waiting for it to exit. > > Make sure that the mm is still valid before setting TIF_MEMDIE by way of > mark_tsk_oom_victim(). I would prefer if lmk didn't abuse mark_tsk_oom_victim much more. But this is correct as well. > Signed-off-by: David Rientjes Acked-by: Michal Hocko > --- > diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c > --- a/drivers/staging/android/lowmemorykiller.c > +++ b/drivers/staging/android/lowmemorykiller.c > @@ -156,20 +156,27 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) > p->pid, p->comm, oom_score_adj, tasksize); > } > if (selected) { > - lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n", > - selected->pid, selected->comm, > - selected_oom_score_adj, selected_tasksize); > - lowmem_deathpending_timeout = jiffies + HZ; > + task_lock(selected); > + if (!selected->mm) { > + /* Already exited, cannot do mark_tsk_oom_victim() */ > + task_unlock(selected); > + goto out; > + } > /* > * 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_tsk_oom_victim(selected); > + task_unlock(selected); > + lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n", > + selected->pid, selected->comm, > + selected_oom_score_adj, selected_tasksize); > + 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(); -- Michal Hocko SUSE Labs