From patchwork Thu Feb 2 22:31:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Fehlig X-Patchwork-Id: 9553303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0B39660424 for ; Thu, 2 Feb 2017 22:33:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 049C328480 for ; Thu, 2 Feb 2017 22:33:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDB8B28497; Thu, 2 Feb 2017 22:33:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 872A3284CE for ; Thu, 2 Feb 2017 22:33:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZPud-0007Pu-Q1; Thu, 02 Feb 2017 22:31:31 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZPuc-0007Pc-JJ for xen-devel@lists.xen.org; Thu, 02 Feb 2017 22:31:30 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id 0A/0A-22326-243B3985; Thu, 02 Feb 2017 22:31:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsXS6fgrUNdx8+Q IgwevxC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozVfY/YC5aoVjRu+MjYwHheuouRi0NIYDuj xP6d+5i6GDk52ASUJV523mIFsUUEpCQW3VvADGIzC1hLfGtdCRYXBrJbPvWwgdgsAqoSHTuXs YDYvAImEkc3PmQEsSUE5CRevv4J1sspYCrx8NVpMFsIqObRhS9sExi5FjAyrGLUKE4tKkst0j W01EsqykzPKMlNzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECPQjAxDsYPyxLOAQoyQHk5Io78+ FkyOE+JLyUyozEosz4otKc1KLDzFqcHAIbF67+gKjFEtefl6qkgRvyCagOsGi1PTUirTMHGCg wZRKcPAoifDOBknzFhck5hZnpkOkTjHqcnzZeeYlkxDYDClxXj6QIgGQoozSPLgRsKC/xCgrJ czLCHSgEE9BalFuZgmq/CtGcQ5GJWHeeSBTeDLzSuA2vQI6ggnoiJ+PJ4EcUZKIkJJqYDR8Eu XW0aH5cF7SdrPGzskx+tse+Kql/vrzpCpsw93iORO/hMjcOFwm8vfSB728Mr8fqjNfhvf+bOE XWCPGlx6hoG95ue34xdWvGxemeM5zP5l+yXPODcOkJgvuzAVT962dlCEiUvziQfVBLZNwjzVX TNfKH10dPLXuXrzEKnaeIjUTgXe1m5RYijMSDbWYi4oTAfMrm9V1AgAA X-Env-Sender: jfehlig@suse.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1486074687!84838379!1 X-Originating-IP: [137.65.250.81] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21697 invoked from network); 2 Feb 2017 22:31:29 -0000 Received: from smtp2.provo.novell.com (HELO smtp2.provo.novell.com) (137.65.250.81) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Feb 2017 22:31:29 -0000 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> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20170202223114.5793-1-jfehlig@suse.com> References: <20170202223114.5793-1-jfehlig@suse.com> Cc: Jim Fehlig , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH 2/2] libxl: fix dom0 maximum memory setting X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 cfg, } +/* + * 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=4G,max:8G + * + * If not constrained by the user, dom0 can effectively use all host memory. + * This function returns the configured maximum memory for dom0 in kilobytes, + * either the user-specified value or total physical memory as a default. + */ +unsigned long long +libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg) +{ + char **cmd_tokens = NULL; + char **mem_tokens = NULL; + size_t i; + size_t j; + unsigned long long ret; + libxl_physinfo physinfo; + + if (cfg->verInfo->commandline == NULL || + !(cmd_tokens = virStringSplit(cfg->verInfo->commandline, " ", 0))) + goto physmem; + + for (i = 0; cmd_tokens[i] != NULL; i++) { + if (!STRPREFIX(cmd_tokens[i], "dom0_mem=")) + continue; + + if (!(mem_tokens = virStringSplit(cmd_tokens[i], ",", 0))) + break; + for (j = 0; mem_tokens[j] != NULL; j++) { + if (STRPREFIX(mem_tokens[j], "max:")) { + char *p = mem_tokens[j] + 4; + unsigned long long multiplier = 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 = 1024; + break; + case 'm': + case 'M': + multiplier = 1024 * 1024; + break; + case 'g': + case 'G': + multiplier = 1024 * 1024 * 1024; + break; + } + } + ret = (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 = (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); +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 = d_info.current_memkb; - virDomainDefSetMemoryTotal(vm->def, d_info.max_memkb); + virDomainDefSetMemoryTotal(vm->def, libxlDriverGetDom0MaxmemConf(cfg)); ret = 0;