[GIT PULL 12/18] xfs: support in-memory btrees

Darrick J. Wong
2024-02-24T01:32:05Z

The following changes since commit 1c51ac0998ed9baaca3ac75c0083b4c3b4d993ef:

xfs: move setting bt_logical_sectorsize out of xfs_setsize_buftarg (2024-02-22 12:42:45 -0800)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git tags/in-memory-btrees-6.9_2024-02-23

for you to fetch changes up to 0dc63c8a1ce39c1ac7da536ee9174cdc714afae2:

xfs: launder in-memory btree buffers before transaction commit (2024-02-22 12:43:36 -0800)

----------------------------------------------------------------
xfs: support in-memory btrees [v29.3 12/18]

Online repair of the reverse-mapping btrees presens some unique
challenges. To construct a new reverse mapping btree, we must scan the
entire filesystem, but we cannot afford to quiesce the entire filesystem
for the potentially lengthy scan.

For rmap btrees, therefore, we relax our requirements of totally atomic
repairs. Instead, repairs will scan all inodes, construct a new reverse
mapping dataset, format a new btree, and commit it before anyone trips
over the corruption. This is exactly the same strategy as was used in
the quotacheck and nlink scanners.

Unfortunately, the xfarray cannot perform key-based lookups and is
therefore unsuitable for supporting live updates. Luckily, we already a
data structure that maintains an indexed rmap recordset -- the existing
rmap btree code! Hence we port the existing btree and buffer target
code to be able to create a btree using the xfile we developed earlier.
Live hooks keep the in-memory btree up to date for any resources that
have already been scanned.

This approach is not maximally memory efficient, but we can use the same
rmap code that we do everywhere else, which provides improved stability
without growing the code base even more. Note that in-memory btree
blocks are always page sized.

This patchset modifies the kernel xfs buffer cache to be capable of
using a xfile (aka a shmem file) as a backing device. It then augments
the btree code to support creating btree cursors with buffers that come
from a buftarg other than the data device (namely an xfile-backed
buftarg). For the userspace xfs buffer cache, we instead use a memfd or
an O_TMPFILE file as a backing device.

This has been running on the djcloud for months with no problems. Enjoy!

Signed-off-by: Darrick J. Wong <djwong@kernel.org>

----------------------------------------------------------------
Christoph Hellwig (1):
xfs: add a xfs_btree_ptrs_equal helper

Darrick J. Wong (4):
xfs: teach buftargs to maintain their own buffer hashtable
xfs: support in-memory buffer cache targets
xfs: support in-memory btrees
xfs: launder in-memory btree buffers before transaction commit

.../filesystems/xfs/xfs-online-fsck-design.rst | 5 +-
fs/xfs/Kconfig | 8 +
fs/xfs/Makefile | 2 +
fs/xfs/libxfs/xfs_ag.c | 6 +-
fs/xfs/libxfs/xfs_ag.h | 4 +-
fs/xfs/libxfs/xfs_btree.c | 286 ++++++++++++++---
fs/xfs/libxfs/xfs_btree.h | 7 +
fs/xfs/libxfs/xfs_btree_mem.c | 347 +++++++++++++++++++++
fs/xfs/libxfs/xfs_btree_mem.h | 75 +++++
fs/xfs/scrub/scrub.c | 5 +
fs/xfs/scrub/scrub.h | 3 +
fs/xfs/xfs_buf.c | 214 ++++++++-----
fs/xfs/xfs_buf.h | 17 +
fs/xfs/xfs_buf_mem.c | 270 ++++++++++++++++
fs/xfs/xfs_buf_mem.h | 34 ++
fs/xfs/xfs_health.c | 3 +
fs/xfs/xfs_mount.h | 3 -
fs/xfs/xfs_trace.c | 2 +
fs/xfs/xfs_trace.h | 167 +++++++++-
fs/xfs/xfs_trans.h | 1 +
fs/xfs/xfs_trans_buf.c | 42 +++
21 files changed, 1363 insertions(+), 138 deletions(-)
create mode 100644 fs/xfs/libxfs/xfs_btree_mem.c
create mode 100644 fs/xfs/libxfs/xfs_btree_mem.h
create mode 100644 fs/xfs/xfs_buf_mem.c
create mode 100644 fs/xfs/xfs_buf_mem.h