Hi all, The design doc for XFS online fsck contains a long discussion of the eventual consistency models in use for XFS metadata. In that chapter, we note that it is possible for scrub to collide with a chain of deferred space metadata updates, and proposes a lightweight solution: The use of a pending-intents counter so that scrub can wait for the system to drain all chains. This patchset implements that scrub drain. The first patch implements the basic mechanism, and the subsequent patches reduce the runtime overhead by converting the implementation to use sloppy counters and introducing jump labels to avoid walking into scrub hooks when it isn't running. This last paradigm repeats elsewhere in this megaseries. v23.1: make intent items take an active ref to the perag structure and document why we bump and drop the intent counts when we do If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below. This is an extraordinary way to destroy everything. 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=scrub-drain-intents xfsprogs git tree: https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-drain-intents --- fs/xfs/Kconfig | 5 ++ fs/xfs/Makefile | 2 + fs/xfs/libxfs/xfs_ag.c | 4 + fs/xfs/libxfs/xfs_ag.h | 8 +++ fs/xfs/libxfs/xfs_defer.c | 6 +- fs/xfs/scrub/agheader.c | 9 +++ fs/xfs/scrub/alloc.c | 3 + fs/xfs/scrub/bmap.c | 3 + fs/xfs/scrub/btree.c | 1 fs/xfs/scrub/common.c | 129 ++++++++++++++++++++++++++++++++++++++++---- fs/xfs/scrub/common.h | 15 +++++ fs/xfs/scrub/dabtree.c | 1 fs/xfs/scrub/fscounters.c | 7 ++ fs/xfs/scrub/health.c | 2 + fs/xfs/scrub/ialloc.c | 2 + fs/xfs/scrub/inode.c | 3 + fs/xfs/scrub/quota.c | 3 + fs/xfs/scrub/refcount.c | 9 +++ fs/xfs/scrub/repair.c | 3 + fs/xfs/scrub/rmap.c | 3 + fs/xfs/scrub/scrub.c | 63 ++++++++++++++++----- fs/xfs/scrub/scrub.h | 6 ++ fs/xfs/scrub/trace.h | 69 ++++++++++++++++++++++++ fs/xfs/xfs_bmap_item.c | 10 +++ fs/xfs/xfs_drain.c | 121 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_drain.h | 80 +++++++++++++++++++++++++++ fs/xfs/xfs_extfree_item.c | 2 + fs/xfs/xfs_linux.h | 1 fs/xfs/xfs_refcount_item.c | 2 + fs/xfs/xfs_rmap_item.c | 2 + fs/xfs/xfs_trace.h | 71 ++++++++++++++++++++++++ 31 files changed, 614 insertions(+), 31 deletions(-) create mode 100644 fs/xfs/xfs_drain.c create mode 100644 fs/xfs/xfs_drain.h