Skip to content

Commit

Permalink
Make deflate-on-oom optional
Browse files Browse the repository at this point in the history
Signed-off-by: Santtu Lakkala <santtu.lakkala@unikie.com>
  • Loading branch information
slakkala authored and astro committed Jan 27, 2025
1 parent 38cf46f commit 3768f49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/runners/cloud-hypervisor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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${
Expand Down
9 changes: 9 additions & 0 deletions nixos-modules/microvm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3768f49

Please sign in to comment.