From: Dennis Zhou <dennis@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: fdmanana@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, dennis@kernel.org, tj@kernel.org,
cl@linux.com, linux-btrfs@vger.kernel.org,
Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH] percpu: make pcpu_alloc() aware of current gfp context
Date: Thu, 30 Apr 2020 22:23:47 +0000 [thread overview]
Message-ID: <20200430222347.GA164259@google.com> (raw)
In-Reply-To: <20200430144018.c855f031b321d68e5c89b30c@linux-foundation.org>
On Thu, Apr 30, 2020 at 02:40:18PM -0700, Andrew Morton wrote:
> On Thu, 30 Apr 2020 17:43:56 +0100 fdmanana@kernel.org wrote:
>
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > Since 5.7-rc1, on btrfs we have a percpu counter initialization for which
> > we always pass a GFP_KERNEL gfp_t argument (this happens since commit
> > 2992df73268f78 ("btrfs: Implement DREW lock")). That is safe in some
> > contextes but not on others where allowing fs reclaim could lead to a
> > deadlock because we are either holding some btrfs lock needed for a
> > transaction commit or holding a btrfs transaction handle open. Because
> > of that we surround the call to the function that initializes the percpu
> > counter with a NOFS context using memalloc_nofs_save() (this is done at
> > btrfs_init_fs_root()).
> >
> > However it turns out that this is not enough to prevent a possible
> > deadlock because percpu_alloc() determines if it is in an atomic context
> > by looking exclusively at the gfp flags passed to it (GFP_KERNEL in this
> > case) and it is not aware that a NOFS context is set. Because it thinks
> > it is in a non atomic context it locks the pcpu_alloc_mutex, which can
> > result in a btrfs deadlock when pcpu_balance_workfn() is running, has
> > acquired that mutex and is waiting for reclaim, while the btrfs task that
> > called percpu_counter_init() (and therefore percpu_alloc()) is holding
> > either the btrfs commit_root semaphore or a transaction handle (done at
> > fs/btrfs/backref.c:iterate_extent_inodes()), which prevents reclaim from
> > finishing as an attempt to commit the current btrfs transaction will
> > deadlock.
> >
>
> Patch looks good and seems sensible, thanks.
>
Acked-by: Dennis Zhou <dennis@kernel.org>
> But why did btrfs use memalloc_nofs_save()/restore() rather than
> s/GFP_KERNEL/GFP_NOFS/?
I would also like to know.
Thanks,
Dennis
next prev parent reply other threads:[~2020-04-30 22:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-30 16:43 [PATCH] percpu: make pcpu_alloc() aware of current gfp context fdmanana
2020-04-30 16:54 ` Tejun Heo
2020-04-30 21:40 ` Andrew Morton
2020-04-30 22:23 ` Dennis Zhou [this message]
2020-04-30 22:43 ` Filipe Manana
2020-05-01 0:03 ` Dennis Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200430222347.GA164259@google.com \
--to=dennis@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=fdmanana@kernel.org \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).