Questions about btrfs

I recently reinstalled latest manjaro cinnamon minimal iso to my nvme using btrfs as my filesystem to take advantage of its magic like snapshots and compression

i use the latest lts 5.15.28-1 and planning to use the latest avalaible lts kernel

after a lot of reading from various sources i set my /etc/fstab like this

UUID=6AB2-02F1                            /boot/efi      vfat    umask=0077 0 2
UUID=3ccce400-6cf3-4d91-99a0-d5228a8fe2d3 /              btrfs   subvol=/@,defaults,noatime,commit=120,compress-force=zstd 0 0
UUID=3ccce400-6cf3-4d91-99a0-d5228a8fe2d3 /home          btrfs   subvol=/@home,defaults,noatime,commit=120,compress-force=zstd 0 0
UUID=3ccce400-6cf3-4d91-99a0-d5228a8fe2d3 /var/cache     btrfs   subvol=/@cache,defaults,noatime,commit=120,compress-force=zstd 0 0
UUID=3ccce400-6cf3-4d91-99a0-d5228a8fe2d3 /var/log       btrfs   subvol=/@log,defaults,noatime,commit=120,compress-force=zstd 0 0

any thoughts?

also i stumbled upon btrfs maintanace package

and tweaked balance,scrub,defrag and trim settings mostly in defaults all running monthly except trim for which i use weekly?

is this frequency optimal?

also correct me if i am wrong is btrfsmaintance settings right?

# Run periodic defrag on selected paths. The files from a given path do not
# cross mount points or other subvolumes/snapshots. If you want to defragment
# nested subvolumes, all have to be listed in this variable.
# (Colon separated paths)
BTRFS_DEFRAG_PATHS="/:/home:/var/cache:/var/log"

finally any wisdom regarding btrfs maintenance in general?

Lets say it clear:

The most valuable feature of btrfs is not snapshots nor Compression, but RAID1

You find good Information about Btrfs in the wiki

and in
https://forum.manjaro.org/t/how-to-manual-rollback-with-btrfs/80230/5
https://forum.manjaro.org/t/how-to-rescue-data-from-a-damaged-btrfs-volume/79414/4

The default configuration of btrfsmaintance is fine for me, no need to change frequency/time interval.

btrfsmaintance disabled its own trim service by default, because fstrim already existed.

Run manually fstrim -v / or enable fstrim.timer for systemctl.

i disabled fstrim timer and enabled trim from btrfs maintenance because it makes sure its tasks don’t collide each other

can you confirm that this setting is ok?

BTRFS_DEFRAG_PATHS="/:/home:/var/cache:/var/log"

It depends on BTRFS_DEFRAG_PERIOD, but its default value is “none”.
That means defragment trigger is disabled by default. You do not need to config BTRFS_DEFRAG_PATHS.

But you don’t need to defragment always again, because fragmentation is reset after creating new snapshot.

You can check yourself:
Before:

❯ sudo btrfs filesystem du -s /btrfs/@home/                                                                                      
     Total   Exclusive  Set shared  Filename
  76.76GiB    65.16MiB    72.11GiB  /btrfs/@home/

“Set shared”: 72.11 GB

Run defrag: sudo btrfs filesystem defragment -czstd -r /btrfs/@home/
After defrag:

❯ sudo btrfs filesystem du -s /btrfs/@home/
     Total   Exclusive  Set shared  Filename
  76.76GiB    76.75GiB     8.02MiB  /btrfs/@home/

“Set shared”: 8 MB is closer to 0 MB

If you create a new snapshot:

❯ sudo btrfs filesystem du -s /btrfs/@home/                                                                                       
     Total   Exclusive  Set shared  Filename
  76.76GiB   308.00KiB    73.47GiB  /btrfs/@home/

“Set shared”: back to 73.47 GB

i enabled all 4 tasks via systemd user timers
btrfs-trim set to weekly
defrag,balance and scrub configured to monthly

i presume my settings are ok
BTRFS_DEFRAG_PERIOD=“monthly”
BTRFS_DEFRAG_PATHS="/:/home:/var/cache:/var/log"