From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by kanga.kvack.org (Postfix) with ESMTP id D87D56B0009 for ; Fri, 29 Jan 2016 10:32:52 -0500 (EST) Received: by mail-wm0-f45.google.com with SMTP id p63so73084570wmp.1 for ; Fri, 29 Jan 2016 07:32:52 -0800 (PST) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com. [74.125.82.66]) by mx.google.com with ESMTPS id lu1si18374687wjb.170.2016.01.29.07.32.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jan 2016 07:32:51 -0800 (PST) Received: by mail-wm0-f66.google.com with SMTP id l66so10516131wml.2 for ; Fri, 29 Jan 2016 07:32:51 -0800 (PST) Date: Fri, 29 Jan 2016 16:32:50 +0100 From: Michal Hocko Subject: Re: [PATCH 4/3] mm, oom: drop the last allocation attempt before out_of_memory Message-ID: <20160129153250.GH32174@dhcp22.suse.cz> References: <1450203586-10959-1-git-send-email-mhocko@kernel.org> <1454013603-3682-1-git-send-email-mhocko@kernel.org> <20160128213634.GA4903@cmpxchg.org> <20160128235110.GA5805@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160128235110.GA5805@cmpxchg.org> Sender: owner-linux-mm@kvack.org List-ID: To: Johannes Weiner Cc: David Rientjes , Andrew Morton , Linus Torvalds , Mel Gorman , Tetsuo Handa , Hillf Danton , KAMEZAWA Hiroyuki , linux-mm@kvack.org, LKML On Thu 28-01-16 18:51:10, Johannes Weiner wrote: > On Thu, Jan 28, 2016 at 03:19:08PM -0800, David Rientjes wrote: > > On Thu, 28 Jan 2016, Johannes Weiner wrote: > > > > > The check has to happen while holding the OOM lock, otherwise we'll > > > end up killing much more than necessary when there are many racing > > > allocations. > > > > > > > Right, we need to try with ALLOC_WMARK_HIGH after oom_lock has been > > acquired. > > > > The situation is still somewhat fragile, however, but I think it's > > tangential to this patch series. If the ALLOC_WMARK_HIGH allocation fails > > because an oom victim hasn't freed its memory yet, and then the TIF_MEMDIE > > thread isn't visible during the oom killer's tasklist scan because it has > > exited, we still end up killing more than we should. The likelihood of > > this happening grows with the length of the tasklist. > > > > Perhaps we should try testing watermarks after a victim has been selected > > and immediately before killing? (Aside: we actually carry an internal > > patch to test mem_cgroup_margin() in the memcg oom path after selecting a > > victim because we have been hit with this before in the memcg path.) > > > > I would think that retrying with ALLOC_WMARK_HIGH would be enough memory > > to deem that we aren't going to immediately reenter an oom condition so > > the deferred killing is a waste of time. > > > > The downside is how sloppy this would be because it's blurring the line > > between oom killer and page allocator. We'd need the oom killer to return > > the selected victim to the page allocator, try the allocation, and then > > call oom_kill_process() if necessary. > > https://lkml.org/lkml/2015/3/25/40 > > We could have out_of_memory() wait until the number of outstanding OOM > victims drops to 0. Then __alloc_pages_may_oom() doesn't relinquish > the lock until its kill has been finalized: > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 914451a..4dc5b9d 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -892,7 +892,9 @@ bool out_of_memory(struct oom_control *oc) > * Give the killed process a good chance to exit before trying > * to allocate memory again. > */ > - schedule_timeout_killable(1); > + if (!test_thread_flag(TIF_MEMDIE)) > + wait_event_timeout(oom_victims_wait, > + !atomic_read(&oom_victims), HZ); > } > return true; > } Yes this makes sense to me -- Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org