Why does defragmenting break reflinks?
BTRFS-FILESYSTEM(8) says "defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks of COW data (for example files copied with cp --reflink, snapshots or de-duplicated data)." Why does defragmenting not preserve reflinks and why was it removed?
Signature · 2 lines
George truly, 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣 This email does not constitute a legally binding contract
Quoted 2 lines · 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣
BTRFS-FILESYSTEM(8) says "defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks of COW data (for example files copied with cp --reflink, snapshots or de-duplicated data)." Why does defragmenting not preserve reflinks and why was it removed?
Defrag means to re-dirty the data, and write them back again, which will cause COW. And by nature this breaks reflinked data extents.
Quoted 8 lines · Qu Wenruo
Quoted 2 lines · 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣
BTRFS-FILESYSTEM(8) says "defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks of COW data (for example files copied with cp --reflink, snapshots or de-duplicated data)." Why does defragmenting not preserve reflinks and why was it removed?
Defrag means to re-dirty the data, and write them back again, which will cause COW. And by nature this breaks reflinked data extents.
But why did it previusly not break reflinks?
Signature · 1 line
George truly, 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣 Improve your wifi reception for free <https://www.youtube.com/watch?v=LY8Wi7XRXCA>Home alone any% world <https://www.youtube.com/watch?v=IMstFIKZLpI>record set by 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣 <https://www.speedrun.com/home_alone_nes/runs/zpkq978y> This email does not constitute a legally binding contract
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣
Quoted 8 lines · Qu Wenruo
Quoted 2 lines · 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣
BTRFS-FILESYSTEM(8) says "defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks of COW data (for example files copied with cp --reflink, snapshots or de- duplicated data)." Why does defragmenting not preserve reflinks and why was it removed?
Defrag means to re-dirty the data, and write them back again, which will cause COW. And by nature this breaks reflinked data extents.
But why did it not break reflinks previusly?
It looks like it's technical difficulties.
The commit is 8101c8dbf624 ("Btrfs: disable snapshot aware defrag for now").
I do not have all the details, but at least a quick glance already shows that the old detection is not taking reflink into consideration. It only considers snapshot, but reflink can happen within a single subvolume, or between subvolumes (not snapshot).
So the old method is not reliable in the first place.
Thanks,
Qu
Quoted 3 lines
Signature · 2 lines
-- George truly, 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣 Improve your wifi reception for free <https:// www.youtube.com/watch?v=LY8Wi7XRXCA>Home alone any% world <https:// www.youtube.com/watch?v=IMstFIKZLpI>record set by 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣 <https:// www.speedrun.com/home_alone_nes/runs/zpkq978y> This email does not constitute a legally binding contract
Op 30-05-2025 om 02:27 schreef Qu Wenruo:
Quoted 7 lines · 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣
Quoted 2 lines
BTRFS-FILESYSTEM(8) says "defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks of COW data (for example files copied with cp --reflink, snapshots or de- duplicated data)." Why does defragmenting not preserve reflinks and why was it removed?
Defrag means to re-dirty the data, and write them back again, which will cause COW.
That sounds like an implementation choice.
Quoted 1 line
And by nature this breaks reflinked data extents.
With a different implementation this would not by nature be the case.
Actually this makes defrag a very dangerous operation on disks with many snapshots (> 20). When you would defrag each snapshot suddenly your 5% full disk would be 100%.
Quoted 1 line · Ferry Toth
Actually this makes defrag a very dangerous operation on disks with many snapshots (> 20). When you would defrag each snapshot suddenly your 5% full disk would be 100%.
This actualy happend to me once because i forgot i had snapshots.
Signature · 2 lines
George truly, 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣 This email does not constitute a legally binding contract
Quoted 6 lines · 𝕍𝕖𝕝𝕠𝕔𝕚𝕗𝕪𝕖𝕣
Quoted 3 lines · Ferry Toth
Actually this makes defrag a very dangerous operation on disks with many snapshots (> 20). When you would defrag each snapshot suddenly your 5% full disk would be 100%.
This actualy happend to me once because i forgot i had snapshots.
Greater than 20 is a lot of snapshots? I guess I should stop using things like Snapper on my systems, then. It *defaults* to hourly snapshots of every subvolume you activate it on, pruned to the last 24 hours, so that's 24 alone. Then it keeps midnight for every day going back several weeks.