Since kernel 5.19, Btrfs has a new feature to automatically balance the filesystem:
Since Linux kernel 5.19 there is a
sysfs
knob to enable automatic block group reclaim. This is essentially the kernel automatically balancing individual block groups as they fall under a certain threshold.By default completely empty block groups are reclaimed into free space automatically. Using the sysfs knob
bg_reclaim_threshold
, it is now it is possible to to set another threshold than0
. The full sysfs path is/sys/fs/btrfs/<FSID>/allocation/<PROFILE>/bg_reclaim_threshold
.
- FSID = filesystem UUID. Use
btrfs filesystem show
to list current filesystems.- PROFILE = DATA, METADATA or SYSTEM chunks.
Source: Balancing a Btrfs filesystem | Forza's Ramblings
I was wondering if Fedora could benefit from this feature and what is the best method to enable it at every startup.
Awaiting further improvements: [PATCH 0/6] btrfs: dynamic and periodic block_group reclaim - Boris Burkov
It seems that Meta uses it with some benefits:
This can be worked around by:
- enabling automatic reclaim
- periodically running balance
The latter is widely deployed via btrfsmaintenance
(GitHub - kdave/btrfsmaintenance: Scripts for btrfs maintenance tasks like periodic scrub, balance, trim or defrag on selected mountpoints or directories.) and the former is used at scale at Meta with good results.
Any opinions?
An example: echo 10 > /sys/fs/btrfs/c3c00bf0-73a6-4aca-91bb-b5e32e76a08c/allocation/data/bg_reclaim_threshold
Here,
10
, means a threshold of 10%. The kernel will now consider block groups that fall below this amount of usage for automatic reclaiming.