Skip to content

btrfs: Make balance cancelling response faster

Qu Wenruo linux-btrfs 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 6 repliesIn review
  2. v24 patches 7 repliesSuperseded
  3. v14 patches 6 repliesSuperseded

Changes in v3 from the cover letter

- Add comment explaining how cancelling/error handling is done in relocate_block_group()
- Remove one patch which is already covered by patch 2 and 3.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: relocation: Introduce error injection points for cancelling balancefs/btrfs/ctree.h fs/btrfs/relocation.c fs/btrfs/volumes.c+13 -11 reply
2/3btrfs: relocation: Check cancel request after each data page readfs/btrfs/relocation.c+12 -01 reply
3/3btrfs: relocation: Check cancel request after each extent foundfs/btrfs/relocation.c+4 -01 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchJohannes Thumshirn
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] btrfs: Make balance cancelling response faster

[PROBLEM]
There are quite some users reporting that 'btrfs balance cancel' slow to cancel current running balance, or even doesn't work for certain dead balance loop.

With the following script showing how long it takes to fully stop a balance:
#!/bin/bash
dev=/dev/test/test
mnt=/mnt/btrfs

umount $mnt &> /dev/null
umount $dev &> /dev/null

mkfs.btrfs -f $dev
mount $dev -o nospace_cache $mnt

dd if=/dev/zero bs=1M of=$mnt/large &
dd_pid=$!

sleep 3
kill -KILL $dd_pid
sync

  btrfs balance start --bg --full $mnt &
  sleep 1

echo "cancel request" >> /dev/kmsg
time btrfs balance cancel $mnt
umount $mnt

It takes around 7~10s to cancel the running balance in my test environment.

[CAUSE]
Btrfs uses btrfs_fs_info::balance_cancel_req to record how many cancel request are queued.
However that cancelling request is only checked after relocating a block group.

That behavior is far from optimal to provide a faster cancelling.

[FIX]
This patchset will add more cancelling check points, to make cancelling faster.

And also, introduce a new error injection points to cover these newly introduced and future check points.

For the canceled balance during relocate_block_group(), we are re-using the existing error handling path.
It will mark all existing reloc_roots as orphan in prepare_to_merge(), then queue all of them for cleanup in merge_reloc_roots(). Thus it shouldn't cause any problem.

Changelog:
v2:
- Rebased to v5.6-rc1
There is a small conflicts caused by extra finished stage output. Other than that, everything is pretty straightforward

- Add explanation for the error handling path in cover letter.

v3:
- Add comment explaining how cancelling/error handling is done in relocate_block_group()
- Remove one patch which is already covered by patch 2 and 3.

Qu Wenruo (3):
btrfs: relocation: Introduce error injection points for cancelling
balance
btrfs: relocation: Check cancel request after each data page read
btrfs: relocation: Check cancel request after each extent found

 fs/btrfs/ctree.h      |  1 +
 fs/btrfs/relocation.c | 27 +++++++++++++++++++++++++++
 fs/btrfs/volumes.c    |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.0