From patchwork Fri Dec 16 22:00:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 9478561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E669601C2 for ; Fri, 16 Dec 2016 22:00:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F08A24EE5 for ; Fri, 16 Dec 2016 22:00:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 135D828658; Fri, 16 Dec 2016 22:00:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 632B324EE5 for ; Fri, 16 Dec 2016 22:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759232AbcLPWAj (ORCPT ); Fri, 16 Dec 2016 17:00:39 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34325 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756550AbcLPWAc (ORCPT ); Fri, 16 Dec 2016 17:00:32 -0500 Received: by mail-wm0-f68.google.com with SMTP id g23so7829112wme.1; Fri, 16 Dec 2016 14:00:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jzWz2B9vidZDdkgbYJ2oB0QrXq97nDQVYei1Evy8/Dg=; b=A/RBxDXC2zO/E3dUFmWI1aDXOcwI8FWmbNYVPJ5QnEO88cEtMeAQ0Ao5Vast0kzNCs iKwCFZVQA6q5b4Y3q3AkRpl9smP5y/uRY2B5BUS0OwsX/LYtk81UQswL4QQqLvC2MbnC V4tqL0t4EQlhkN/KTHalGzsQ2S+jYsrrXCUnCG73yPNPVxHPcFeT85ZUkLM9F2oyNMu4 NzTYqN0rSRUQdvgB3YYZZi8RPDIBTqEc2ivmmL+DuC4hrFVa1eIAHn5NjUFWtxOFIwTj eofsbo2/ZqFMe+y5fjIQtWXkzdnuNn8Xf5iZwQSRu5G/SkIDVheAL4dhtikHYT6u4qi4 OaZg== X-Gm-Message-State: AIkVDXJ447IqcLAJGejTihN0/O1unQ9D9gL6wKh3TAkutiVPDrlyTxmZBHF6Mp1tKNknxQ== X-Received: by 10.28.134.146 with SMTP id i140mr4993259wmd.100.1481925630069; Fri, 16 Dec 2016 14:00:30 -0800 (PST) Received: from localhost (ip-94-113-214-7.net.upcbroadband.cz. [94.113.214.7]) by smtp.gmail.com with ESMTPSA id bf2sm8578899wjc.48.2016.12.16.14.00.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Dec 2016 14:00:29 -0800 (PST) Date: Fri, 16 Dec 2016 23:00:28 +0100 From: Michal Hocko To: Brian Foster Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Dave Chinner , Theodore Ts'o , Chris Mason , David Sterba , Jan Kara , ceph-devel@vger.kernel.org, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, logfs@logfs.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mtd@lists.infradead.org, reiserfs-devel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-f2fs-devel@lists.sourceforge.net, linux-afs@lists.infradead.org, LKML Subject: [PATCH 5/9 v2] xfs: use memalloc_nofs_{save,restore} instead of memalloc_noio* Message-ID: <20161216220028.GB7645@dhcp22.suse.cz> References: <20161215140715.12732-1-mhocko@kernel.org> <20161215140715.12732-6-mhocko@kernel.org> <20161216163811.GG8447@bfoster.bfoster> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161216163811.GG8447@bfoster.bfoster> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri 16-12-16 11:38:11, Brian Foster wrote: > On Thu, Dec 15, 2016 at 03:07:11PM +0100, Michal Hocko wrote: [...] > > @@ -459,7 +459,7 @@ _xfs_buf_map_pages( > > break; > > vm_unmap_aliases(); > > } while (retried++ <= 1); > > - memalloc_noio_restore(noio_flag); > > + memalloc_noio_restore(nofs_flag); > > memalloc_nofs_restore() ? Ups, you are right of course. Fixed. --- From 47826112e59014030ffe27a673c1b1de345dd9de Mon Sep 17 00:00:00 2001 From: Michal Hocko Date: Thu, 15 Dec 2016 13:10:53 +0100 Subject: [PATCH] xfs: use memalloc_nofs_{save,restore} instead of memalloc_noio* kmem_zalloc_large and _xfs_buf_map_pages use memalloc_noio_{save,restore} API to prevent from reclaim recursion into the fs because vmalloc can invoke unconditional GFP_KERNEL allocations and these functions might be called from the NOFS contexts. The memalloc_noio_save will enforce GFP_NOIO context which is even weaker than GFP_NOFS and that seems to be unnecessary. Let's use memalloc_nofs_{save,restore} instead as it should provide exactly what we need here - implicit GFP_NOFS context. Changes since v1 - s@memalloc_noio_restore@memalloc_nofs_restore@ in _xfs_buf_map_pages as per Brian Foster Signed-off-by: Michal Hocko --- fs/xfs/kmem.c | 10 +++++----- fs/xfs/xfs_buf.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c index a76a05dae96b..d69ed5e76621 100644 --- a/fs/xfs/kmem.c +++ b/fs/xfs/kmem.c @@ -65,7 +65,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags) void * kmem_zalloc_large(size_t size, xfs_km_flags_t flags) { - unsigned noio_flag = 0; + unsigned nofs_flag = 0; void *ptr; gfp_t lflags; @@ -80,14 +80,14 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) * context via PF_MEMALLOC_NOIO to prevent memory reclaim re-entering * the filesystem here and potentially deadlocking. */ - if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS)) - noio_flag = memalloc_noio_save(); + if (flags & KM_NOFS) + nofs_flag = memalloc_nofs_save(); lflags = kmem_flags_convert(flags); ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); - if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS)) - memalloc_noio_restore(noio_flag); + if (flags & KM_NOFS) + memalloc_nofs_restore(nofs_flag); return ptr; } diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index f31ae592dcae..e9eec256056c 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -441,17 +441,17 @@ _xfs_buf_map_pages( bp->b_addr = NULL; } else { int retried = 0; - unsigned noio_flag; + unsigned nofs_flag; /* * vm_map_ram() will allocate auxillary structures (e.g. * pagetables) with GFP_KERNEL, yet we are likely to be under * GFP_NOFS context here. Hence we need to tell memory reclaim - * that we are in such a context via PF_MEMALLOC_NOIO to prevent + * that we are in such a context via PF_MEMALLOC_NOFS to prevent * memory reclaim re-entering the filesystem here and * potentially deadlocking. */ - noio_flag = memalloc_noio_save(); + nofs_flag = memalloc_nofs_save(); do { bp->b_addr = vm_map_ram(bp->b_pages, bp->b_page_count, -1, PAGE_KERNEL); @@ -459,7 +459,7 @@ _xfs_buf_map_pages( break; vm_unmap_aliases(); } while (retried++ <= 1); - memalloc_noio_restore(noio_flag); + memalloc_nofs_restore(nofs_flag); if (!bp->b_addr) return -ENOMEM;