]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
config / qemu: support maxmem argument
authorGregory Price <gourry@gourry.net>
Tue, 23 Sep 2025 12:19:48 +0000 (08:19 -0400)
committerGregory Price <gourry@gourry.net>
Tue, 23 Sep 2025 16:25:25 +0000 (12:25 -0400)
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 <gourry@gourry.net>
mkosi/config.py
mkosi/qemu.py
mkosi/resources/man/mkosi.1.md
tests/test_json.py

index 3823090e4c2994969ad75ff5a07f00002352710c..01ff458f4fdc05e162251fcfcc0a352672bece0d 100644 (file)
@@ -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)}
index 0e10a27dad141988497057185c7d69756aefe984..e7228e2a5834aa91363d042aa016eab755fa04b3 100644 (file)
@@ -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",
index 1733fb13ceb5864f323823df26b7d65bc004af25..ccfbcc72cfe6e9875725b826305b4b9654b4b1a3 100644 (file)
@@ -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`.
index 5e4928da126fc1d4c562ac9cb9420fb8529efb1d..f8a01ff39abde10a1597c91348f2f16c03b401a6 100644 (file)
@@ -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",