#39 improve systemd-journald behavior on btrfs
Opened 3 years ago by chrismurphy. Modified 3 years ago

Since 2015 systemd-journald uses nodatacow on Btrfs for systemd journal files. Upon rotation, they are also submitted for defragmentation. In my experience, there's no benefit to the defragmentation, they don't get meaningfully fragmented in the first place due to the journal being both fallocated and nodatacow.

Proposal: Default behavior nodatacow, and no defragmentation. If /etc/tmpfiles.d/journal-nocow.conf exists, inhibit setting chattr +C (this is already the case), but enable defragmentation on log rotation.

Restated differently, presently defragmentation is unconditional. Let's make it conditional on the journal-nocow.conf file existing, i.e. only defragment the journals if they are datacow.

Relevant commits:
commit 3a92e4ba470611ceec6693640b05eb248d62e32d
tmpfiles: Add +C attrib to the journal files directories
commit f27a386430cc7a27ebd06899d93310fb3bd4cee7
journald: whenever we rotate a file, btrfs defrag it

Upstream devel thread:
https://lists.freedesktop.org/archives/systemd-devel/2021-January/045847.html


I think the above is in-scope for Fedora 34.

The snapshotting of these nodatacow journal files results in significant fragmentation, and defragmenting them is still not snapshot aware so it just explodes the storage requirements and excessive writes do to this.

Therefore a future version of Fedora should consider a "varlog" subvolume mounted at /var/log to prevent logs from being snapshot and rolled back.

Offhand I don't think autodefrag is helpful here. Just avoid snapshotting them, and keep them nodatacow until there's a cow friendly journald format.

Login to comment on this ticket.

Metadata