public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs-progs: mkfs: optimize the discard behavior so it won't drive me crazy
@ 2026-01-09  5:31 Qu Wenruo
  2026-01-09  5:31 ` [PATCH 1/2] btrfs-progs: mkfs: discard the logical range in one search Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-01-09  5:31 UTC (permalink / raw)
  To: linux-btrfs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-23 23:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-09  5:31 [PATCH 0/2] btrfs-progs: mkfs: optimize the discard behavior so it won't drive me crazy Qu Wenruo
2026-01-09  5:31 ` [PATCH 1/2] btrfs-progs: mkfs: discard the logical range in one search Qu Wenruo
2026-01-09  5:31 ` [PATCH 2/2] btrfs-progs: mkfs: optimise the block group discarding behavior Qu Wenruo
2026-01-23 23:02 ` [PATCH 0/2] btrfs-progs: mkfs: optimize the discard behavior so it won't drive me crazy David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox