From b1d9bbc26e4dbc843ec3bde46a56a77d1b2bcf48 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Thu, 21 Dec 2023 17:08:25 +0800 Subject: [PATCH] feat: enable zram --- modules/nixos/base/misc.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/nixos/base/misc.nix b/modules/nixos/base/misc.nix index d76bccbb..92c27caf 100644 --- a/modules/nixos/base/misc.nix +++ b/modules/nixos/base/misc.nix @@ -27,6 +27,22 @@ # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store nix.settings.auto-optimise-store = true; + # Enable in-memory compressed devices and swap space provided by the zram kernel module. + # By enable this, we can store more data in memory instead of fallback to disk-based swap devices directly, and thus improve I/O performance. + zramSwap = { + enable = true; + # one of "lzo", "lz4", "zstd" + algorithm = "zstd"; + # Priority of the zram swap devices. + # It should be a number higher than the priority of your disk-based swap devices + # (so that the system will fill the zram swap devices before falling back to disk swap). + priority = 5; + # Maximum total amount of memory that can be stored in the zram swap devices (as a percentage of your total memory). + # Defaults to 1/2 of your total RAM. Run zramctl to check how good memory is compressed. + # This doesn’t define how much memory will be used by the zram swap devices. + memoryPercent = 50; + }; + # for power management services = { power-profiles-daemon = {