From nobody Wed May 14 07:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526051385032668.8821261435883; Fri, 11 May 2018 08:09:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC68C30C54F9; Fri, 11 May 2018 15:09:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BAF42015992; Fri, 11 May 2018 15:09:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 353B34CAA7; Fri, 11 May 2018 15:09:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BF9UqV008551 for ; Fri, 11 May 2018 11:09:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F11483B6B; Fri, 11 May 2018 15:09:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25F53728F5; Fri, 11 May 2018 15:09:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:09:17 +0200 Message-Id: <331424013ed60549476eefa5fabc7df2226b7369.1526051215.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com Subject: [libvirt] [PATCH v5 6/7] conf: Introduce memoryBacking/discard X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 11 May 2018 15:09:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU has possibility to call madvise(.., MADV_REMOVE) in some cases. Expose this feature to users by new element/attribute discard. Signed-off-by: Michal Privoznik Reviewed-by: J=EF=BF=BDn Tomko --- docs/formatdomain.html.in | 34 +++++++++++++++++++++++= -- docs/schemas/cputypes.rng | 5 ++++ docs/schemas/domaincommon.rng | 10 ++++++++ src/conf/domain_conf.c | 36 +++++++++++++++++++++++= +++- src/conf/domain_conf.h | 3 +++ src/conf/numa_conf.c | 27 ++++++++++++++++++++ src/conf/numa_conf.h | 3 +++ src/libvirt_private.syms | 1 + tests/qemuxml2argvdata/hugepages-pages.xml | 3 ++- tests/qemuxml2argvdata/hugepages-pages3.xml | 4 +-- tests/qemuxml2argvdata/hugepages-pages7.xml | 4 +-- tests/qemuxml2xmloutdata/hugepages-pages.xml | 3 ++- tests/qemuxml2xmloutdata/hugepages-pages3.xml | 4 +-- 13 files changed, 126 insertions(+), 11 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 072f9a0fdc..80172c18d0 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1016,6 +1016,7 @@ <source type=3D"file|anonymous"/> <access mode=3D"shared|private"/> <allocation mode=3D"immediate|ondemand"/> + <discard/> </memoryBacking> ... </domain> @@ -1070,6 +1071,14 @@ numa node by memAccess
allocation
Specify when allocate the memory
+
discard
+
When set and supported by hypervisor the memory + content is discarded just before guest shuts down (or + when DIMM module is unplugged). Please note that this is + just an optimization and is not guaranteed to work in + all cases (e.g. when hypervisor crashes). + Since 4.4.0 (QEMU/KVM only) +
=20 =20 @@ -1608,7 +1617,7 @@ <cpu> ... <numa> - <cell id=3D'0' cpus=3D'0-3' memory=3D'512000' unit=3D'KiB'/> + <cell id=3D'0' cpus=3D'0-3' memory=3D'512000' unit=3D'KiB' discard= =3D'yes'/> <cell id=3D'1' cpus=3D'4-7' memory=3D'512000' unit=3D'KiB' memAcces= s=3D'shared'/> </numa> ... @@ -1634,6 +1643,13 @@ memAccess can control whether the memory is to be mapped as "shared" or "private". This is valid only for hugepages-backed memory and nvdimm modules. + + Each cell element can have an optional + discard attribute which fine tunes the discard + feature for given numa node as described under + Memory Backing. + Accepted values are yes and no. + Since 4.4.0

=20

@@ -7883,7 +7899,7 @@ qemu-kvm -net nic,model=3D? /dev/null

 ...
 <devices>
-  <memory model=3D'dimm' access=3D'private'>
+  <memory model=3D'dimm' access=3D'private' discard=3D'yes'>
     <target>
       <size unit=3D'KiB'>524287</size>
       <node>0</node>
@@ -7937,6 +7953,20 @@ qemu-kvm -net nic,model=3D? /dev/null
         

=20 +
discard
+
+

+ An optional attribute discard + (since 4.4.0) that provides + capability to fine tune discard of data on per module + basis. Accepted values are yes and + no. The feature is described here: + Memory Backing. + This attribute is allowed only for + model=3D'dimm'. +

+
+
source

diff --git a/docs/schemas/cputypes.rng b/docs/schemas/cputypes.rng index c45b6dfb28..1f1e0e36d5 100644 --- a/docs/schemas/cputypes.rng +++ b/docs/schemas/cputypes.rng @@ -129,6 +129,11 @@ + + + + + diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 8c446ca418..13af5b74a4 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -633,6 +633,11 @@ + + + + + @@ -5124,6 +5129,11 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6786d81c9b..86229db654 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5516,6 +5516,20 @@ virDomainVideoDefValidate(const virDomainVideoDef *v= ideo) } =20 =20 +static int +virDomainMemoryDefValidate(const virDomainMemoryDef *mem) +{ + if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM && + mem->discard =3D=3D VIR_TRISTATE_BOOL_YES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("discard is not supported for nvdimms")); + return -1; + } + + return 0; +} + + static int virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, const virDomainDef *def) @@ -5548,6 +5562,9 @@ virDomainDeviceDefValidateInternal(const virDomainDev= iceDef *dev, case VIR_DOMAIN_DEVICE_VIDEO: return virDomainVideoDefValidate(dev->data.video); =20 + case VIR_DOMAIN_DEVICE_MEMORY: + return virDomainMemoryDefValidate(dev->data.memory); + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: @@ -5560,7 +5577,6 @@ virDomainDeviceDefValidateInternal(const virDomainDev= iceDef *dev, case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: @@ -15673,6 +15689,16 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr x= mlopt, } VIR_FREE(tmp); =20 + if ((tmp =3D virXMLPropString(memdevNode, "discard"))) { + if ((val =3D virTristateBoolTypeFromString(tmp)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid discard value '%s'"), tmp); + goto error; + } + + def->discard =3D val; + } + /* source */ if ((node =3D virXPathNode("./source", ctxt)) && virDomainMemorySourceDefParseXML(node, ctxt, def) < 0) @@ -18999,6 +19025,9 @@ virDomainDefParseXML(xmlDocPtr xml, if (virXPathBoolean("boolean(./memoryBacking/locked)", ctxt)) def->mem.locked =3D true; =20 + if (virXPathBoolean("boolean(./memoryBacking/discard)", ctxt)) + def->mem.discard =3D VIR_TRISTATE_BOOL_YES; + /* Extract blkio cgroup tunables */ if (virXPathUInt("string(./blkiotune/weight)", ctxt, &def->blkio.weight) < 0) @@ -25259,6 +25288,9 @@ virDomainMemoryDefFormat(virBufferPtr buf, if (def->access) virBufferAsprintf(buf, " access=3D'%s'", virDomainMemoryAccessTypeToString(def->access)); + if (def->discard) + virBufferAsprintf(buf, " discard=3D'%s'", + virTristateBoolTypeToString(def->discard)); virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); =20 @@ -26605,6 +26637,8 @@ virDomainMemtuneFormat(virBufferPtr buf, if (mem->allocation) virBufferAsprintf(&childBuf, "\n", virDomainMemoryAllocationTypeToString(mem->alloc= ation)); + if (mem->discard) + virBufferAddLit(&childBuf, "\n"); =20 if (virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf) < 0) goto cleanup; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 15d228ba9e..07d04fb2f9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2105,6 +2105,7 @@ typedef enum { =20 struct _virDomainMemoryDef { virDomainMemoryAccess access; + virTristateBool discard; =20 /* source */ virBitmapPtr sourceNodes; @@ -2267,6 +2268,8 @@ struct _virDomainMemtune { int source; /* enum virDomainMemorySource */ int access; /* enum virDomainMemoryAccess */ int allocation; /* enum virDomainMemoryAllocation */ + + virTristateBool discard; }; =20 typedef struct _virDomainPowerManagement virDomainPowerManagement; diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 9307dd93d3..bf42946a99 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 configura= tion */ + int discard; /* discard-data for memory-backend-file, virTristateB= ool */ =20 struct _virDomainNumaDistance { unsigned int value; /* locality value for node i->j or j->i */ @@ -947,6 +948,18 @@ virDomainNumaDefCPUParseXML(virDomainNumaPtr def, VIR_FREE(tmp); } =20 + if ((tmp =3D virXMLPropString(nodes[i], "discard"))) { + if ((rc =3D virTristateBoolTypeFromString(tmp)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Invalid 'discard' attribute value '%s'"), + tmp); + goto cleanup; + } + + def->mem_nodes[cur_cell].discard =3D rc; + VIR_FREE(tmp); + } + /* Parse NUMA distances info */ if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0) goto cleanup; @@ -967,6 +980,7 @@ virDomainNumaDefCPUFormatXML(virBufferPtr buf, virDomainNumaPtr def) { virDomainMemoryAccess memAccess; + int discard; char *cpustr; size_t ncells =3D virDomainNumaGetNodeCount(def); size_t i; @@ -980,6 +994,7 @@ virDomainNumaDefCPUFormatXML(virBufferPtr buf, int ndistances; =20 memAccess =3D virDomainNumaGetNodeMemoryAccessMode(def, i); + discard =3D virDomainNumaGetNodeDiscard(def, i); =20 if (!(cpustr =3D virBitmapFormat(virDomainNumaGetNodeCpumask(def, = i)))) return -1; @@ -994,6 +1009,10 @@ virDomainNumaDefCPUFormatXML(virBufferPtr buf, virBufferAsprintf(buf, " memAccess=3D'%s'", virDomainMemoryAccessTypeToString(memAccess)= ); =20 + if (discard) + virBufferAsprintf(buf, " discard=3D'%s'", + virTristateBoolTypeToString(discard)); + ndistances =3D def->mem_nodes[i].ndistances; if (ndistances =3D=3D 0) { virBufferAddLit(buf, "/>\n"); @@ -1304,6 +1323,14 @@ virDomainNumaGetNodeMemoryAccessMode(virDomainNumaPt= r numa, } =20 =20 +virTristateBool +virDomainNumaGetNodeDiscard(virDomainNumaPtr numa, + size_t node) +{ + return numa->mem_nodes[node].discard; +} + + unsigned long long virDomainNumaGetNodeMemorySize(virDomainNumaPtr numa, size_t node) diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index 7947fdb219..85269be565 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -102,6 +102,9 @@ virBitmapPtr virDomainNumaGetNodeCpumask(virDomainNumaP= tr numa, virDomainMemoryAccess virDomainNumaGetNodeMemoryAccessMode(virDomainNumaPt= r numa, size_t node) ATTRIBUTE_NONNULL(1); +virTristateBool virDomainNumaGetNodeDiscard(virDomainNumaPtr numa, + size_t node) + ATTRIBUTE_NONNULL(1); unsigned long long virDomainNumaGetNodeMemorySize(virDomainNumaPtr numa, size_t node) ATTRIBUTE_NONNULL(1); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5fea1bca41..d28a751ebd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -750,6 +750,7 @@ virDomainNumaGetMaxCPUID; virDomainNumaGetMemorySize; virDomainNumaGetNodeCount; virDomainNumaGetNodeCpumask; +virDomainNumaGetNodeDiscard; virDomainNumaGetNodeDistance; virDomainNumaGetNodeMemoryAccessMode; virDomainNumaGetNodeMemorySize; diff --git a/tests/qemuxml2argvdata/hugepages-pages.xml b/tests/qemuxml2arg= vdata/hugepages-pages.xml index f9270782d4..cba83e754c 100644 --- a/tests/qemuxml2argvdata/hugepages-pages.xml +++ b/tests/qemuxml2argvdata/hugepages-pages.xml @@ -8,6 +8,7 @@ + 4 @@ -21,7 +22,7 @@ - + diff --git a/tests/qemuxml2argvdata/hugepages-pages3.xml b/tests/qemuxml2ar= gvdata/hugepages-pages3.xml index 3d3b3f3cc3..147acc4c95 100644 --- a/tests/qemuxml2argvdata/hugepages-pages3.xml +++ b/tests/qemuxml2argvdata/hugepages-pages3.xml @@ -15,8 +15,8 @@ - - + + diff --git a/tests/qemuxml2argvdata/hugepages-pages7.xml b/tests/qemuxml2ar= gvdata/hugepages-pages7.xml index d75cf5afa3..28c72f85a7 100644 --- a/tests/qemuxml2argvdata/hugepages-pages7.xml +++ b/tests/qemuxml2argvdata/hugepages-pages7.xml @@ -43,7 +43,7 @@

- + 1-3 1048576 @@ -54,7 +54,7 @@
- + 524287 0 diff --git a/tests/qemuxml2xmloutdata/hugepages-pages.xml b/tests/qemuxml2x= mloutdata/hugepages-pages.xml index 498610a217..292454588e 100644 --- a/tests/qemuxml2xmloutdata/hugepages-pages.xml +++ b/tests/qemuxml2xmloutdata/hugepages-pages.xml @@ -8,6 +8,7 @@ + 4 @@ -21,7 +22,7 @@ - + diff --git a/tests/qemuxml2xmloutdata/hugepages-pages3.xml b/tests/qemuxml2= xmloutdata/hugepages-pages3.xml index be21c3eddd..90e6efa5ea 100644 --- a/tests/qemuxml2xmloutdata/hugepages-pages3.xml +++ b/tests/qemuxml2xmloutdata/hugepages-pages3.xml @@ -15,8 +15,8 @@ - - + + --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list