Hi all, 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. If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below. This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome. --D kernel git tree: https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=in-memory-btrees xfsprogs git tree: https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=in-memory-btrees --- configure.ac | 4 include/builddefs.in | 4 include/libxfs.h | 2 include/xfs_mount.h | 10 + include/xfs_trace.h | 15 + include/xfs_trans.h | 1 libfrog/bitmap.c | 64 +++ libfrog/bitmap.h | 3 libxfs/Makefile | 18 + libxfs/init.c | 121 +++++-- libxfs/libxfs_io.h | 23 + libxfs/libxfs_priv.h | 5 libxfs/rdwr.c | 109 +++++- libxfs/trans.c | 40 ++ libxfs/xfbtree.c | 797 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfbtree.h | 57 +++ libxfs/xfile.c | 299 ++++++++++++++++ libxfs/xfile.h | 108 ++++++ libxfs/xfs_ag.c | 6 libxfs/xfs_ag.h | 4 libxfs/xfs_btree.c | 173 ++++++++- libxfs/xfs_btree.h | 17 + libxfs/xfs_btree_mem.h | 128 +++++++ libxfs/xfs_refcount_btree.c | 4 libxfs/xfs_rmap_btree.c | 4 m4/package_libcdev.m4 | 66 ++++ mkfs/xfs_mkfs.c | 2 repair/prefetch.c | 12 - repair/prefetch.h | 1 repair/progress.c | 14 - repair/progress.h | 2 repair/scan.c | 2 repair/xfs_repair.c | 47 ++- 33 files changed, 2022 insertions(+), 140 deletions(-) create mode 100644 libxfs/xfbtree.c create mode 100644 libxfs/xfbtree.h create mode 100644 libxfs/xfile.c create mode 100644 libxfs/xfile.h create mode 100644 libxfs/xfs_btree_mem.h