linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: stop doing GFP_KERNEL memory allocations in the ref verify tool
Date: Wed, 21 Jul 2021 19:21:44 +0200	[thread overview]
Message-ID: <20210721172144.GL19710@twin.jikos.cz> (raw)
In-Reply-To: <a3c49375c499e32d265feea5895d59da78db1c89.1626791739.git.fdmanana@suse.com>

On Tue, Jul 20, 2021 at 04:05:23PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> In commit 351cbf6e4410e7 ("btrfs: use nofs allocations for running delayed
> items") we wrapped all btree updates when running delayed items with
> memalloc_nofs_save() and memalloc_nofs_restore(), due to a lock inversion
> detected by lockdep involving reclaim and the mutex of delayed nodes.
> 
> The problem is because the ref verify tool does some memory allocations
> with GFP_KERNEL, which can trigger reclaim and reclaim can trigger inode
> eviction, which requires locking the mutex of an inode's delayed node.
> On the other hand the ref verify tool is called when allocating metadata
> extents as part of operations that modify a btree, which is a problem when
> running delayed nodes, where we do btree updates while holding the mutex
> of a delayed node. This is what caused the lockdep warning.
> 
> Instead of wrapping every btree update when running delayed nodes, change
> the ref verify tool to never do GFP_KERNEL allocations, because:
> 
> 1) We get less repeated code, which at the moment does not even have a
>    comment mentioning why we need to setup the NOFS context, which is a
>    recommended good practice as mentioned at
>    Documentation/core-api/gfp_mask-from-fs-io.rst
> 
> 2) The ref verify tool is something meant only for debugging and not
>    something that should be enabled on non-debug / non-development
>    kernels;
> 
> 3) We may have yet more places outside delayed-inode.c where we have
>    similar problem: doing btree updates while holding some lock and
>    then having the GFP_KERNEL memory allocations, from the ref verify
>    tool, trigger reclaim and trying again to acquire the same lock
>    through the reclaim path.
>    Or we could get more such cases in the future, therefore this change
>    prevents getting into similar cases when using the ref verify tool.

That all sounds reasonable to me regarding the GFP flags use.

  reply	other threads:[~2021-07-21 17:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20 15:05 [PATCH 0/2] btrfs: make the batch insertion of dir index keys more efficient fdmanana
2021-07-20 15:05 ` [PATCH 1/2] btrfs: improve the batch insertion of delayed items fdmanana
2021-07-20 15:05 ` [PATCH 2/2] btrfs: stop doing GFP_KERNEL memory allocations in the ref verify tool fdmanana
2021-07-21 17:21   ` David Sterba [this message]
2021-07-21 20:40 ` [PATCH 0/2] btrfs: make the batch insertion of dir index keys more efficient Josef Bacik
2021-07-22 13:00 ` David Sterba

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=20210721172144.GL19710@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.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).