# Documentation: https://www.kernel.org/doc/html/latest/admin-guide/mm/zswap.html # Explanation: https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html { config, lib, ... }: let cfg = config.zswap; in { options.zswap = { enable = lib.mkEnableOption "zswap compressed swap cache" // { default = true; }; max_pool_percent = lib.mkOption { type = lib.types.int; default = 50; description = "Maximum percentage of RAM to use for the zswap pool."; }; }; config = lib.mkIf cfg.enable { boot = { kernelParams = [ "zswap.enabled=1" "zswap.compressor=zstd" "zswap.max_pool_percent=${toString cfg.max_pool_percent}" "zswap.shrinker_enabled=1" "zswap.zpool=zsmalloc" ]; initrd.kernelModules = [ "zsmalloc" "zstd" ]; }; }; }