Btrfs: Difference between revisions

Pigs (talk | contribs)
Compression: talk about compression algos and levels
Line 48: Line 48:
=== Compression ===
=== Compression ===


<code>nixos-generate-config --show-hardware-config</code> doesn't detect mount options automatically, so to enable compression, you must specify it and other mount options in a persistent configuration:
<code>nixos-generate-config</code> doesn't detect mount options automatically. To enable compression, you must specify them manually and other mount options in your <code>configuration.nix</code>:


<syntaxhighlight lang="nix">
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
fileSystems = {
fileSystems = {
   "/".options = [ "compress=zstd" ];
   "/".options = [ "compress=zstd" ];
Line 57: Line 58:
   "/swap".options = [ "noatime" ];
   "/swap".options = [ "noatime" ];
};
};
</syntaxhighlight>
</nowiki>
}}
 
Btrfs supports a few compression algorithms, each with different trade-offs:
 
* <code>zstd</code>: Good compression ratio and performance, especially for general-purpose workloads. You can specify compression levels, as example <code>compress=zstd:3</code>.
 
* <code>lzo</code>: Faster but provides lower compression ratios. Good for low powered systems or where performance is important.
 
* <code>zlib</code>: Higher compression ratio but slower performance. Less commonly used nowadays in favor of zstd.
 
You can find more details on the official [https://btrfs.readthedocs.io/en/latest/Compression.html Btrfs Compression Documentation].
 
{{note| Compression is applied only to newly written data. Existing data won't be compressed unless rewritten. (e.g., <code>btrfs filesystem defrag -r -v -czstd /path</code>)}}


=== Swap file ===
=== Swap file ===