mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-11 07:15:54 +03:00
nixos/zram: add writebackDevice option and corresponding test
This commit is contained in:
parent
d586805a5c
commit
cd3ffbdfe6
@ -82,12 +82,30 @@ in
|
|||||||
{command}`cat /sys/class/block/zram*/comp_algorithm`
|
{command}`cat /sys/class/block/zram*/comp_algorithm`
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
writebackDevice = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
example = "/dev/zvol/tarta-zoot/swap-writeback";
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Write incompressible pages to this device,
|
||||||
|
as there's no gain from keeping them in RAM.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.writebackDevice == null || cfg.swapDevices <= 1;
|
||||||
|
message = "A single writeback device cannot be shared among multiple zram devices";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
||||||
(isModule "ZRAM")
|
(isModule "ZRAM")
|
||||||
];
|
];
|
||||||
@ -112,6 +130,8 @@ in
|
|||||||
zram-size = if cfg.memoryMax != null then "min(${size}, ${toString cfg.memoryMax} / 1024 / 1024)" else size;
|
zram-size = if cfg.memoryMax != null then "min(${size}, ${toString cfg.memoryMax} / 1024 / 1024)" else size;
|
||||||
compression-algorithm = cfg.algorithm;
|
compression-algorithm = cfg.algorithm;
|
||||||
swap-priority = cfg.priority;
|
swap-priority = cfg.priority;
|
||||||
|
} // lib.optionalAttrs (cfg.writebackDevice != null) {
|
||||||
|
writeback-device = cfg.writebackDevice;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
devices));
|
devices));
|
||||||
|
@ -1,18 +1,36 @@
|
|||||||
import ./make-test-python.nix {
|
import ./make-test-python.nix {
|
||||||
name = "zram-generator";
|
name = "zram-generator";
|
||||||
|
|
||||||
nodes.machine = { ... }: {
|
nodes = {
|
||||||
zramSwap = {
|
single = { ... }: {
|
||||||
enable = true;
|
virtualisation = {
|
||||||
priority = 10;
|
emptyDiskImages = [ 512 ];
|
||||||
algorithm = "lz4";
|
};
|
||||||
swapDevices = 2;
|
zramSwap = {
|
||||||
memoryPercent = 30;
|
enable = true;
|
||||||
memoryMax = 10 * 1024 * 1024;
|
priority = 10;
|
||||||
|
algorithm = "lz4";
|
||||||
|
swapDevices = 1;
|
||||||
|
memoryPercent = 30;
|
||||||
|
memoryMax = 10 * 1024 * 1024;
|
||||||
|
writebackDevice = "/dev/vdb";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
machine = { ... }: {
|
||||||
|
zramSwap = {
|
||||||
|
enable = true;
|
||||||
|
priority = 10;
|
||||||
|
algorithm = "lz4";
|
||||||
|
swapDevices = 2;
|
||||||
|
memoryPercent = 30;
|
||||||
|
memoryMax = 10 * 1024 * 1024;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
|
single.wait_for_unit("systemd-zram-setup@zram0.service")
|
||||||
|
|
||||||
machine.wait_for_unit("systemd-zram-setup@zram0.service")
|
machine.wait_for_unit("systemd-zram-setup@zram0.service")
|
||||||
machine.wait_for_unit("systemd-zram-setup@zram1.service")
|
machine.wait_for_unit("systemd-zram-setup@zram1.service")
|
||||||
zram = machine.succeed("zramctl --noheadings --raw")
|
zram = machine.succeed("zramctl --noheadings --raw")
|
||||||
|
Loading…
Reference in New Issue
Block a user