From nobody Wed May 14 06:22: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 1526051390006746.0211665634216; Fri, 11 May 2018 08:09:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8210216B; Fri, 11 May 2018 15:09:48 +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 51CC530012DA; Fri, 11 May 2018 15:09:48 +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 0EAB43FCFC; Fri, 11 May 2018 15:09:48 +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 w4BF9V13008566 for ; Fri, 11 May 2018 11:09:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5DDE0728F5; Fri, 11 May 2018 15:09:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id D944783B79; Fri, 11 May 2018 15:09:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:09:18 +0200 Message-Id: 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 7/7] qemu: Implement 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 11 May 2018 15:09:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1480668 QEMU has this new feature memory-backend-file.discard-data=3Dyes 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. Signed-off-by: Michal Privoznik Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_command.c | 27 ++++++++++++++++++++++++= --- tests/qemuxml2argvdata/hugepages-pages.args | 12 ++++++------ tests/qemuxml2argvdata/hugepages-pages3.args | 3 ++- tests/qemuxml2argvdata/hugepages-pages7.args | 3 ++- tests/qemuxml2argvtest.c | 9 ++++++--- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 81a9811d14..11ad77f145 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3029,6 +3029,7 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPro= ps, unsigned long long pagesize =3D mem->pagesize; bool needHugepage =3D !!pagesize; bool useHugepage =3D !!pagesize; + int discard =3D mem->discard; =20 /* The difference between @needHugepage and @useHugepage is that the l= atter * is true whenever huge page is defined for the current memory cell. @@ -3039,8 +3040,7 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPro= ps, *backendProps =3D NULL; *backendType =3D NULL; =20 - if (memAccess =3D=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT && - mem->targetNode >=3D 0) { + if (mem->targetNode >=3D 0) { /* memory devices could provide a invalid guest node */ if (mem->targetNode >=3D virDomainNumaGetNodeCount(def->numa)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -3050,12 +3050,19 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendP= rops, return -1; } =20 - memAccess =3D virDomainNumaGetNodeMemoryAccessMode(def->numa, mem-= >targetNode); + if (memAccess =3D=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + memAccess =3D virDomainNumaGetNodeMemoryAccessMode(def->numa, = mem->targetNode); + + if (discard =3D=3D VIR_TRISTATE_BOOL_ABSENT) + discard =3D virDomainNumaGetNodeDiscard(def->numa, mem->target= Node); } =20 if (memAccess =3D=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) memAccess =3D def->mem.access; =20 + if (discard =3D=3D VIR_TRISTATE_BOOL_ABSENT) + discard =3D def->mem.discard; + if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 && virDomainNumatuneGetMode(def->numa, -1, &mode) < 0) mode =3D VIR_DOMAIN_NUMATUNE_MEM_STRICT; @@ -3143,6 +3150,20 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPr= ops, NULL) < 0) goto cleanup; =20 + if (!mem->nvdimmPath && + discard =3D=3D VIR_TRISTATE_BOOL_YES) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE_DIS= CARD)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this QEMU doesn't support memory discard= ")); + goto cleanup; + } + + if (virJSONValueObjectAdd(props, + "B:discard-data", true, + NULL) < 0) + goto cleanup; + } + switch (memAccess) { case VIR_DOMAIN_MEMORY_ACCESS_SHARED: if (virJSONValueObjectAdd(props, "b:share", true, NULL) < 0) diff --git a/tests/qemuxml2argvdata/hugepages-pages.args b/tests/qemuxml2ar= gvdata/hugepages-pages.args index 7ece0272a0..b52cd581d5 100644 --- a/tests/qemuxml2argvdata/hugepages-pages.args +++ b/tests/qemuxml2argvdata/hugepages-pages.args @@ -11,20 +11,20 @@ QEMU_AUDIO_DRV=3Dnone \ -m 4096 \ -smp 4,sockets=3D4,cores=3D1,threads=3D1 \ -object memory-backend-file,id=3Dram-node0,prealloc=3Dyes,\ -mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,size=3D1073741824,\ -host-nodes=3D0-3,policy=3Dbind \ +mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,discard-data=3Dyes,\ +size=3D1073741824,host-nodes=3D0-3,policy=3Dbind \ -numa node,nodeid=3D0,cpus=3D0,memdev=3Dram-node0 \ -object memory-backend-file,id=3Dram-node1,prealloc=3Dyes,\ mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,size=3D1073741824,\ host-nodes=3D0-3,policy=3Dbind \ -numa node,nodeid=3D1,cpus=3D1,memdev=3Dram-node1 \ -object memory-backend-file,id=3Dram-node2,prealloc=3Dyes,\ -mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,size=3D1073741824,\ -host-nodes=3D0-3,policy=3Dbind \ +mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,discard-data=3Dyes,\ +size=3D1073741824,host-nodes=3D0-3,policy=3Dbind \ -numa node,nodeid=3D2,cpus=3D2,memdev=3Dram-node2 \ -object memory-backend-file,id=3Dram-node3,prealloc=3Dyes,\ -mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,size=3D1073741824,\ -host-nodes=3D3,policy=3Dbind \ +mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,discard-data=3Dyes,\ +size=3D1073741824,host-nodes=3D3,policy=3Dbind \ -numa node,nodeid=3D3,cpus=3D3,memdev=3Dram-node3 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -display none \ diff --git a/tests/qemuxml2argvdata/hugepages-pages3.args b/tests/qemuxml2a= rgvdata/hugepages-pages3.args index 2fc701ca22..d55265cdd8 100644 --- a/tests/qemuxml2argvdata/hugepages-pages3.args +++ b/tests/qemuxml2argvdata/hugepages-pages3.args @@ -13,7 +13,8 @@ QEMU_AUDIO_DRV=3Dnone \ -object memory-backend-ram,id=3Dram-node0,size=3D268435456 \ -numa node,nodeid=3D0,cpus=3D0,memdev=3Dram-node0 \ -object memory-backend-file,id=3Dram-node1,prealloc=3Dyes,\ -mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-SomeDummyHugepagesGu,size=3D80= 5306368 \ +mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-SomeDummyHugepagesGu,\ +discard-data=3Dyes,size=3D805306368 \ -numa node,nodeid=3D1,cpus=3D1,memdev=3Dram-node1 \ -uuid ef1bdff4-27f3-4e85-a807-5fb4d58463cc \ -display none \ diff --git a/tests/qemuxml2argvdata/hugepages-pages7.args b/tests/qemuxml2a= rgvdata/hugepages-pages7.args index 1cb598d692..02a98026eb 100644 --- a/tests/qemuxml2argvdata/hugepages-pages7.args +++ b/tests/qemuxml2argvdata/hugepages-pages7.args @@ -18,7 +18,8 @@ mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-fedora,size= =3D1073741824,\ host-nodes=3D1-3,policy=3Dbind \ -device pc-dimm,node=3D0,memdev=3Dmemdimm0,id=3Ddimm0,slot=3D0 \ -object memory-backend-file,id=3Dmemdimm1,prealloc=3Dyes,\ -mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-fedora,share=3Dno,size=3D53687= 0912 \ +mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-fedora,discard-data=3Dyes,shar= e=3Dno,\ +size=3D536870912 \ -device pc-dimm,node=3D0,memdev=3Dmemdimm1,id=3Ddimm1,slot=3D1 \ -uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ -display none \ diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 756ca7a77f..d4d64b0d21 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -919,11 +919,13 @@ mymain(void) QEMU_CAPS_OBJECT_MEMORY_FILE); DO_TEST("hugepages-pages", QEMU_CAPS_OBJECT_MEMORY_RAM, - QEMU_CAPS_OBJECT_MEMORY_FILE); + QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD); DO_TEST("hugepages-pages2", QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE); DO_TEST("hugepages-pages3", QEMU_CAPS_OBJECT_MEMORY_RAM, - QEMU_CAPS_OBJECT_MEMORY_FILE); + QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD); DO_TEST("hugepages-shared", QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE); @@ -933,7 +935,8 @@ mymain(void) DO_TEST("hugepages-pages5", NONE); DO_TEST("hugepages-pages6", NONE); DO_TEST("hugepages-pages7", - QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_OBJECT_MEMORY_FILE); + QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD); DO_TEST("hugepages-memaccess", QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_NUMA); --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list