Skip to content

btrfs-progs: mkfs: optimize the discard behavior so it won't drive me crazy

Qu Wenruo linux-btrfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2btrfs-progs: mkfs: discard the logical range in one searchmkfs/main.c+9 -210 replies
2/2btrfs-progs: mkfs: optimise the block group discarding behaviorkernel-shared/volumes.c kernel-shared/volumes.h mkfs/main.c+74 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] btrfs-progs: mkfs: optimize the discard behavior so it won't drive me crazy

After commit 4b861c186592 ("btrfs-progs: mkfs: discard free space"), mkfs.btrfs inside my VM is much slower.

Previously it takes only around 0.015s, now it takes over 0.750s, which is around 50x regression, and that's already when that virtio-blk device is already ignoring discard commands.

It turns out that the main problem is inside how we submit discard requests.

Currently we submit the discard immediately after finding a free space, but for DUP profiles (the default one for metadata/system chunks), we send a discard request for each mirror.

Since it's DUP, the two device extents are on the same device, then the for next free space we send two discard requests again, meaning we're switching between two different dev extents, making the discard requests more like some random writes, greatly reduce the peroformance.

The root fix is in the second patch, where we record and re-order the discard requests for each device, so that the eventual requests are all in ascending order and are merged when possible.

The first patch is just a minor cleanup to reduce the call of btrfs_map_blocks() by using WRITE for discard.

With this series, the runtime of mkfs.btrfs is still increased (by the free space discarding), but still fast enough that even I can not sense it (0.015s - > 0.017s), finally bring back my inner peace.

Qu Wenruo (2):
btrfs-progs: mkfs: discard the logical range in one search
btrfs-progs: mkfs: optimise the block group discarding behavior

 kernel-shared/volumes.c |   4 ++
 kernel-shared/volumes.h |   3 ++
 mkfs/main.c             | 100 ++++++++++++++++++++++++++++++----------
 3 files changed, 83 insertions(+), 24 deletions(-)

--
2.52.0