From patchwork Thu Mar 26 11:51:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 6098081 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0835BBF90F for ; Thu, 26 Mar 2015 11:51:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 18354203F1 for ; Thu, 26 Mar 2015 11:51:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED27C203EC for ; Thu, 26 Mar 2015 11:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752153AbbCZLvn (ORCPT ); Thu, 26 Mar 2015 07:51:43 -0400 Received: from cantor2.suse.de ([195.135.220.15]:36228 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751025AbbCZLvm (ORCPT ); Thu, 26 Mar 2015 07:51:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BC903ABA2; Thu, 26 Mar 2015 11:51:40 +0000 (UTC) Date: Thu, 26 Mar 2015 12:51:40 +0100 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 01/12] mm: oom_kill: remove unnecessary locking in oom_enable() Message-ID: <20150326115140.GC15257@dhcp22.suse.cz> References: <1427264236-17249-1-git-send-email-hannes@cmpxchg.org> <1427264236-17249-2-git-send-email-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed 25-03-15 17:51:31, David Rientjes wrote: > On Wed, 25 Mar 2015, Johannes Weiner wrote: > > > Setting oom_killer_disabled to false is atomic, there is no need for > > further synchronization with ongoing allocations trying to OOM-kill. > > > > Signed-off-by: Johannes Weiner > > --- > > mm/oom_kill.c | 2 -- > > 1 file changed, 2 deletions(-) > > > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > > index 2b665da1b3c9..73763e489e86 100644 > > --- a/mm/oom_kill.c > > +++ b/mm/oom_kill.c > > @@ -488,9 +488,7 @@ bool oom_killer_disable(void) > > */ > > void oom_killer_enable(void) > > { > > - down_write(&oom_sem); > > oom_killer_disabled = false; > > - up_write(&oom_sem); > > } > > > > #define K(x) ((x) << (PAGE_SHIFT-10)) > > I haven't looked through the new disable-oom-killer-for-pm patchset that > was merged, but this oom_killer_disabled thing already looks improperly > handled. I think any correctness or cleanups in this area would be very > helpful. > > I think mark_tsk_oom_victim() in mem_cgroup_out_of_memory() is just > luckily not racing with a call to oom_killer_enable() and triggering the ^^^^^^^^^^ oom_killer_disable? > WARN_ON(oom_killer_disabled) since there's no "oom_sem" held here, and > it's an improper context based on the comment of mark_tsk_oom_victim(). OOM killer is disabled only _after_ all user tasks have been frozen. So we cannot get any page fault and a race. So the semaphore is not needed in this path although the comment says otherwise. I can add a comment clarifying this... --- > There might be something else that is intended but not implemented > correctly that I'm unaware of, but I know of no reason why setting of > oom_killer_disabled would need to take a semaphore? > > I'm thinking it has something to do with the remainder of that comment, > specifically the "never after oom has been disabled already." > > Michal? diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 14c2f2017e37..20828ecaf3ba 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1536,6 +1536,11 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, * quickly exit and free its memory. */ if (fatal_signal_pending(current) || task_will_free_mem(current)) { + /* + * We do not hold oom_sem in this path because we know + * we cannot race with oom_kill_disable(). No user runable + * tasks are allowed at the time oom_kill_disable is called. + */ mark_tsk_oom_victim(current); return; }