[PATCH v4 0/2] xfs: optimize getfsmap by reusing and advancing the refcount cursor

From: zhangshida2026

Date: Tue Dec 01 2026 - 20:22:38 EST


From: Shida Zhang <zhangshida@xxxxxxxxxx>

GETFSMAP walks the rmap btree in increasing startblock order and asks
the refcount btree whether each record's blocks are shared. Every
record pays a cursor alloc/free and a root-to-leaf btree search, even
though the next query is almost always the next refcount record.

This series keeps one refcount cursor per group, positions it once, and
advances it with xfs_btree_increment() as the rmap walk moves forward.
Patch 1 factors out the cursor cleanup so patch 2 can add the cached
refcount cursor without duplicating it.

Measured with a kernel-isolated FS_IOC_GETFSMAP loop over the whole data
device (3000 reflinked 256KB files, mkfs -m rmapbt=1,reflink=1 -d
agcount=4, Kunpeng 920 + NVMe), mean of three interleaved A/B runs:

original this series
walk time 3040 us 335 us (9.1x)
xfs_btree_lookup 11.9% ~0% (% of cycles)

The full fsmap output is byte-identical before and after (6421 records).

---

v4:
- the advance loop breaks out at the first COW record instead of
iterating through the COW section (hch); output unchanged
- del_cursors final alignment placed in the prep patch (no churn)
- shortened the rc_done comment and wrapped a long line

v3: https://lore.kernel.org/linux-xfs/20261201074947.3338021-1-zhangshida2026@xxxxxxx/
v2: https://lore.kernel.org/linux-xfs/20261126013009.533557-1-zhangshida2026@xxxxxxx/
v1: https://lore.kernel.org/linux-xfs/20261123075048.3658960-1-zhangshida@xxxxxxxxxx/

Testing (7.3.4, Kunpeng 920 + NVMe, mkfs -m rmapbt=1,reflink=1):
- data fsmap byte-identical base vs series (6421 records)
- with COW records present (reflink + COW writes), fsmap is
byte-identical base vs series (245 records)
- realtime reflink (rtrefcountbt) path exercised: fsmap over a reflinked
realtime volume is byte-identical, 1000 shared records
- full xfstests -g auto: 1166 tests run; the 29 failures are
pre-existing/environmental (none use fsmap) and match the
unpatched base kernel exactly

Shida Zhang (2):
xfs: factor out a xfs_getfsmap_del_cursors helper
xfs: optimize getfsmap by reusing and advancing the refcount cursor

fs/xfs/xfs_fsmap.c | 146 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 121 insertions(+), 25 deletions(-)

--
2.34.1