Re: [PATCH v2 2/2] xfs: optimize getfsmap by reusing and advancing the refcount cursor
From: Christoph Hellwig
Date: Mon Nov 30 2026 - 07:51:23 EST
On Thu, Nov 26, 2026 at 09:30:09AM +0800, zhangshida2026@xxxxxxx wrote:
> Suggested-by: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Not really, this was all your own idea. I just did a round of feedback.
> + struct xfs_btree_cur *refcount_cur; /* cached refcountbt cursor */
> + struct xfs_refcount_irec rc_cur; /* current refcount record */
> + bool rc_eof; /* refcount cursor past end */
I should have pointed that out before, but the name for the flag is a
bit odd. eof stands for end of file, so it doesn't really apply here.
Maybe call this rc_done
> struct xfs_group *group; /* group info, if applicable */
> xfs_daddr_t next_daddr; /* next daddr we expect */
> /* daddr of low fsmap key when we're using the rtbitmap */
> @@ -205,15 +210,79 @@ xfs_getfsmap_dev_compare(
> /* Delete the btree cursors used by a getfsmap group walk. */
> static void
> xfs_getfsmap_del_cursors(
> - struct xfs_btree_cur *bt_cur,
> - int error)
> + struct xfs_getfsmap_info *info,
> + struct xfs_btree_cur *bt_cur,
> + int error)
Next time just adjust to the final alignment in the firstr patch.
> {
> + if (info->refcount_cur) {
> + xfs_btree_del_cursor(info->refcount_cur, error < 0 ?
> + XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
> + info->refcount_cur = NULL;
> + info->rc_eof = false;
> + }
> if (bt_cur)
> xfs_btree_del_cursor(bt_cur, error < 0 ?
> XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
And maybe keep a local variable for XFS_BTREE_ERROR vs
XFS_BTREE_NOERROR.
(and we should probably turn XFS_BTREE_NOERROR/XFS_BTREE_ERROR into an
enum pass that to xfs_btree_del_cursor, but that's a separate project).
> }
>
> -/* Decide if this mapping is shared. */
> +/*
> + * Allocate the refcount cursor for this group and position it at the last
> + * record at or before agbno, or the first record if there is none. Set
> + * rc_eof if the btree has no records at or after agbno.
This is just a summar of what the code does and not really adds any
additional information. Please don't bother with such comments.
Comments are useful to explain why something is done, or if something
done is really non-obvious.
> @@ -223,31 +292,55 @@ xfs_getfsmap_is_shared(
> {
> struct xfs_mount *mp = tp->t_mountp;
> struct xfs_btree_cur *cur;
> - xfs_agblock_t fbno;
> - xfs_extlen_t flen = 0;
> - int error;
> + struct xfs_refcount_irec *rc = &info->rc_cur;
struct xfs_refcount_irec *rc = &info->rc_cur;
> + xfs_agblock_t agbno = frec->rec_key;
> + xfs_extlen_t aglen = XFS_BB_TO_FSBT(mp, frec->len_daddr);
>
xfs_extlen_t aglen =
XFS_BB_TO_FSBT(mp, frec->len_daddr);
.. or just do away with the variable as it just has a single user.
> + }
> + cur = info->refcount_cur;
I'd probably do away with this variable. Given that the function deals
with two different cursors, having the local variable isn't super
helpful.
>
> + /* Advance to the first SHARED record that ends after agbno. */
> + while (rc->rc_domain != XFS_REFC_DOMAIN_SHARED ||
> + rc->rc_startblock + rc->rc_blockcount <= agbno) {
Sashiko complains that this iterators over XFS_REFC_DOMAIN_COW
unintentionally and I think it is right.