Re: [PATCH 0/6] btrfs: trim unused space when relocating data extents
From: Qu Wenruo
Date: Sun Nov 29 2026 - 23:44:04 EST
在 2026/11/30 11:50, Ismael Luceno 写道:
On Mon, 30 Nov 2026 07:30:17 +1030
Qu Wenruo <quwenruo.btrfs@xxxxxxx> wrote:
在 2026/11/30 00:01, Ismael Luceno 写道:
A data balance copies every data extent whole, including bytes that
no file references. Those dead bytes stay allocated, and an
overwritten file keeps its old extents until every reference to
them is gone.
This series copies only the referenced bytes. For each old extent,
the referenced ranges are collected and laid out in one new
allocation, and each file extent is remapped to its own range. Dead
bytes are not copied, so they are freed with the old block group.
Won't this introduce extra backref walk during relocation?
That can be very expensive for heavily shared data extents, meanwhile
may even not result any space saving.
The data copy seems to always dominate, I couldn't measure any
meaningful difference.
IIRC the problem is that, now we will need to hold a trans handle to iterate through the backrefs of one extent.
Previously we only need to update the reloc tree of subvolumes, and that can happen in multiple transaction, so it won't block future transaction for too long.
But now we can block future transaction when doing a huge backref walk.
There are examples like doing a million reflink, in fstests.
If we're relocating such extent, I think it can stall the next transaction.
I'm looking into how to optimise this, though.
Maybe something to fallback to the current solution if there are too many backrefs.
But I do not have a quick and reliable way to do that.
E.g. if you just check the number of refs, it can be wrong. E.g. a single backref pointing to a parent tree block, but that tree block can be shared by a lot of snapshots, thus can still have a lot of roots referring to it.
Thanks,
Qu
But sashiko is already reporting 9 high level problems and 11 medium
level bugs, I think you would like to get them addressed.
I'll look at it and make a new submission.
Thanks!