From: Breno Leitao <leitao@debian.org>
To: Qu Wenruo <wqu@suse.com>
Cc: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
fdmanana@suse.com, 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 09:34:14 -0700 [thread overview]
Message-ID: <aoh6Hobk-wJ2ngDk@gmail.com> (raw)
In-Reply-To: <a1eff18d-a630-4ea2-ac27-02c9252691d3@suse.com>
Hello Qu,
On Fri, Aug 21, 2026 at 08:43:00PM +0930, Qu Wenruo wrote:
> 在 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?
Filipe has asked the same question, and I used that thread to reply,
let's use that thread for performance discussions.
> We are using write_trylock() already, meaning if it's not locked we should
> get the lock immediately, otherwise we skip the inode.
You are right that the shrinker itself never waits. But there are two
costs left that the trylock does not avoid:
1) Even uncontended, the atomic is not free. write_trylock() is a
cmpxchg that has to pull the extent_map_tree cache line in
exclusive.
2) The trylock only protects the shrinker from waiting. When it
succeeds we do hold the lock, briefly, on an inode we are about to
skip anyway, and anyone arriving in that window block
While my microbenchmark results in Filipe's answer might be skewed
toward this case, the fleet profiler shows find_first_inode_to_shrink()
is far from negligible in production.
next prev parent reply other threads:[~2026-08-21 16:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 10:38 [PATCH] btrfs: skip the extent map tree lock for inodes without extent maps Breno Leitao
2026-08-21 11:13 ` Qu Wenruo
2026-08-21 16:34 ` Breno Leitao [this message]
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=aoh6Hobk-wJ2ngDk@gmail.com \
--to=leitao@debian.org \
--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=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wqu@suse.com \
/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