[libvirt] [PATCH v4 5/5] qemu: Introduce memoryBacking/discard

Ján Tomko jtomko at redhat.com
Thu Apr 26 12:56:58 UTC 2018


On Fri, Apr 20, 2018 at 11:09:31AM +0200, Michal Privoznik wrote:
>https://bugzilla.redhat.com/show_bug.cgi?id=1480668
>
>QEMU has this new feature memory-backend-file.discard-data=yes
>which is a nifty optimization. Basically, when qemu is quitting
>or on memory hotplug it calls munmap() and close() on the file
>that is backing the memory. However, this does not mean kernel
>won't stop touching that part of memory. It still might. With
>this feature enabled we tell kernel: "we don't need this memory
>nor data stored in it". This makes kernel drop the memory
>immediately without trying to sync memory with the mapped file.
>
>Unfortunately, this cannot be turned on by default because we
>can't be sure when users really don't care about what happens to
>data after qemu dies. So it has to be opt-in. As usual, there are
>three places where one can configure memory attributes. This
>patch adds the feature to all of them.
>

But only tests one of the three ways. It would be nice to split the conf
and qemu changes and provide a XML->XML test.

>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> docs/formatdomain.html.in                    | 34 ++++++++++++++++++++++--
> docs/schemas/cputypes.rng                    |  5 ++++
> docs/schemas/domaincommon.rng                | 10 +++++++
> src/conf/domain_conf.c                       | 39 ++++++++++++++++++++++++++--
> src/conf/domain_conf.h                       |  3 +++
> src/conf/numa_conf.c                         | 27 +++++++++++++++++++
> src/conf/numa_conf.h                         |  3 +++
> src/libvirt_private.syms                     |  1 +
> src/qemu/qemu_command.c                      | 27 ++++++++++++++++---
> tests/qemuxml2argvdata/hugepages-pages7.args |  3 ++-
> tests/qemuxml2argvdata/hugepages-pages7.xml  |  4 +--
> tests/qemuxml2argvtest.c                     |  3 ++-
> 12 files changed, 148 insertions(+), 11 deletions(-)
>

>@@ -26658,7 +26690,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
>     }
>

A perfect candidate to be split out in a separate function...

>     if (def->mem.nhugepages || def->mem.nosharepages || def->mem.locked
>-        || def->mem.source || def->mem.access || def->mem.allocation)
>+        || def->mem.source || def->mem.access || def->mem.allocation
>+        || def->mem.discard)

... and converted to use virXMLFormatElement O:-)

>     {
>         virBufferAddLit(buf, "<memoryBacking>\n");
>         virBufferAdjustIndent(buf, 2);
>@@ -26677,6 +26710,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
>         if (def->mem.allocation)
>             virBufferAsprintf(buf, "<allocation mode='%s'/>\n",
>                 virDomainMemoryAllocationTypeToString(def->mem.allocation));
>+        if (def->mem.discard)
>+            virBufferAddLit(buf, "<discard/>\n");
>
>         virBufferAdjustIndent(buf, -2);
>         virBufferAddLit(buf, "</memoryBacking>\n");
>diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
>index 3c7eccb8ca..52d29124f1 100644
>--- a/src/conf/domain_conf.h
>+++ b/src/conf/domain_conf.h
>@@ -2107,6 +2107,7 @@ typedef enum {
>
> struct _virDomainMemoryDef {
>     virDomainMemoryAccess access;
>+    int discard; /* enum virTristateBool */

You can use virTristateBool discard; directly

>
>     /* source */
>     virBitmapPtr sourceNodes;
>@@ -2269,6 +2270,8 @@ struct _virDomainMemtune {
>     int source; /* enum virDomainMemorySource */
>     int access; /* enum virDomainMemoryAccess */
>     int allocation; /* enum virDomainMemoryAllocation */
>+
>+    int discard; /* enum virTristateBool */

Same here.

> };
>
> typedef struct _virDomainPowerManagement virDomainPowerManagement;
>diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
>index 9307dd93d3..a1bbcfa945 100644
>--- a/src/conf/numa_conf.c
>+++ b/src/conf/numa_conf.c
>@@ -77,6 +77,7 @@ struct _virDomainNuma {
>         virBitmapPtr nodeset;   /* host memory nodes where this guest node resides */
>         virDomainNumatuneMemMode mode;  /* memory mode selection */
>         virDomainMemoryAccess memAccess; /* shared memory access configuration */
>+        int discard; /* discard-data for memory-backend-file, virTristateBool */
>

And here.

>         struct _virDomainNumaDistance {
>             unsigned int value; /* locality value for node i->j or j->i */

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180426/f2fbf0e2/attachment-0001.sig>


More information about the libvir-list mailing list