From nobody Mon Feb 9 16:51:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1486074903456605.1468215208167; Thu, 2 Feb 2017 14:35:03 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12MVVKT024075; Thu, 2 Feb 2017 17:31:32 -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 v12MVUPm023491 for ; Thu, 2 Feb 2017 17:31:30 -0500 Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12MVTMH027255 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 2 Feb 2017 17:31:29 -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 908AD61BB5 for ; Thu, 2 Feb 2017 22:31:28 +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); Thu, 02 Feb 2017 15:31:25 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Thu, 2 Feb 2017 15:31:14 -0700 Message-Id: <20170202223114.5793-3-jfehlig@suse.com> In-Reply-To: <20170202223114.5793-1-jfehlig@suse.com> References: <20170202223114.5793-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.39]); Thu, 02 Feb 2017 22:31:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 02 Feb 2017 22:31:28 +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.39 X-loop: libvir-list@redhat.com Cc: xen-devel@lists.xen.org Subject: [libvirt] [PATCH 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 --- src/libxl/libxl_conf.c | 75 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/libxl/libxl_conf.h | 3 ++ src/libxl/libxl_driver.c | 2 +- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index b5186f2..bfe0e92 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" @@ -1530,6 +1531,80 @@ 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. + */ +unsigned long long +libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg) +{ + char **cmd_tokens =3D NULL; + char **mem_tokens =3D NULL; + size_t i; + size_t j; + unsigned long long ret; + libxl_physinfo physinfo; + + 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, &ret) < 0) + break; + if (*p) { + switch (*p) { + case 'k': + case 'K': + multiplier =3D 1024; + break; + case 'm': + case 'M': + multiplier =3D 1024 * 1024; + break; + case 'g': + case 'G': + multiplier =3D 1024 * 1024 * 1024; + break; + } + } + ret =3D (ret * multiplier) / 1024; + goto cleanup; + } + } + } + + physmem: + /* No 'max' specified in dom0_mem, so dom0 can use all physical memory= */ + libxl_physinfo_init(&physinfo); + libxl_get_physinfo(cfg->ctx, &physinfo); + ret =3D (physinfo.total_pages * cfg->verInfo->pagesize) / 1024; + libxl_physinfo_dispose(&physinfo); + + 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..c4ddbfe 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -173,6 +173,9 @@ libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver, int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, const char *filename); =20 +unsigned long long +libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg); + int libxlMakeDisk(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev); int diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 921cc93..e54b3b7 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -615,7 +615,7 @@ 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); + virDomainDefSetMemoryTotal(vm->def, libxlDriverGetDom0MaxmemConf(cfg)); =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