As far as I know, BTRFS filesystems can be optimized in 2 steps, creation and mounting.
NOTE: read corrections below.
Creation
When creating a filesystem, one can define the hashing function to be used. BTRFS does not yet support blake3, but it supports blake2. According to Wikipedia blake3 is a variant of blake2 that is has fewer rounds and is thus many times faster.
official documentation on BTRFS checksum algorithms
Following that documentation, xxhash, successor to the default CRC32C might be the preferred one.
# create LUKS2 container
cryptsetup luksFormat /dev/DEVICE
cryptsetup open /dev/DEVICE root
# create BTRFS filesystem
mkfs.btrfs -L NIXROOT --csum xxhash /dev/mapper/root
There seems to be no way to change the checksum algorithm of an existing filesystem. The default one is fine, but for new deployments this might be relevant.
Mounting
In hardware-configuration.nix I have added the following arguments
fileSystems."/" =
{ device = "/dev/disk/by-uuid/xxxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxx";
fsType = "btrfs";
options = [ "compress=zstd:??" "discard" ];
};
To my knowledge, the chosen compression is applied for newly created files, so this will change the filesystem over time. The compression is transparent, meaning that files appear uncompressed, but take up less space on disk than their uncompressed sum, and are uncompressed when opened with an application. Only compressible files are compressed, so no unneeded work is done.
At current storage situations, using a high value may give you more freedom without a need for upgrading.
The “discard” option, which, according to the Arch wiki has the potential to leak a small amount of data like the filesystem used, but improves performance on SSDs.
It might cause performance and durability improvements or issues (on older hardware).
You might also be interested in authenticated BTRFS which might be useful when sharing a filesystem with others that should only read it, and all writes are authenticated.
mkfs.btrfs --csum hmac-sha256 --auth-key 0123456 /dev/disk
mount -t btrfs -o auth_key=btrfs:foo /dev/disk /mnt/point