From nobody Fri May 3 13:35:33 2024 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 1544619495273810.5940552444463; Wed, 12 Dec 2018 04:58:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE3453097025; Wed, 12 Dec 2018 12:58:13 +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 37433608C5; Wed, 12 Dec 2018 12:58:13 +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 A28C03D39D; Wed, 12 Dec 2018 12:58:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wBCCwBYi020493 for ; Wed, 12 Dec 2018 07:58:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id D9E1B5D738; Wed, 12 Dec 2018 12:58:11 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DC375D70A for ; Wed, 12 Dec 2018 12:58:11 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 12 Dec 2018 13:58:03 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/2] qemuBuildMemoryBackendProps: Pass @priv instead of its individual members 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Dec 2018 12:58:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So far we have two arguments that we are passing to qemuBuildMemoryBackendProps() and that are taken from domain private data: @qemuCaps and @autoNodeset. In the next commit I will use one more item from there. Therefore, instead of having it as yet another argument to the function, pass pointer to the private data object. There is one change in qemuDomainAttachMemory() where previously @autoNodeset was NULL but now is priv->autoNodeset (which may be set). This is safe to do as @autoNodeset is advisory only. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_command.c | 30 ++++++++++++++---------------- src/qemu/qemu_command.h | 3 +-- src/qemu/qemu_hotplug.c | 2 +- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 32ed83f277..01a3141134 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3201,22 +3201,21 @@ qemuBuildMemoryBackendPropsShare(virJSONValuePtr pr= ops, * @backendProps: [out] constructed object * @alias: alias of the device * @cfg: qemu driver config object - * @qemuCaps: qemu capabilities object + * @priv: pointer to domain private object * @def: domain definition object * @mem: memory definition object - * @autoNodeset: fallback nodeset in case of automatic NUMA placement * @force: forcibly use one of the backends * * Creates a configuration object that represents memory backend of given = guest - * NUMA node (domain @def and @mem). Use @autoNodeset to fine tune the + * NUMA node (domain @def and @mem). Use @priv->autoNodeset to fine tune t= he * placement of the memory on the host NUMA nodes. * * By default, if no memory-backend-* object is necessary to fulfil the gu= est * configuration value of 1 is returned. This behaviour can be suppressed = by * setting @force to true in which case 0 would be returned. * - * Then, if one of the three memory-backend-* should be used, the @qemuCap= s is - * consulted to check if qemu does support it. + * Then, if one of the three memory-backend-* should be used, the @priv->q= emuCaps + * is consulted to check if qemu does support it. * * Returns: 0 on success, * 1 on success and if there's no need to use memory-backend-* @@ -3226,10 +3225,9 @@ int qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, const char *alias, virQEMUDriverConfigPtr cfg, - virQEMUCapsPtr qemuCaps, + qemuDomainObjPrivatePtr priv, virDomainDefPtr def, virDomainMemoryDefPtr mem, - virBitmapPtr autoNodeset, bool force) { const char *backendType =3D "memory-backend-file"; @@ -3379,7 +3377,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, =20 if (!mem->nvdimmPath && discard =3D=3D VIR_TRISTATE_BOOL_YES) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE_DIS= CARD)) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FI= LE_DISCARD)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this QEMU doesn't support memory discard= ")); goto cleanup; @@ -3403,7 +3401,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, if (mem->sourceNodes) { nodemask =3D mem->sourceNodes; } else { - if (virDomainNumatuneMaybeGetNodeset(def->numa, autoNodeset, + if (virDomainNumatuneMaybeGetNodeset(def->numa, priv->autoNodeset, &nodemask, mem->targetNode) <= 0) goto cleanup; } @@ -3431,19 +3429,19 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, } else { /* otherwise check the required capability */ if (STREQ(backendType, "memory-backend-file") && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) { + !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE))= { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this qemu doesn't support the " "memory-backend-file object")); goto cleanup; } else if (STREQ(backendType, "memory-backend-ram") && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM))= { + !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY= _RAM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this qemu doesn't support the " "memory-backend-ram object")); goto cleanup; } else if (STREQ(backendType, "memory-backend-memory") && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_MEMFD= )) { + !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY= _MEMFD)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this qemu doesn't support the " "memory-backend-memfd object")); @@ -3486,8 +3484,8 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, mem.targetNode =3D cell; mem.info.alias =3D alias; =20 - if ((rc =3D qemuBuildMemoryBackendProps(&props, alias, cfg, priv->qemu= Caps, - def, &mem, priv->autoNodeset, fa= lse)) < 0) + if ((rc =3D qemuBuildMemoryBackendProps(&props, alias, cfg, + priv, def, &mem, false)) < 0) goto cleanup; =20 if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0) @@ -3523,8 +3521,8 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf, if (virAsprintf(&alias, "mem%s", mem->info.alias) < 0) goto cleanup; =20 - if (qemuBuildMemoryBackendProps(&props, alias, cfg, priv->qemuCaps, - def, mem, priv->autoNodeset, true) < 0) + if (qemuBuildMemoryBackendProps(&props, alias, cfg, + priv, def, mem, true) < 0) goto cleanup; =20 if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index d382cd592a..5cd744b8bf 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -125,10 +125,9 @@ int qemuBuildControllerDevStr(const virDomainDef *doma= inDef, int qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, const char *alias, virQEMUDriverConfigPtr cfg, - virQEMUCapsPtr qemuCaps, + qemuDomainObjPrivatePtr priv, virDomainDefPtr def, virDomainMemoryDefPtr mem, - virBitmapPtr autoNodeset, bool force); =20 char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c455baeab6..4e795c7859 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2568,7 +2568,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, goto cleanup; =20 if (qemuBuildMemoryBackendProps(&props, objalias, cfg, - priv->qemuCaps, vm->def, mem, NULL, tr= ue) < 0) + priv, vm->def, mem, true) < 0) goto cleanup; =20 if (qemuProcessBuildDestroyMemoryPaths(driver, vm, mem, true) < 0) --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 13:35:33 2024 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 1544619497584830.0113939770343; Wed, 12 Dec 2018 04:58:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39A5881DEC; Wed, 12 Dec 2018 12:58:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06D0C1A7CF; Wed, 12 Dec 2018 12:58:16 +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 B10AA181B9E9; Wed, 12 Dec 2018 12:58:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wBCCwCQE020503 for ; Wed, 12 Dec 2018 07:58:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id ACFD85D738; Wed, 12 Dec 2018 12:58:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3335F5D70A for ; Wed, 12 Dec 2018 12:58:12 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 12 Dec 2018 13:58:04 +0100 Message-Id: <7eb262b6c6fdfc1bedfadc9199f0f4f519045985.1544619423.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/2] qemu: Don't use -mem-prealloc among with .prealloc=yes 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: , 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 12 Dec 2018 12:58:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1624223 There are two ways to request memory preallocation on cmd line: -mem-prealloc and .prealloc attribute for a memory-backend-file. However, as it turns out it's not safe to use both at the same time. If -mem-prealloc is used then qemu will fullly allocate the memory (this is done by actually touching every page that has been allocated). Then, if .prealloc=3Dyes is specified, mbind(flags =3D MPOL_MF_STRICT | MPOL_MF_MOVE) is called which: a) has to (possibly) move the memory to a different NUMA node, b) can have no effect when hugepages are in play (thus ignoring user request to place memory on desired NUMA nodes). Prefer -mem-prealloc as it is more backward compatible compared to switching to "-numa node,memdev=3D + -object memory-backend-file". Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_command.c | 26 ++++++++++++------- src/qemu/qemu_domain.c | 7 +++++ src/qemu/qemu_domain.h | 3 +++ .../hugepages-numa-default-dimm.args | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 01a3141134..1a1cb9cbbd 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3357,11 +3357,13 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, if (mem->nvdimmPath) { if (VIR_STRDUP(memPath, mem->nvdimmPath) < 0) goto cleanup; - prealloc =3D true; + if (!priv->memPrealloc) + prealloc =3D true; } else if (useHugepage) { if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) <= 0) goto cleanup; - prealloc =3D true; + if (!priv->memPrealloc) + prealloc =3D true; } else { /* We can have both pagesize and mem source. If that's the cas= e, * prefer hugepages as those are more specific. */ @@ -7576,7 +7578,8 @@ qemuBuildSmpCommandLine(virCommandPtr cmd, static int qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, const virDomainDef *def, - virCommandPtr cmd) + virCommandPtr cmd, + qemuDomainObjPrivatePtr priv) { const long system_page_size =3D virGetSystemPageSizeKB(); char *mem_path =3D NULL; @@ -7598,8 +7601,10 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, return 0; } =20 - if (def->mem.allocation !=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) + if (def->mem.allocation !=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) { virCommandAddArgList(cmd, "-mem-prealloc", NULL); + priv->memPrealloc =3D true; + } =20 virCommandAddArgList(cmd, "-mem-path", mem_path, NULL); VIR_FREE(mem_path); @@ -7612,7 +7617,8 @@ static int qemuBuildMemCommandLine(virCommandPtr cmd, virQEMUDriverConfigPtr cfg, const virDomainDef *def, - virQEMUCapsPtr qemuCaps) + virQEMUCapsPtr qemuCaps, + qemuDomainObjPrivatePtr priv) { if (qemuDomainDefValidateMemoryHotplug(def, qemuCaps, NULL) < 0) return -1; @@ -7631,15 +7637,17 @@ qemuBuildMemCommandLine(virCommandPtr cmd, virDomainDefGetMemoryInitial(def) / 1024); } =20 - if (def->mem.allocation =3D=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) + if (def->mem.allocation =3D=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE)= { virCommandAddArgList(cmd, "-mem-prealloc", NULL); + priv->memPrealloc =3D true; + } =20 /* * Add '-mem-path' (and '-mem-prealloc') parameter here if * the hugepages and no numa node is specified. */ if (!virDomainNumaGetNodeCount(def->numa) && - qemuBuildMemPathStr(cfg, def, cmd) < 0) + qemuBuildMemPathStr(cfg, def, cmd, priv) < 0) return -1; =20 if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_REALTIME_ML= OCK)) { @@ -7748,7 +7756,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, } =20 if (!needBackend && - qemuBuildMemPathStr(cfg, def, cmd) < 0) + qemuBuildMemPathStr(cfg, def, cmd, priv) < 0) goto cleanup; =20 for (i =3D 0; i < ncells; i++) { @@ -10441,7 +10449,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0) goto error; =20 - if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps) < 0) + if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps, priv) < 0) goto error; =20 if (qemuBuildSmpCommandLine(cmd, def) < 0) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 509da6bfea..039b887d8e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1944,6 +1944,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) VIR_FREE(priv->libDir); VIR_FREE(priv->channelTargetDir); =20 + priv->memPrealloc =3D false; + /* remove automatic pinning data */ virBitmapFree(priv->autoNodeset); priv->autoNodeset =3D NULL; @@ -2489,6 +2491,9 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) virBufferAsprintf(buf, "\n", priv->noden= ameindex); =20 + if (priv->memPrealloc) + virBufferAddLit(buf, "\n"); + if (qemuDomainObjPrivateXMLFormatBlockjobs(buf, vm) < 0) return -1; =20 @@ -2993,6 +2998,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, goto error; } =20 + priv->memPrealloc =3D virXPathBoolean("boolean(./memPrealloc)", ctxt) = =3D=3D 1; + return 0; =20 error: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 53b5ea1678..b7347c72ce 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -372,6 +372,9 @@ struct _qemuDomainObjPrivate { =20 /* true if libvirt remembers the original owner for files */ bool rememberOwner; + + /* true if global -mem-prealloc appears on cmd line */ + bool memPrealloc; }; =20 # define QEMU_DOMAIN_PRIVATE(vm) \ diff --git a/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args b/test= s/qemuxml2argvdata/hugepages-numa-default-dimm.args index 143d8b041f..df90f7aad9 100644 --- a/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args +++ b/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args @@ -13,7 +13,7 @@ QEMU_AUDIO_DRV=3Dnone \ -mem-prealloc \ -mem-path /dev/hugepages2M/libvirt/qemu/-1-fedora \ -numa node,nodeid=3D0,cpus=3D0-1,mem=3D1024 \ --object memory-backend-file,id=3Dmemdimm0,prealloc=3Dyes,\ +-object memory-backend-file,id=3Dmemdimm0,\ 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 \ --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list