Swap: Difference between revisions

Clarify swap on zvol situation. Add notes to zram (recommendation to use userspace oom-killer, zswap instead of zram with writeback). Expand zswap section.
m boot.zswap configuration module was added. Removed manual configuration of boot.kernelParams. Added reference to boot.zswap option.
 
Line 90: Line 90:
Unlike zram, zswap requires a disk-based swap device or file to back it.
Unlike zram, zswap requires a disk-based swap device or file to back it.


Zswap is controlled by kernel parameters and can be enabled in your NixOS configuration by setting appropriate options through <code>boot.kernelParams</code>.
Zswap is controlled by kernel parameters and can be enabled in your NixOS configuration by using the {{nixos:option|boot.zswap}} options.


{{file|/etc/nixos/configuration.nix|nix|
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
<nowiki>
   boot.kernelParams = [
   boot.zswap = {
    "zswap.enabled=1" # enables zswap
     enable = true;
     "zswap.compressor=lz4" # compression algorithm
     #
     "zswap.max_pool_percent=20" # maximum percentage of RAM that zswap is allowed to use
   };
    "zswap.shrinker_enabled=1" # whether to shrink the pool proactively on high memory pressure
   ];
</nowiki>
</nowiki>
}}
}}
Line 106: Line 104:


You can verify zswap's runtime status via <code>cat /sys/module/zswap/parameters/enabled</code> and inspect usage statistics with <code># grep -r . /sys/kernel/debug/zswap/</code>
You can verify zswap's runtime status via <code>cat /sys/module/zswap/parameters/enabled</code> and inspect usage statistics with <code># grep -r . /sys/kernel/debug/zswap/</code>
A proper zswap configuration module is [https://github.com/NixOS/nixpkgs/pull/470366 currently under review].


== Disable swap ==
== Disable swap ==