From patchwork Wed Aug 5 09:51:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 6947531 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 542219F358 for ; Wed, 5 Aug 2015 09:56:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 782212047B for ; Wed, 5 Aug 2015 09:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 754B92034A for ; Wed, 5 Aug 2015 09:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbbHEJvv (ORCPT ); Wed, 5 Aug 2015 05:51:51 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:35587 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752450AbbHEJvs (ORCPT ); Wed, 5 Aug 2015 05:51:48 -0400 Received: by wibxm9 with SMTP id xm9so200908611wib.0; Wed, 05 Aug 2015 02:51:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/pWPwJ29iTeb/HfDjMqd+M9Jsnq+g7nuV2T8l2SaIdw=; b=g3GIcOiVZGj33uYgAkr+DXdHsaPsJK9lXoooC0fap6hCpC6w5Nen3dUTf/GQBjCZV+ 3zsmK5VP+R1Lhbpd7l493YZUlxYhsxAhemzrrz7eBhiTGXT04O/zqguLaOwSqErH5RWY wLXa0OXzDS8hL1SxWemzHNVHIaenyNkYQ7HwW6SnqMFjSLozu8VJVQ+HR37TVDw1FZTg 91rlNKNrCQe7xem58NBwrVUjzGFwCxevLRtdzMQi9IQ9NQ6o43aj6BQmwcHQ6jkhehXz V6j7qUZ4KhvbiQonYRn2eHuu2ogk7rq8rEJXoqmJkFn88sDEsGnr9UFhufgx64b5BlsI Ihmw== X-Received: by 10.194.172.8 with SMTP id ay8mr18026136wjc.106.1438768306983; Wed, 05 Aug 2015 02:51:46 -0700 (PDT) Received: from tiehlicka.suse.cz (nat1.scz.suse.com. [213.151.88.250]) by smtp.gmail.com with ESMTPSA id yu4sm3229106wjc.43.2015.08.05.02.51.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Aug 2015 02:51:46 -0700 (PDT) From: mhocko@kernel.org To: LKML Cc: , , Andrew Morton , Johannes Weiner , Tetsuo Handa , Dave Chinner , "Theodore Ts'o" , linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, Jan Kara , Michal Hocko Subject: [RFC 1/8] mm, oom: Give __GFP_NOFAIL allocations access to memory reserves Date: Wed, 5 Aug 2015 11:51:17 +0200 Message-Id: <1438768284-30927-2-git-send-email-mhocko@kernel.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438768284-30927-1-git-send-email-mhocko@kernel.org> References: <1438768284-30927-1-git-send-email-mhocko@kernel.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 From: Michal Hocko __GFP_NOFAIL is a big hammer used to ensure that the allocation request can never fail. This is a strong requirement and as such it also deserves a special treatment when the system is OOM. The primary problem here is that the allocation request might have come with some locks held and the oom victim might be blocked on the same locks. This is basically an OOM deadlock situation. This patch tries to reduce the risk of such a deadlocks by giving __GFP_NOFAIL allocations a special treatment and let them dive into memory reserves after oom killer invocation. This should help them to make a progress and release resources they are holding. The OOM victim should compensate for the reserves consumption. Signed-off-by: Michal Hocko --- mm/page_alloc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1f9ffbb087cb..ee69c338ca2a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2732,8 +2732,16 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, } /* Exhausted what can be done so it's blamo time */ if (out_of_memory(ac->zonelist, gfp_mask, order, ac->nodemask, false) - || WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) + || WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) { *did_some_progress = 1; + + if (gfp_mask & __GFP_NOFAIL) { + page = get_page_from_freelist(gfp_mask, order, + ALLOC_NO_WATERMARKS|ALLOC_CPUSET, ac); + WARN_ONCE(!page, "Unable to fullfil gfp_nofail allocation." + " Consider increasing min_free_kbytes.\n"); + } + } out: mutex_unlock(&oom_lock); return page;