Open ShamrockLee opened 3 years ago
Just to remind people who find this issue, a custom kernel could be necessary depending on the options you want to use, e.g.:
{ boot.kernelPatches =
optional (config.swapDevices != []) {
name = "zswap";
patch = null;
extraConfig = ''
Z3FOLD y
CRYPTO_LZ4 y
'';
};
}
@ShamrockLee thanks for bringing this up again - do you have any code for such a module lying around?
@ShamrockLee thanks for bringing this up again - do you have any code for such a module lying around?
No.
My knowledge toward the Linux kernel is very limited, and I havent found any documentation (beside the issue) about how to enable it on NixOS, so I'm not sure how to do it right.
I marked this as stale due to inactivity. → More info
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
I marked this as stale due to inactivity. → More info
Please include these in the default kernel.
Everybody keeps reinventing the wheel, and nobody's helping each other solve this simple problem. I suck at writing Nix and Systemd units, but here's my solution that will hopefully help others.
A Hacked Systemd Unit to Enable Zswap. It's not pretty, but it works for me. I welcome improvements.
systemd.services.zswap = {
description = "Enable ZSwap, set to LZ4 and Z3FOLD";
enable = true;
wantedBy = [ "basic.target" ];
path = [ pkgs.bash ];
serviceConfig = {
ExecStart = ''${pkgs.bash}/bin/bash -c 'cd /sys/module/zswap/parameters&& \
echo 1 > enabled&& \
echo 20 > max_pool_percent&& \
echo lz4 > compressor&& \
echo z3fold > zpool'
'';
Type = "simple";
};
};
You can verify it works by running this
grep -R . /sys/module/zswap/parameters/
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/working-zswap-configuration-different-from-zram/47804/5
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/working-zswap-configuration-different-from-zram/47804/7
Issue description
There is currently no specific modules for zswap, and people configure it semi-manually using
boot.kernelParams
andboot.initrd.kernelModules
. Having a NixOS module that enables and configureszswap
would be convenient to users, and it would also make configuration more structural.Technical details
The current way to enable the
zswap
kernel feature is specifying the needed kernel parameters and kernel modules. The following example is borrowed from #44901 by @ikervagyok :The options may include
zswap.enable
zswap.compressor
zswap.zpool