]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: command: Add helper to align memory sizes
authorPeter Krempa <pkrempa@redhat.com>
Wed, 18 Feb 2015 13:31:47 +0000 (14:31 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2015 13:32:20 +0000 (14:32 +0100)
The memory sizes in qemu are aligned up to 1 MiB boundaries. There are
two places where this was done once for the total size and then for
individual NUMA cell sizes.

Add a function that will align the sizes in one place so that it's clear
where the sizes are aligned.

src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index 958a5519b5d60d9d96e16569ec8668b2aec55e28..aa7a92839a34df09fec4a77848d1ece499ca92e1 100644 (file)
@@ -7270,9 +7270,6 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
     /* using of -numa memdev= cannot be combined with -numa mem=, thus we
      * need to check which approach to use */
     for (i = 0; i < ncells; i++) {
-        unsigned long long cellmem = virDomainNumaGetNodeMemorySize(def->numa, i);
-        virDomainNumaSetNodeMemorySize(def->numa, i, VIR_ROUND_UP(cellmem, 1024));
-
         if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) ||
             virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) {
             if ((rc = qemuBuildMemoryCellBackendStr(def, qemuCaps, cfg, i,
@@ -8490,13 +8487,15 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (qemuBuildDomainLoaderCommandLine(cmd, def, qemuCaps) < 0)
         goto error;
 
+    if (qemuDomainAlignMemorySizes(def) < 0)
+        goto error;
+
     /* Set '-m MB' based on maxmem, because the lower 'memory' limit
      * is set post-startup using the balloon driver. If balloon driver
      * is not supported, then they're out of luck anyway.  Update the
      * XML to reflect our rounding.
      */
     virCommandAddArg(cmd, "-m");
-    virDomainDefSetMemoryInitial(def, VIR_ROUND_UP(virDomainDefGetMemoryInitial(def), 1024));
     virCommandAddArgFormat(cmd, "%llu", virDomainDefGetMemoryInitial(def)  / 1024);
 
     if (def->mem.nhugepages && !virDomainNumaGetNodeCount(def->numa)) {
index ff4307b6282a9cb146bf9cb52274da812c03f53c..2eacef2a7792148a9246148ae5b3d518080f96b6 100644 (file)
@@ -2875,3 +2875,24 @@ qemuDomObjEndAPI(virDomainObjPtr *vm)
     virObjectUnref(*vm);
     *vm = NULL;
 }
+
+
+int
+qemuDomainAlignMemorySizes(virDomainDefPtr def)
+{
+    unsigned long long mem;
+    size_t ncells = virDomainNumaGetNodeCount(def->numa);
+    size_t i;
+
+    /* align NUMA cell sizes if relevant */
+    for (i = 0; i < ncells; i++) {
+        mem = virDomainNumaGetNodeMemorySize(def->numa, i);
+        virDomainNumaSetNodeMemorySize(def->numa, i, VIR_ROUND_UP(mem, 1024));
+    }
+
+    /* align initial memory size */
+    mem = virDomainDefGetMemoryInitial(def);
+    virDomainDefSetMemoryInitial(def, VIR_ROUND_UP(mem, 1024));
+
+    return 0;
+}
index 41e075b98656eb98bbc64694b3275112bf111c65..ba8d3983bd337da712eeaaa5106d2f01b3aa4beb 100644 (file)
@@ -418,4 +418,6 @@ bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
 
 void qemuDomObjEndAPI(virDomainObjPtr *vm);
 
+int qemuDomainAlignMemorySizes(virDomainDefPtr def);
+
 #endif /* __QEMU_DOMAIN_H__ */