Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19031,6 +19031,12 @@
githubId = 7536431;
name = "Jonas Fierlings";
};
pigsinablanket = {
email = "[email protected]";
github = "pigsinspace";
githubId = 28584473;
name = "Daniel Reimer";
};
pimeys = {
email = "[email protected]";
github = "pimeys";
Expand Down
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@

- [uMurmur](https://umurmur.net), minimalistic Mumble server primarily targeted to run on embedded computers. Available as [services.umurmur](options.html#opt-services.umurmur).

- [zswap](https://www.kernel.org/doc/Documentation/vm/zswap.txt) is a lightweight compressed cache for swap pages. It takes pages that are in the process of being swapped out and attempts to compress them into a dynamically allocated RAM-based memory pool. Available as [zswap](options.html#zswap)

- [Zenoh](https://zenoh.io/), a pub/sub/query protocol with low overhead. The Zenoh router daemon is available as [services.zenohd](options.html#opt-services.zenohd.enable)

- [ytdl-sub](https://github.com/jmbannon/ytdl-sub), a tool that downloads media via yt-dlp and prepares it for your favorite media player, including Kodi, Jellyfin, Plex, Emby, and modern music players. Available as [services.ytdl-sub](options.html#opt-services.ytdl-sub.instances).
Expand Down
110 changes: 110 additions & 0 deletions nixos/modules/config/zswap.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
config,
lib,
pkgs,
...
}:

let

cfg = config.zswap;

in

{
###### interface

options = {

zswap = {

enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Enable zswap, a lightweight compressed cache for swap pages.
See [
https://www.kernel.org/doc/Documentation/vm/zswap.txt
] (https://www.kernel.org/doc/Documentation/vm/zswap.txt)
'';
};

maxPoolPercent = lib.mkOption {
default = 20;
type = lib.types.int;
description = ''
The maximum percentage of memory that the compressed pool can occupy.
'';
};

compressor = lib.mkOption {
default = "zstd";
example = "lzo";
type =
with lib.types;
either (enum [
"842"
"lzo"
"lz4"
"lz4hc"
"zstd"
]) str;
description = ''
Compression algorithm. `lzo` has good compression,
but is slow. `lz4` has bad compression, but is fast.
`zstd` is both good compression and fast.
'';
};

zpool = lib.mkOption {
default = "zsmalloc";
type =
with lib.types;
either (enum [
"zsmalloc"
"zbud"
]) str;
description = ''
Zswap makes use of zpool for managing the compressed memory pool.
See [
https://docs.kernel.org/admin-guide/mm/zswap.html#design
] (https://docs.kernel.org/admin-guide/mm/zswap.html#design).
'';
};

acceptThresholdPercent = lib.mkOption {
default = 90;
type = lib.types.int;
description = ''
Sets the threshold at which zswap would start accepting pages again
after it became full.
'';
};
};

};

config = lib.mkMerge [

(lib.mkIf cfg.enable {
boot.kernelParams = [ "zswap.enabled=1" ];

system.activationScripts.zswap-activate = ''
echo ${toString cfg.maxPoolPercent} > /sys/module/zswap/parameters/max_pool_percent
echo ${cfg.compressor} > /sys/module/zswap/parameters/compressor
echo ${cfg.zpool} > /sys/module/zswap/parameters/zpool
echo ${toString cfg.acceptThresholdPercent} > /sys/module/zswap/parameters/accept_threshold_percent
echo "Y" > /sys/module/zswap/parameters/enabled
'';
})

(lib.mkIf (!cfg.enable) {
system.activationScripts.zswap-activate = ''
echo N > /sys/module/zswap/parameters/enabled
'';
})

];

meta.maintainers = with lib.maintainers; [ pigsinablanket ];
}
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
./config/xdg/sounds.nix
./config/xdg/terminal-exec.nix
./config/zram.nix
./config/zswap.nix
./hardware/acpilight.nix
./hardware/all-firmware.nix
./hardware/all-hardware.nix
Expand Down
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ in
zram-generator = runTest ./zram-generator.nix;
zrepl = runTest ./zrepl.nix;
zsh-history = runTest ./zsh-history.nix;
zswap = runTest ./zswap.nix;
zwave-js = runTest ./zwave-js.nix;
zwave-js-ui = runTest ./zwave-js-ui.nix;
}
32 changes: 32 additions & 0 deletions nixos/tests/zswap.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ lib, ... }:
{
name = "zswap";
meta.maintainers = with lib.maintainers; [ pigsinablanket ];

nodes.machine =
{ ... }:
{
zswap = {
enable = true;
compressor = "zstd";
zpool = "zsmalloc";
maxPoolPercent = 25;
acceptThresholdPercent = 85;
};

};

testScript = ''
machine.start()

machine.wait_for_unit("multi-user.target")

machine.succeed("cat /sys/module/zswap/parameters/enabled | grep Y")
machine.succeed("cat /sys/module/zswap/parameters/compressor | grep zstd")
machine.succeed("cat /sys/module/zswap/parameters/zpool | grep zsmalloc")
machine.succeed("cat /sys/module/zswap/parameters/max_pool_percent | grep 25")
machine.succeed("cat /sys/module/zswap/parameters/accept_threshold_percent | grep 85")

machine.succeed("dmesg | grep 'zswap: loaded using pool zstd/zsmalloc'")
'';
}