From: Christoph Hellwig <hch@infradead.org>
To: Shida Zhang <zhangshida@kylinos.cn>
Cc: Carlos Maiolino <cem@kernel.org>,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
djwong@kernel.org
Subject: Re: [PATCH] xfs: optimize getfsmap by reusing and advancing the refcount cursor
Date: Tue, 24 Nov 2026 22:58:05 -0800 [thread overview]
Message-ID: <awaG_cs82bPs8QSt@infradead.org> (raw)
In-Reply-To: <20261123075048.3658960-1-zhangshida@kylinos.cn>
On Mon, Nov 23, 2026 at 03:50:48PM +0800, Shida Zhang wrote:
> GETFSMAP sweeps the whole device: online fsck, dedup scanners and
> imaging tools walk thousands of records per call.
>
> Every record pays two costs. xfs_getfsmap_is_shared() allocates and
> frees a refcount btree cursor, and xfs_refcount_find_shared() searches
> the refcount btree from the root via xfs_btree_lookup(). A fresh cursor
> re-reads the root block each time; the search re-descends root to leaf
> even when the answer is the next slot.
This reads pretty odd. Maybe try to reword it a bit using your own
writing instead of an LLM?
> Testing: xfstests with rmapbt=1,reflink=1 passes the fsmap/rmap/clone subset
> (xfs/271-274, 277, 114, 233, 234, 236, 517, 560, 600, generic/127, 129). The
> full fsmap record set is byte-identical before and after.
A full -g auto run would also be useful as we have quite a few tests
that use getfsmap under the hood.
> Not tested: the rtrefcountbt advance path (no RT device on the test box).
> It uses the same logic via the rtrefcountbt cursor, and the rtrmap walk is
> also sorted.
With the zoned allocator, you can use an internal RT device.
Just add "-r zoned" to the test and scratch mkfs options.
> @@ -161,6 +163,10 @@ struct xfs_getfsmap_info {
> struct xfs_fsmap_head *head;
> struct fsmap *fsmap_recs; /* mapping records */
> struct xfs_buf *agf_bp; /* AGF, for refcount queries */
> + struct xfs_btree_cur *refcount_cur; /* cached refcountbt cursor */
> + struct xfs_refcount_irec rc_cur; /* current refcount record */
Overly long line here, and weird indentation for rc_cur.
Please go over the patch and fix all the long lines, not going to
report more of those.
> +/* Drop the cached refcount btree cursor when leaving a group. */
> +static void
> +xfs_getfsmap_put_refcount_cur(
> + struct xfs_getfsmap_info *info,
> + int error)
> +{
> + if (info->refcount_cur) {
> + xfs_btree_del_cursor(info->refcount_cur, error < 0 ?
> + XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
> + info->refcount_cur = NULL;
> + }
> +}
All the callers also delete the rmap btree. So maybe do a prep patch
to add a xfs_getfsmap_del_cursors helper which initially just does
this work for the rmap one, and where you can then add the refcount
cursor deletion as well.
> + if (!info->refcount_cur) {
> + if (info->group->xg_type == XG_TYPE_RTG)
> + cur = xfs_rtrefcountbt_init_cursor(tp,
> + to_rtg(info->group));
> + else
> + cur = xfs_refcountbt_init_cursor(mp, tp, info->agf_bp,
> + to_perag(info->group));
> + info->refcount_cur = cur;
> + info->rc_positioned = false;
> + info->rc_eof = false;
> + }
> + cur = info->refcount_cur;
> + if (info->rc_eof)
> + return 0;
I don't see why we'd want to allocate a new cursor at EOF. So this
check should probably move to before the cursor allocation.
> + if (!info->rc_positioned) {
And this only happens if the cursor was just allocatd. So the two
branches can be merged, and rc_positioned can be removed. Bonous
points of splitting the cursor allocation and initial positioning
into a helper.
prev parent reply other threads:[~2026-11-25 6:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 7:50 [PATCH] xfs: optimize getfsmap by reusing and advancing the refcount cursor Shida Zhang
2026-11-25 6:58 ` Christoph Hellwig [this message]
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=awaG_cs82bPs8QSt@infradead.org \
--to=hch@infradead.org \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=zhangshida@kylinos.cn \
/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