diff --git a/hosts/k8s/kubevirt-shoryu/default.nix b/hosts/k8s/kubevirt-shoryu/default.nix index 5b8cfc36..7043f500 100644 --- a/hosts/k8s/kubevirt-shoryu/default.nix +++ b/hosts/k8s/kubevirt-shoryu/default.nix @@ -57,15 +57,10 @@ in modules.btrbk.enable = true; boot.kernelParams = [ - # disable transparent hugepage(allocate hugepages dynamically) - "transparent_hugepage=never" - - # https://kubevirt.io/user-guide/compute/hugepages/ - # - # pre-allocate hugepages manually(for kubevirt guest vms) - # NOTE: the hugepages allocated here can not be used for other purposes! - # so we should left some memory for the host OS and other vms that don't use hugepages - "hugepagesz=1G" - "hugepages=48" # use 75% of the total memory for hugepages + # Use transparent huge pages on demand (madvise) instead of a fixed 1G hugetlb + # pool. The static pool cannot be overcommitted or shared with the host / + # other VMs, which stranded memory and blocked scheduling; the VMs now use + # ordinary memory (see the instancetypes in k8s-gitops). + "transparent_hugepage=madvise" ]; } diff --git a/hosts/k8s/kubevirt-shushou/default.nix b/hosts/k8s/kubevirt-shushou/default.nix index b160612b..e6754772 100644 --- a/hosts/k8s/kubevirt-shushou/default.nix +++ b/hosts/k8s/kubevirt-shushou/default.nix @@ -54,15 +54,10 @@ in modules.btrbk.enable = true; boot.kernelParams = [ - # disable transparent hugepage(allocate hugepages dynamically) - "transparent_hugepage=never" - - # https://kubevirt.io/user-guide/compute/hugepages/ - # - # pre-allocate hugepages manually(for kubevirt guest vms) - # NOTE: the hugepages allocated here can not be used for other purposes! - # so we should left some memory for the host OS and other vms that don't use hugepages - "hugepagesz=1G" - "hugepages=48" # use 75% of the total memory for hugepages + # Use transparent huge pages on demand (madvise) instead of a fixed 1G hugetlb + # pool. The static pool cannot be overcommitted or shared with the host / + # other VMs, which stranded memory and blocked scheduling; the VMs now use + # ordinary memory (see the instancetypes in k8s-gitops). + "transparent_hugepage=madvise" ]; } diff --git a/hosts/k8s/kubevirt-youko/default.nix b/hosts/k8s/kubevirt-youko/default.nix index 6911116c..c77bd7fe 100644 --- a/hosts/k8s/kubevirt-youko/default.nix +++ b/hosts/k8s/kubevirt-youko/default.nix @@ -54,16 +54,10 @@ in modules.btrbk.enable = true; boot.kernelParams = [ - # disable transparent hugepage(allocate hugepages dynamically) - "transparent_hugepage=never" - - # https://kubevirt.io/user-guide/compute/hugepages/ - # - # pre-allocate hugepages manually(for kubevirt guest vms) - # NOTE: the hugepages allocated here can not be used for other purposes! - # so we should left some memory for the host OS and other vms that don't use hugepages - "hugepagesz=1G" - "hugepages=15" # use 15/24 of the total memory for hugepages + # Use transparent huge pages on demand (madvise) instead of a fixed 1G hugetlb + # pool (cannot be overcommitted/shared; it stranded memory and blocked + # scheduling). The VMs now use ordinary memory. + "transparent_hugepage=madvise" # https://kubevirt.io/user-guide/compute/host-devices/ # diff --git a/lib/genKubeVirtHostModule.nix b/lib/genKubeVirtHostModule.nix index ffc85a06..d1704bbe 100644 --- a/lib/genKubeVirtHostModule.nix +++ b/lib/genKubeVirtHostModule.nix @@ -50,8 +50,18 @@ in # ----- IPv6 ----- # "net.ipv6.conf.all.forwarding" = 1; # Enable forwarding - # --- memory --- # - "vm.swappiness" = 0; # don't swap unless absolutely necessary + # NOTE: vm.swappiness is intentionally NOT set here; it comes from + # modules/nixos/base/zram.nix (mkDefault 180, tuned for the zram device). + # The previous hard-coded 0 disabled swapping entirely, so the zram device + # (already enabled by that module) was never used. + }; + + # zram itself is provided by modules/nixos/base/zram.nix (enabled by default). + # Kill the greediest process before the host starts thrashing / gets OOM-killed. + services.earlyoom = { + enable = true; + freeMemThresholdPercent = 5; + freeSwapThresholdPercent = 5; }; environment.systemPackages = with pkgs; [