Return-Path: Received: from mx2.suse.de ([195.135.220.15]:52372 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731471AbeGSQ2t (ORCPT ); Thu, 19 Jul 2018 12:28:49 -0400 Date: Thu, 19 Jul 2018 17:44:53 +0200 From: David Sterba To: Nikolay Borisov Cc: Josef Bacik , linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 10/22] btrfs: alloc space cache inode with GFP_NOFS Message-ID: <20180719154453.GV26141@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20180719145006.17532-1-josef@toxicpanda.com> <20180719145006.17532-10-josef@toxicpanda.com> <3e617a5c-03d7-5937-fbe1-e067c5b8d5ee@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <3e617a5c-03d7-5937-fbe1-e067c5b8d5ee@suse.com> Sender: linux-btrfs-owner@vger.kernel.org List-ID: On Thu, Jul 19, 2018 at 06:35:33PM +0300, Nikolay Borisov wrote: > > > On 19.07.2018 17:49, Josef Bacik wrote: > > If we're allocating a new space cache inode it's likely going to be > > under a transaction handle, so we need to use GFP_NOFS to keep from > > deadlocking. Otherwise GFP_KERNEL is fine. > > > > Signed-off-by: Josef Bacik > > --- > > fs/btrfs/free-space-cache.c | 5 +++++ > > fs/btrfs/inode.c | 3 ++- > > fs/btrfs/transaction.h | 1 + > > 3 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > > index d5f80cb300be..13bc514e4e16 100644 > > --- a/fs/btrfs/free-space-cache.c > > +++ b/fs/btrfs/free-space-cache.c > > @@ -68,7 +68,12 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, > > btrfs_disk_key_to_cpu(&location, &disk_key); > > btrfs_release_path(path); > > > > + /* We need this set so that we use GFP_NOFS when allocating our inode. */ > > + if (current->journal_info == NULL) > > + current->journal_info = BTRFS_TRANS_STUB; > > inode = btrfs_iget(fs_info->sb, &location, root, NULL); > > + if (current->journal_info == BTRFS_TRANS_STUB) > > + current->journal_info = NULL; > This is not safe in the face of stacked filesystem, i.e ext4 uses the > journal_info. > > > if (IS_ERR(inode)) > > return inode; > > if (is_bad_inode(inode)) { > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > > index eba61bcb9bb3..14ecfe5d6110 100644 > > --- a/fs/btrfs/inode.c > > +++ b/fs/btrfs/inode.c > > @@ -9211,8 +9211,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) > > struct btrfs_fs_info *fs_info = btrfs_sb(sb); > > struct btrfs_inode *ei; > > struct inode *inode; > > + gfp_t flags = (current->journal_info) ? GFP_NOFS : GFP_KERNEL; > > > > - ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_KERNEL); > > + ei = kmem_cache_alloc(btrfs_inode_cachep, flags); > > Why don't you just hardcode GFP_NOFS? We should be striving at removing > abuse of ->journal_info than proliferating it. We're also removing unnecessary use of GFP_NOFS. The right way here is to use memalloc_nofs_save/memalloc_nofs_restore around btrfs_iget.