Hello, Dave reported that with async discard enabled, relocation fails [1]. This could be caused by two things. First, if we unpin extents, that means we haven't fully discarded the block group and need to let async discard revisit it. Second, relocation removes block_groups outside of the normal. I fixed both issues and now it successfully passes xfstests btrfs/003. Changes in v5: - Changed the rules so free space is always added as the right type based on discard settings (see btrfs_add_free_space()), this removes the need to pass around trim_state in unpin_extent_range(). - Handled relocation block group deletion (xfstests btrfs/003) - When adding to the discard lists, make sure the work queue is active. (made all additions go through either btrfs_discard_queue_work() or btrfs_discard_check_filter()). - Added 10 sec reuse timeout for fully empty block groups. v4 is available here: [2]. This series is on top of btrfs-devel#misc-next fbc0468e42d2 + [3]. [1] https://lore.kernel.org/linux-btrfs/20191126215204.GP2734@xxxxxxxxxxxxx/ [2] https://lore.kernel.org/linux-btrfs/cover.1574709825.git.dennis@xxxxxxxxxx/ [3] https://lore.kernel.org/linux-btrfs/20191209193846.18162-1-dennis@xxxxxxxxxx/ Dennis Zhou (22): bitmap: genericize percpu bitmap region iterators btrfs: rename DISCARD opt to DISCARD_SYNC btrfs: keep track of which extents have been discarded btrfs: keep track of cleanliness of the bitmap btrfs: add the beginning of async discard, discard workqueue btrfs: handle empty block_group removal btrfs: discard one region at a time in async discard btrfs: add removal calls for sysfs debug/ btrfs: make UUID/debug have its own kobject btrfs: add discard sysfs directory btrfs: track discardable extents for async discard btrfs: keep track of discardable_bytes btrfs: calculate discard delay based on number of extents btrfs: add bps discard rate limit btrfs: limit max discard size for async discard btrfs: make max async discard size tunable btrfs: have multiple discard lists btrfs: only keep track of data extents for async discard btrfs: keep track of discard reuse stats btrfs: add async discard header btrfs: increase the metadata allowance for the free_space_cache btrfs: make smaller extents more likely to go into bitmaps fs/btrfs/Makefile | 2 +- fs/btrfs/block-group.c | 88 ++++- fs/btrfs/block-group.h | 30 ++ fs/btrfs/ctree.h | 52 ++- fs/btrfs/discard.c | 684 ++++++++++++++++++++++++++++++++++++ fs/btrfs/discard.h | 42 +++ fs/btrfs/disk-io.c | 15 +- fs/btrfs/extent-tree.c | 8 +- fs/btrfs/free-space-cache.c | 611 +++++++++++++++++++++++++++----- fs/btrfs/free-space-cache.h | 41 ++- fs/btrfs/inode-map.c | 13 +- fs/btrfs/inode.c | 2 +- fs/btrfs/scrub.c | 7 +- fs/btrfs/super.c | 39 +- fs/btrfs/sysfs.c | 205 ++++++++++- fs/btrfs/volumes.c | 7 + include/linux/bitmap.h | 35 ++ mm/percpu.c | 61 +--- 18 files changed, 1789 insertions(+), 153 deletions(-) create mode 100644 fs/btrfs/discard.c create mode 100644 fs/btrfs/discard.h -- 2.17.1
