[btrfs] Flush Journal to Persistent Storage slow boot issue [solution]

Hello Community,
I write my experience with this issue that I have just solved.

I installed Manjaro KDE Plasma 21.1.1 about a month ago. I installed it on a single btrfs partition using (and erasing) the whole disk, with the automatic selection during the installation.

I had a clean and full working system.
After a while, I noticed that during the boot procedure it took long time to the line
A start job is running for Flush Journal to Persistent Storage
See the following photo:

So, I remembered my /etc/fstab file that had a btrfs subvolume @log automatically created during installation for /var/log:
UUID=#### / btrfs subvol=/@,defaults,noatime,space_cache 0 1
UUID=#### /home btrfs subvol=/@home,defaults,noatime,space_cache 0 2
UUID=#### /var/cache btrfs subvol=/@cache,defaults,noatime,space_cache 0 2
UUID=#### /var/log btrfs subvol=/@log,defaults,noatime,space_cache 0 2
UUID=#### /swap btrfs subvol=/@swap,defaults,noatime,space_cache 0 2
/swap/swapfile swap swap defaults,noatime 0 0

So I mounted the filesystem on /mnt:
sudo mount /dev/sda1 /mnt

I copied all directories and files inside the @log subvolume from /mnt/@log/* to /mnt/@/var/log/* that was empty before.

I commented the following line in /etc/fstab:
#UUID=#### /var/log btrfs subvol=/@log,defaults,noatime,space_cache 0 2

Rebooted and the issue seems to be solved.

I wrote this because I hope that it could help someone else with this issue.
Thank you.

1 Like

Your solution is only temporary. The reason for the slowdown is because the journal files were highly fragmented. By moving them to a different subvolume, you also defragmented them. They will get fragmented again due to the nature of btrfs.

Without removing the @log subvolume, a correct solution is to defragment the files with
sudo btrfs file defrag -vrft 40M /var/log/journal
and then run
sudo chattr -R +C /var/log/journal
which will prevent them from getting fragmented again.

2 Likes

Thank you for the explanation. So, is there a way to verify the fragmentation on a btrfs filesystem?
Could the autodefrag mount option also help with the issue? Is the online defragmentation a heavy load for the pc?

Hello @anon59284200, I bought a new SSD and put it inside my old notebook.
Before that, I created read only snapshots of subvolumes on my old HD and saved them on files by the btrfs send -vf command.
Then I installed the new SSD, I formatted it in btrfs and using btrfs receive -f, I restored the subvolumes on the new drive. Changed them to rw, modified fstab, reinstalled and updated grub and the system was transferred without problems.

Is it useful to keep the journal log files not fragmented, even if they are on a ssd, please?

Thank you.

An easy solution is to limit the space, the logs are allowed to use Arch wiki
Then when the limit is reached, parts of the previous logs will be deleted. For most pcs it is not necessary to keep logs of several years.

But if you get a long logfile in a short time,

It may be worth looking into it. There may be lines with errors that are repeated endlessly because no one did read them and correct the error.