mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-08-29 06:17:13 +02:00
fix(nixos): gate zram kernel sysctl tunings behind modules.zram.enable
The zram module was auto-imported on all hosts via base scanPaths, and its swappiness=180/page-cluster=0 tunings leaked onto hosts that disabled zram (e.g. idols-ai with a disk swapfile, pushing cold anon pages to disk swap). Wrap the whole module in modules.zram.enable (default true); idols-ai now turns off zram and its tunings with a single switch.
This commit is contained in:
@@ -39,7 +39,8 @@ in
|
|||||||
];
|
];
|
||||||
|
|
||||||
# Zram consumes physical memory for compression, which can cause a deadlock and system hang if the model size approaches the physical memory limit.
|
# Zram consumes physical memory for compression, which can cause a deadlock and system hang if the model size approaches the physical memory limit.
|
||||||
zramSwap.enable = lib.mkForce false;
|
# Disable the whole module (zram device + its swappiness=180 sysctl tunings); this host uses a disk swapfile instead.
|
||||||
|
modules.zram.enable = false;
|
||||||
|
|
||||||
services.sunshine.enable = false;
|
services.sunshine.enable = false;
|
||||||
services.tuned.ppdSettings.main.default = lib.mkForce "performance";
|
services.tuned.ppdSettings.main.default = lib.mkForce "performance";
|
||||||
|
|||||||
@@ -1,5 +1,28 @@
|
|||||||
{ lib, ... }:
|
|
||||||
{
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.modules.zram;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.zram.enable =
|
||||||
|
lib.mkEnableOption ''
|
||||||
|
zram in-memory swap device plus kernel sysctl tunings for it.
|
||||||
|
|
||||||
|
The sysctl tunings (swappiness=180 etc.) are designed for in-memory swap
|
||||||
|
devices only; they are gated behind this switch so that hosts which
|
||||||
|
disable zram (e.g. using a disk swapfile instead) also revert to the
|
||||||
|
kernel default swappiness instead of leaking zram tunings onto disk swap.
|
||||||
|
|
||||||
|
Enabled by default; hosts that want disk-only swap should set it to false.
|
||||||
|
''
|
||||||
|
// {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
# Enable in-memory compressed devices and swap space provided by the zram kernel module.
|
# 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,
|
# 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 when we have a lot of memory.
|
# and thus improve I/O performance when we have a lot of memory.
|
||||||
@@ -15,7 +38,7 @@
|
|||||||
priority = lib.mkDefault 100;
|
priority = lib.mkDefault 100;
|
||||||
# Maximum total amount of memory that can be stored in the zram swap devices (as a percentage of your total memory).
|
# 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.
|
# 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.
|
# This doesn't define how much memory will be used by the zram swap devices.
|
||||||
memoryPercent = lib.mkDefault 50;
|
memoryPercent = lib.mkDefault 50;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +50,7 @@
|
|||||||
|
|
||||||
# vm.watermark_boost_factor - Controls aggressiveness of memory reclaim (default: 15000)
|
# vm.watermark_boost_factor - Controls aggressiveness of memory reclaim (default: 15000)
|
||||||
# Setting to 0 disables watermark boost, preventing premature memory reclamation.
|
# Setting to 0 disables watermark boost, preventing premature memory reclamation.
|
||||||
# This allows fuller memory utilization before the kernel starts reclaiming pages.
|
# This allows fuller memory utilization before the kernel starts reclaiming.
|
||||||
"vm.watermark_boost_factor" = lib.mkDefault 0;
|
"vm.watermark_boost_factor" = lib.mkDefault 0;
|
||||||
|
|
||||||
# vm.watermark_scale_factor - Controls kswapd wakeup frequency (range: 1-1000, default: 10)
|
# vm.watermark_scale_factor - Controls kswapd wakeup frequency (range: 1-1000, default: 10)
|
||||||
@@ -41,4 +64,5 @@
|
|||||||
# For low-latency devices like zram, readahead hurts performance by fetching unnecessary data.
|
# For low-latency devices like zram, readahead hurts performance by fetching unnecessary data.
|
||||||
"vm.page-cluster" = lib.mkDefault 0;
|
"vm.page-cluster" = lib.mkDefault 0;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user