]> Git — Sourcephile - julm/julm-nix.git/blob - nixos/profiles/zramSwap.nix
+user/perf(zswap): use zswap instead zramSwap
[julm/julm-nix.git] / nixos / profiles / zramSwap.nix
1 # Warning(perf): using zswap is almost always better, see:
2 # https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html
3 { lib, ... }:
4 with lib;
5 {
6 zramSwap = {
7 enable = true;
8 algorithm = mkDefault "zstd";
9 # There is little point creating a zram greater
10 # than twice the size of memory.
11 memoryPercent = mkDefault 150;
12 # Linux supports multithreaded compression for 1 device since 3.15.
13 # See https://lkml.org/lkml/2014/2/28/404 for details.
14 swapDevices = mkDefault 1;
15 };
16
17 boot.kernel.sysctl = {
18 # Increase cache pressure, which increases the tendency of the kernel to
19 # reclaim memory used for caching of directory and inode objects. You will use
20 # less memory over a longer period of time. The performance hit is negated by
21 # the downside of swapping sooner.
22 "vm.vfs_cache_pressure" = mkDefault 500;
23
24 # Increasing how aggressively the kernel will swap memory pages since we are
25 # using ZRAM first.
26 "vm.swappiness" = mkDefault 100;
27
28 # Background processes will start writing right away when it hits the 1% limit
29 "vm.dirty_background_ratio" = mkDefault 1;
30
31 # The system won’t force synchronous I/O until it gets to 50% dirty_ratio.
32 "vm.dirty_ratio" = mkDefault 50;
33 };
34 }