Hi all, These patches contain experimental code to enable userspace to defragment the free space in a filesystem. Two purposes are imagined for this functionality: clearing space at the end of a filesystem before shrinking it, and clearing free space in anticipation of making a large allocation. The first patch adds a new fallocate mode that allows userspace to allocate free space from the filesystem into a file. The goal here is to allow the filesystem shrink process to prevent allocation from a certain part of the filesystem while a free space defragmenter evacuates all the files from the doomed part of the filesystem. The second patch amends the online repair system to allow the sysadmin to forcibly rebuild metadata structures, even if they're not corrupt. Without adding an ioctl to move metadata btree blocks, this is the only way to dislodge metadata. This patchset also includes a separate inode migration tool as prototyped by Dave Chinner in 2020. 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=defrag-freespace xfsprogs git tree: https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=defrag-freespace fstests git tree: https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=defrag-freespace --- Commits in this patchset: * xfs_io: display rtgroup number in verbose fsrefs output * xfs: add an ioctl to map free space into a file * xfs_io: support using XFS_IOC_MAP_FREESP to map free space * xfs_db: get and put blocks on the AGFL * xfs_spaceman: implement clearing free space * spaceman: physically move a regular inode * spaceman: find owners of space in an AG * xfs_spaceman: wrap radix tree accesses in find_owner.c * xfs_spaceman: port relocation structure to 32-bit systems * spaceman: relocate the contents of an AG * spaceman: move inodes with hardlinks --- configure.ac | 1 db/agfl.c | 297 +++- include/builddefs.in | 1 include/xfs_trace.h | 4 io/fsrefcounts.c | 22 io/prealloc.c | 35 libfrog/Makefile | 5 libfrog/clearspace.c | 3294 +++++++++++++++++++++++++++++++++++++++ libfrog/clearspace.h | 79 + libfrog/fsgeom.h | 29 libfrog/radix-tree.c | 2 libfrog/radix-tree.h | 2 libxfs/libxfs_api_defs.h | 4 libxfs/libxfs_priv.h | 9 libxfs/xfs_alloc.c | 88 + libxfs/xfs_alloc.h | 3 libxfs/xfs_fs.h | 14 m4/package_libcdev.m4 | 20 man/man2/ioctl_xfs_map_freesp.2 | 76 + man/man8/xfs_db.8 | 11 man/man8/xfs_io.8 | 8 man/man8/xfs_spaceman.8 | 40 spaceman/Makefile | 11 spaceman/clearfree.c | 171 ++ spaceman/find_owner.c | 442 +++++ spaceman/init.c | 7 spaceman/move_inode.c | 662 ++++++++ spaceman/relocation.c | 566 +++++++ spaceman/relocation.h | 53 + spaceman/space.h | 6 30 files changed, 5953 insertions(+), 9 deletions(-) create mode 100644 libfrog/clearspace.c create mode 100644 libfrog/clearspace.h create mode 100644 man/man2/ioctl_xfs_map_freesp.2 create mode 100644 spaceman/clearfree.c create mode 100644 spaceman/find_owner.c create mode 100644 spaceman/move_inode.c create mode 100644 spaceman/relocation.c create mode 100644 spaceman/relocation.h