[libvirt] [PATCHv2 5/7] qemu: command: Add helper to align memory sizes

Martin Kletzander mkletzan at redhat.com
Thu Feb 26 13:45:06 UTC 2015


On Wed, Feb 25, 2015 at 11:22:04AM +0100, Peter Krempa wrote:
>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.
>---
>
>Notes:
>    Version 2:
>    - Already ACKed but didn't make sense to push.
>
> src/qemu/qemu_command.c |  7 +++----
> src/qemu/qemu_domain.c  | 21 +++++++++++++++++++++
> src/qemu/qemu_domain.h  |  2 ++
> 3 files changed, 26 insertions(+), 4 deletions(-)
>
>diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
>index 13b54fe..576c6b1 100644
>--- a/src/qemu/qemu_command.c
>+++ b/src/qemu/qemu_command.c
>@@ -7177,9 +7177,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,
>@@ -8313,13 +8310,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)) {
>diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>index ac5ca74..37804c5 100644
>--- a/src/qemu/qemu_domain.c
>+++ b/src/qemu/qemu_domain.c
>@@ -2837,3 +2837,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));
>+

ACK without these accessors (so it can go it before we decide on the
naming).

>+    return 0;
>+}
>diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
>index b2c3881..faf4ee2 100644
>--- a/src/qemu/qemu_domain.h
>+++ b/src/qemu/qemu_domain.h
>@@ -414,4 +414,6 @@ int qemuDomainJobInfoToParams(qemuDomainJobInfoPtr jobInfo,
>
> void qemuDomObjEndAPI(virDomainObjPtr *vm);
>
>+int qemuDomainAlignMemorySizes(virDomainDefPtr def);
>+
> #endif /* __QEMU_DOMAIN_H__ */
>--
>2.2.2
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150226/4d4c4719/attachment-0001.sig>


More information about the libvir-list mailing list