[PATCH v2 0/2] xfs: optimize getfsmap by reusing and advancing the refcount cursor
From: zhangshida2026
Date: Wed Nov 25 2026 - 20:30:52 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 3048 us 324 us (9.4x)
xfs_btree_lookup 10.7% ~0% (% of cycles)
The full fsmap output is byte-identical before and after (6421 records).
---
v2:
- split into a prep patch (xfs_getfsmap_del_cursors helper) and the
optimization, per hch
- merged the cursor alloc and initial-position branches, removed
rc_positioned; alloc+position is now xfs_getfsmap_refcount_init()
- EOF check moved before cursor allocation; rc_eof reset on cursor
free so it can't leak across groups
- fixed all lines over 80 columns and the rc_cur indentation
- reworded the commit messages
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):
- full xfstests -g auto: 1166 tests run; the 30 failures are environmental
(none use fsmap) and reproduce on the unpatched base kernel
- data fsmap byte-identical base vs series (6421 records)
- realtime reflink (rtrefcountbt) path exercised: fsmap over a reflinked
realtime volume is byte-identical, 1000 shared records
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 | 149 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 125 insertions(+), 24 deletions(-)
--
2.34.1