Swap: Difference between revisions

Hasnep (talk | contribs)
m Change GB to GiB and MB to MiB
Malix (talk | contribs)
Zswap swap cache: deprecate (reason: duplicate)
Line 79: Line 79:


This is probably because the writeback device has already been mounted elsewhere (e.g. as swap). To avoid this you need to do as the [[#Disable swap]] section says and make sure your writeback device is not being mounted as swap (this can happen due to <code>systemd-gpt-auto-generator(8)</code>). Do note that zram writeback does ''not'' respect the swap on-disk format and will destroy your existing swap header.
This is probably because the writeback device has already been mounted elsewhere (e.g. as swap). To avoid this you need to do as the [[#Disable swap]] section says and make sure your writeback device is not being mounted as swap (this can happen due to <code>systemd-gpt-auto-generator(8)</code>). Do note that zram writeback does ''not'' respect the swap on-disk format and will destroy your existing swap header.
== Zswap swap cache ==
[https://docs.kernel.org/admin-guide/mm/zswap.html Zswap] is a compressed RAM cache for swap pages. It acts as a middle layer between system memory and a traditional disk-based swap device, storing compressed pages in RAM before optionally writing them out to disk-based swap if necessary. It acts as an LRU cache.
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>.
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
  boot.kernelParams = [
    "zswap.enabled=1" # enables zswap
    "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>
}}
{{note|If you use the <code>lz4</code> algorithm, you will also need to set {{nixos:option|boot.initrd.systemd.enable}} to true}}
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>


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