diff --git a/lib/runners/cloud-hypervisor.nix b/lib/runners/cloud-hypervisor.nix index 45b6f39d..053a475e 100644 --- a/lib/runners/cloud-hypervisor.nix +++ b/lib/runners/cloud-hypervisor.nix @@ -5,7 +5,7 @@ let inherit (pkgs) lib; - inherit (microvmConfig) vcpu mem balloonMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath; + inherit (microvmConfig) vcpu mem balloonMem deflateOnOOM user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath; inherit (microvmConfig.cloud-hypervisor) extraArgs; kernelPath = { @@ -54,8 +54,9 @@ let balloonOps = opsMapped { size = "${toString balloonMem}M"; - deflate_on_oom = "on"; free_page_reporting = "on"; + } // lib.optionalAttrs deflateOnOOM { + deflate_on_oom = "on"; }; tapMultiQueue = vcpu > 1; diff --git a/lib/runners/qemu.nix b/lib/runners/qemu.nix index b460a187..f6659b16 100644 --- a/lib/runners/qemu.nix +++ b/lib/runners/qemu.nix @@ -39,7 +39,7 @@ let qemu = overrideQemu (if microvmConfig.cpu == null then pkgs.qemu_kvm else pkgs.buildPackages.qemu_full); - inherit (microvmConfig) hostName cpu vcpu mem balloonMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk; + inherit (microvmConfig) hostName cpu vcpu mem balloonMem deflateOnOOM user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk; inherit (microvmConfig.qemu) machine extraArgs serialConsole; inherit (import ../. { inherit (pkgs) lib; }) withDriveLetters; @@ -208,7 +208,9 @@ lib.warnIf (mem == 2048) '' ] ++ lib.optionals (user != null) [ "-user" user ] ++ lib.optionals (socket != null) [ "-qmp" "unix:${socket},server,nowait" ] ++ - lib.optionals (balloonMem > 0) [ "-device" "virtio-balloon,free-page-reporting=on,id=balloon0,deflate-on-oom=on" ] ++ + lib.optionals (balloonMem > 0) [ + "-device" ("virtio-balloon,free-page-reporting=on,id=balloon0" + lib.optionalString (deflateOnOOM) ",deflate-on-oom=on") + ] ++ builtins.concatMap ({ image, letter, serial, direct, readOnly, ... }: [ "-drive" "id=vd${letter},format=raw,file=${image},if=none,aio=io_uring,discard=unmap${ diff --git a/nixos-modules/microvm/options.nix b/nixos-modules/microvm/options.nix index 54f7388f..09c96a26 100644 --- a/nixos-modules/microvm/options.nix +++ b/nixos-modules/microvm/options.nix @@ -123,6 +123,15 @@ in type = types.int; }; + deflateOnOOM = mkOption { + type = types.bool; + default = true; + description = '' + Whether to enable automatic balloon deflation on out-of-memory. + ''; + }; + + forwardPorts = mkOption { type = types.listOf (types.submodule {