From: Gregory Price Date: Tue, 23 Sep 2025 12:19:48 +0000 (-0400) Subject: config / qemu: support maxmem argument X-Git-Tag: v26~113^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e070a8da3177021d1cd1b7fc9093b087aa3cd876;p=thirdparty%2Fmkosi.git config / qemu: support maxmem argument Add maxmem=X support for the `-m` option. This is needed for hotplug memory regions added at runtime by emulated CXL devices. Signed-off-by: Gregory Price --- diff --git a/mkosi/config.py b/mkosi/config.py index 3823090e4..01ff458f4 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -2116,6 +2116,7 @@ class Config: console: ConsoleMode cpus: int ram: int + maxmem: int kvm: ConfigFeature vsock: ConfigFeature vsock_cid: int @@ -4113,6 +4114,15 @@ SETTINGS: list[ConfigSetting[Any]] = [ compat_names=("QemuMem",), scope=SettingScope.main, ), + ConfigSetting( + dest="maxmem", + name="MaxMem", + metavar="BYTES", + section="Runtime", + parse=config_parse_bytes, + help="Configure guest's MaxMem size", + scope=SettingScope.main, + ), ConfigSetting( dest="kvm", name="KVM", @@ -5623,6 +5633,7 @@ def summary(config: Config) -> str: Console: {config.console} CPU Cores: {config.cpus} RAM: {format_bytes(config.ram)} + MaxMem: {format_bytes_or_none(config.maxmem)} KVM: {config.kvm} VSock: {config.vsock} VSock Connection ID: {VsockCID.format(config.vsock_cid)} diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 0e10a27da..e7228e2a5 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -1241,11 +1241,15 @@ def run_qemu(args: Args, config: Config) -> None: if config.console == ConsoleMode.read_only: cmdline += ["--read-only"] + memory = f"{config.ram // 1024**2}M" + if config.maxmem: + memory += f",maxmem={(config.maxmem // 1024**2)}M" + cmdline += [ qemu, "-machine", machine, "-smp", str(config.cpus or os.cpu_count()), - "-m", f"{config.ram // 1024**2}M", + "-m", memory, "-object", "rng-random,filename=/dev/urandom,id=rng0", "-device", "virtio-rng-pci,rng=rng0,id=rng-device0", "-device", "virtio-balloon,free-page-reporting=on", diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index 1733fb13c..ccfbcc72c 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -1744,6 +1744,10 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, `RAM=`, `--ram=` : Configures the amount of RAM assigned to the guest when booting a virtual machine. Defaults to `2G`. +`MaxMem=`, `--maxmem=` +: Configures the maximum amount of memory the guest may deploy in total (RAM + hotplug memory devices). + Defaults to the amount of RAM configured. + `KVM=`, `--kvm=` : Configures whether KVM acceleration should be used when booting a virtual machine. Takes a boolean value or `auto`. Defaults to `auto`. diff --git a/tests/test_json.py b/tests/test_json.py index 5e4928da1..f8a01ff39 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -258,6 +258,7 @@ def test_config() -> None: "json", "changelog" ], + "MaxMem": 123, "MicrocodeHost": true, "MinimumVersion": "123", "Mirror": null, @@ -513,6 +514,7 @@ def test_config() -> None: machine="machine", make_initrd=False, manifest_format=[ManifestFormat.json, ManifestFormat.changelog], + maxmem=123, microcode_host=True, devicetrees=["freescale/imx8mm-verdin-nonwifi-dev.dtb"], minimum_version="123",