From nobody Tue Apr 23 08:34:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1486592885354930.4113426527027; Wed, 8 Feb 2017 14:28:05 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v18MOd2i015106; Wed, 8 Feb 2017 17:24:39 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v18MOb4t000565 for ; Wed, 8 Feb 2017 17:24:37 -0500 Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v18MObGd031812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Feb 2017 17:24:37 -0500 Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 219114E4C4 for ; Wed, 8 Feb 2017 22:24:36 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Wed, 08 Feb 2017 15:24:32 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Wed, 8 Feb 2017 15:24:22 -0700 Message-Id: <20170208222423.28419-2-jfehlig@suse.com> In-Reply-To: <20170208222423.28419-1-jfehlig@suse.com> References: <20170208222423.28419-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 200 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Feb 2017 22:24:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Feb 2017 22:24:36 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.501 (BAYES_50, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH V2 1/2] libxl: fix reporting of maximum memory 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The libxl driver reports different values of maximum memory depending on state of a domain. If inactive, maximum memory value is reported correctly. When active, maximum memory is derived from max_pages value returned by the XEN_SYSCTL_getdomaininfolist sysctl operation. But max_pages can be changed by toolstacks and does not necessarily represent the maximum memory a domain can use during its active lifetime. A better location for determining a domain's maximum memory is the /local/domain//memory/static-max node in xenstore. This value is set from the libxl_domain_build_info.max_memkb field when creating the domain. Currently it cannot be changed nor can its value be exceeded by a balloon operation. From libvirt's perspective, always reporting maximum memory with virDomainDefGetMemoryTotal() will produce the same results as reading the static-max node in xenstore. Signed-off-by: Jim Fehlig Acked-by: Joao Martins --- src/libxl/libxl_driver.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 38ad91e..040b986 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1640,10 +1640,10 @@ libxlDomainGetInfo(virDomainPtr dom, virDomainInfoP= tr info) if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 + info->maxMem =3D virDomainDefGetMemoryTotal(vm->def); if (!virDomainObjIsActive(vm)) { info->cpuTime =3D 0; info->memory =3D vm->def->mem.cur_balloon; - info->maxMem =3D virDomainDefGetMemoryTotal(vm->def); } else { libxl_dominfo_init(&d_info); =20 @@ -1655,7 +1655,6 @@ libxlDomainGetInfo(virDomainPtr dom, virDomainInfoPtr= info) } info->cpuTime =3D d_info.cpu_time; info->memory =3D d_info.current_memkb; - info->maxMem =3D d_info.max_memkb; =20 libxl_dominfo_dispose(&d_info); } @@ -5174,7 +5173,7 @@ libxlDomainMemoryStats(virDomainPtr dom, goto endjob; } mem =3D d_info.current_memkb; - maxmem =3D d_info.max_memkb; + maxmem =3D virDomainDefGetMemoryTotal(vm->def); =20 LIBXL_SET_MEMSTAT(VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON, mem); LIBXL_SET_MEMSTAT(VIR_DOMAIN_MEMORY_STAT_AVAILABLE, maxmem); --=20 2.9.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 23 08:34:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1486592885416906.0831692201108; Wed, 8 Feb 2017 14:28:05 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v18MOrWB028898; Wed, 8 Feb 2017 17:24:53 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v18MObev000573 for ; Wed, 8 Feb 2017 17:24:37 -0500 Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v18MObF6004390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Feb 2017 17:24:37 -0500 Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2510FC05AA59 for ; Wed, 8 Feb 2017 22:24:36 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Wed, 08 Feb 2017 15:24:32 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Wed, 8 Feb 2017 15:24:23 -0700 Message-Id: <20170208222423.28419-3-jfehlig@suse.com> In-Reply-To: <20170208222423.28419-1-jfehlig@suse.com> References: <20170208222423.28419-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 200 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 08 Feb 2017 22:24:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 08 Feb 2017 22:24:36 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.501 (BAYES_50, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH V2 2/2] libxl: fix dom0 maximum memory setting 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When the libxl driver is initialized, it creates a virDomainDef object for dom0 and adds it to the list of domains. Total memory for dom0 was being set from the max_memkb field of libxl_dominfo struct retrieved from libxl, but this field can be set to LIBXL_MEMKB_DEFAULT (~0ULL) if dom0 maximum memory has not been explicitly set by the user. This patch adds some simple parsing of the Xen commandline, looking for a dom0_mem parameter that also specifies a 'max' value. If not specified, dom0 maximum memory is effectively all physical host memory. Signed-off-by: Jim Fehlig Acked-by: Joao Martins --- V2: Check return value of libxl_get_physinfo and libxlDriverGetDom0MaxmemConf. src/libxl/libxl_conf.c | 77 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/libxl/libxl_conf.h | 4 +++ src/libxl/libxl_driver.c | 5 +++- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 28b05e1..7e30c7d 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -34,6 +34,7 @@ #include "internal.h" #include "virlog.h" #include "virerror.h" +#include "c-ctype.h" #include "datatypes.h" #include "virconf.h" #include "virfile.h" @@ -1533,6 +1534,82 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr c= fg, =20 } =20 +/* + * dom0's maximum memory can be controled by the user with the 'dom0_mem' = Xen + * command line parameter. E.g. to set dom0's initial memory to 4G and max + * memory to 8G: dom0_mem=3D4G,max:8G + * + * If not constrained by the user, dom0 can effectively use all host memor= y. + * This function returns the configured maximum memory for dom0 in kilobyt= es, + * either the user-specified value or total physical memory as a default. + */ +int +libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg, + unsigned long long *maxmem) +{ + char **cmd_tokens =3D NULL; + char **mem_tokens =3D NULL; + size_t i; + size_t j; + libxl_physinfo physinfo; + int ret =3D -1; + + if (cfg->verInfo->commandline =3D=3D NULL || + !(cmd_tokens =3D virStringSplit(cfg->verInfo->commandline, " ", 0)= )) + goto physmem; + + for (i =3D 0; cmd_tokens[i] !=3D NULL; i++) { + if (!STRPREFIX(cmd_tokens[i], "dom0_mem=3D")) + continue; + + if (!(mem_tokens =3D virStringSplit(cmd_tokens[i], ",", 0))) + break; + for (j =3D 0; mem_tokens[j] !=3D NULL; j++) { + if (STRPREFIX(mem_tokens[j], "max:")) { + char *p =3D mem_tokens[j] + 4; + unsigned long long multiplier =3D 1; + + while (c_isdigit(*p)) + p++; + if (virStrToLong_ull(mem_tokens[j] + 4, &p, 10, maxmem) < = 0) + break; + if (*p) { + switch (*p) { + case 'm': + case 'M': + multiplier =3D 1024; + break; + case 'g': + case 'G': + multiplier =3D 1024 * 1024; + break; + } + } + *maxmem =3D *maxmem * multiplier; + ret =3D 0; + goto cleanup; + } + } + } + + physmem: + /* No 'max' specified in dom0_mem, so dom0 can use all physical memory= */ + libxl_physinfo_init(&physinfo); + if (libxl_get_physinfo(cfg->ctx, &physinfo)) { + VIR_WARN("libxl_get_physinfo failed"); + goto cleanup; + } + *maxmem =3D (physinfo.total_pages * cfg->verInfo->pagesize) / 1024; + libxl_physinfo_dispose(&physinfo); + ret =3D 0; + + cleanup: + virStringListFree(cmd_tokens); + virStringListFree(mem_tokens); + return ret; +} + + #ifdef LIBXL_HAVE_DEVICE_CHANNEL static int libxlPrepareChannel(virDomainChrDefPtr channel, diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 69d7885..4942171 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -174,6 +174,10 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, const char *filename); =20 int +libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg, + unsigned long long *maxmem); + +int libxlMakeDisk(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev); int libxlMakeNic(virDomainDefPtr def, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 040b986..1558d5b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -576,6 +576,7 @@ libxlAddDom0(libxlDriverPrivatePtr driver) virDomainObjPtr vm =3D NULL; virDomainDefPtr oldDef =3D NULL; libxl_dominfo d_info; + unsigned long long maxmem; int ret =3D -1; =20 libxl_dominfo_init(&d_info); @@ -615,7 +616,9 @@ libxlAddDom0(libxlDriverPrivatePtr driver) if (virDomainDefSetVcpus(vm->def, d_info.vcpu_online) < 0) goto cleanup; vm->def->mem.cur_balloon =3D d_info.current_memkb; - virDomainDefSetMemoryTotal(vm->def, d_info.max_memkb); + if (libxlDriverGetDom0MaxmemConf(cfg, &maxmem) < 0) + maxmem =3D d_info.current_memkb; + virDomainDefSetMemoryTotal(vm->def, maxmem); =20 ret =3D 0; =20 --=20 2.9.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list