mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Breno Leitao <leitao@debian.org>, Chris Mason <clm@fb.com>,
	David Sterba <dsterba@suse.com>,
	fdmanana@suse.com
Cc: boris@bur.io, layton@kernel.org, linux-btrfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH] btrfs: skip the extent map tree lock for inodes without extent maps
Date: Fri, 21 Aug 2026 20:43:00 +0930	[thread overview]
Message-ID: <a1eff18d-a630-4ea2-ac27-02c9252691d3@suse.com> (raw)
In-Reply-To: <20260821-b4-btrfs-em-shrinker-v1-1-286f3fb15873@debian.org>



在 2026/8/21 20:08, Breno Leitao 写道:
> The shrinker (find_first_inode_to_shrink()) takes inode->extent_tree.lock in write
> mode on every inode it walks, only to find out whether that inode has
> any extent maps.
> 
> Most have none, from what I understand, so, avoid the lock  by testing the
> tree with a plain read before taking the lock. tree->root is only
> modified with the tree lock held for write, so the unlocked read is
> a benign race: a false negative just defers the inode to a later scan.
> 
> On my tests, find_first_inode_to_shrink() was a bit faster, so, if this
> patch is correct, I think it is worth having to reduce lock contention.

How much faster?

We are using write_trylock() already, meaning if it's not locked we 
should get the lock immediately, otherwise we skip the inode.

So the lock contention should be low already.

Furthermore, if there are some hidden concurrency bugs, it will be very 
hard to debug.

I strongly prefer to stick to the existing locking scheme, unless you 
have a very strong argument not to.

> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>   fs/btrfs/extent_map.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
> index 6ad7b39ae358b..cdcd2b779050d 100644
> --- a/fs/btrfs/extent_map.c
> +++ b/fs/btrfs/extent_map.c
> @@ -1219,6 +1219,9 @@ static struct btrfs_inode *find_first_inode_to_shrink(struct btrfs_root *root,
>   
>   		tree = &inode->extent_tree;
>   
> +		if (!READ_ONCE(tree->root.rb_node))
> +			goto next;
> +
>   		/*
>   		 * We want to be fast so if the lock is busy we don't want to
>   		 * spend time waiting for it (some task is about to do IO for
> 
> ---
> base-commit: 6a746cd265aed59107ebdaa9ce039bb832922969
> change-id: 20260820-b4-btrfs-em-shrinker-7382d7f0dd05
> 
> Best regards,
> --
> Breno Leitao <leitao@debian.org>
> 


  reply	other threads:[~2026-08-21 11:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 10:38 Breno Leitao
2026-08-21 11:13 ` Qu Wenruo [this message]
2026-08-21 16:34   ` Breno Leitao
2026-08-21 11:17 ` Filipe Manana
2026-08-21 16:07   ` Breno Leitao
2026-08-21 18:18     ` Filipe Manana

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=a1eff18d-a630-4ea2-ac27-02c9252691d3@suse.com \
    --to=wqu@suse.com \
    --cc=boris@bur.io \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=kernel-team@meta.com \
    --cc=layton@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®