Improvement: Auto Balance Configuration
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 than 0. The full sysfs path is /sys/fs/btrfs//allocation//bg_reclaim_threshold.
FSID = filesystem UUID. Use btrfs filesystem show to list current filesystems. PROFILE = DATA, METADATA or SYSTEM chunks.
Source: https://wiki.tnonline.net/w/Btrfs/Balance#Automatic_Balance
The configuration is exposed via the 'sysfs' interface. For 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.
To date, Btrfs Assistant exposes manual balancing or through the 'Btrfsmaintenance' script. The advantage of exposing a configuration via 'sysfs' is that the balancing will happen automatically. I'm wondering how to enable it at boot? From what I understand, the 'sysfs' configuration is not preserved after a reboot, so perhaps the best way to enable it at boot is through a system service at each boot? Regarding the configuration exposure, maybe it’s enough to let the user choose the threshold, with a default of 10?
Here, 10, means a threshold of 10%. The kernel will now consider block groups that fall below this amount of usage for automatic reclaiming.
For some more details, I also wrote a post on the Fedora forum: https://discussion.fedoraproject.org/t/the-best-way-to-enable-parameters-through-sysfs/119410/1
And I thought this could be useful for many users who use Btrfs Assistant."
EDIT: I was thinking, maybe a service that enables it at boot is not the best solution, because if the filesystem is unmounted and then remounted, the configuration is lost. Perhaps creating a udev rule at mount would be better? I could run some tests by creating a udev rule