[Request] Automatic/background btrfs balance (defrag type cleaning of filesystem)
Btrfs, the file system of Jolla, is copy-on-write type fs. This means that every time somdthing is written to the flash, btrfs needs to find new unallocated space to it. There are some internal structures of btrfs that handle that, but one key issue with btrfs and Jolla is btrfs use of 1 GB allocation chunks. It's obvious that 16 GB flash do not have much breathing room of that kind of allocation scheme. This only mattters if you have once filled your device almost full and all available chunks are already allocated. If you then try to write something big to the flash it may fail even fs reports that you have more space left.
This phenonenon may show up like this bug report.
There are excellent thread about al this here.
This btrfs issue can be addressed simply to run defragment type of fs operation from cli (devel-su):
btrfs bal start /
The problem is that this take a long time, ~ hour or so, and the system load is high meanwhile. It can akso trigger reboot, if system thinks that there are endless loop going on because high system load of the command if not run by lowered priority.
There are also less resource heavy version of that balance operation like:
btrfs bal start -dusage=5 /
which cures many issues we sailors are experiencing and don't take long to accomplish. The background task should favor this if the logic detects no need to do full balance as nnth ooints out.
Jolla/Sailfish should have scheduled background job that automatically runs if there are reasons to do that (it can be check out by using other btrfs commands). The system job should run with low priority like with nice settings and only when the phone has been unused sometime with charger connected. The balance operation is quite write heavy so the system should avoid to run the task if not necessarily to prevent excessive wear of flash memory.
EDIT 21-01-2015 upcoming updates will run a btrfs-balance upon system update as mentioned here
EDIT 06-02-2015 there are new systemd btrfs balance service coming hopefully soon, please see below!
With setting option in system settings to start it manually by user as well.
With visual indication what is been done.
Perhaps it would be good to have also the possible to see the current status of the btrfs allocations before actual start of manual balance?
Kari ( 2014-11-27 08:46:27 +0200 )editI agree, good idea. The new Utilities? (Apuohjelmat) system area is good place for this.
pata ( 2014-11-27 08:58:24 +0200 )editIt's better to use the 'btrfs balance start -dusage=5 /' command, with that -dusage parameter added. It fixes most issues people will have and only takes a few seconds instead of an hour.
nthn ( 2014-11-27 09:41:04 +0200 )editHaving faced the symptoms of BTRFS storage space congestion myself (in my case I was required to factory-reset the device via the Bootloader) I wholeheartedly agree with your idea of a background job. I would argue that, for the same reason, the Sailfish OS "free space" indicator (Settings -> System -> About product) should accommodate for the BTRFS headroom and show less free space accordingly.
t-lo ( 2014-11-27 11:34:09 +0200 )editWont the filesystem get hosed when the device reboots/shuts down during the balance ? That could be quite dangerous considering all the spontaneous reboots & shutdowns happening on the Jolla.
And periodically running the balance could only make that more likely/certain that sooner or later there would be a reboot or shutdown during the balance, breaking the filesystem.
MartinK ( 2014-11-27 12:12:14 +0200 )edit