From patchwork Wed Jun 1 15:56:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9147739 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 ED31060751 for ; Wed, 1 Jun 2016 15:59:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D325024B5B for ; Wed, 1 Jun 2016 15:59:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3E0726992; Wed, 1 Jun 2016 15:59:13 +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 1FDE324B5B for ; Wed, 1 Jun 2016 15:59:13 +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 1b88VY-00042O-I3; Wed, 01 Jun 2016 15:56:36 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b88VX-00041Z-Az for xen-devel@lists.xenproject.org; Wed, 01 Jun 2016 15:56:35 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 7F/B3-25578-2B50F475; Wed, 01 Jun 2016 15:56:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRWlGSWpSXmKPExsXitHSDve4mVv9 wgzfNrBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bJHbtZC9oMKnYvaWVtYPyk2sXIySEh4C/x e9sxNhCbRUBF4svu1+wgNpuAssTPzl6wuIiAtsT+d6+BbC4OZoEljBIL1iwCcjg4hAUqJN7ON wWp4RXQk9jcPpUFxBYSKJfonL6dHSIuKHFy5hOwOLOAjsSC3Z/AWpkFpCWW/+MACXMK2Es8fX eUCcQWBTrhyoS37BBjFCQ6ph9jAimXEOCW+NttP4GRfxaSobOQDJ2FMHQBI/MqRo3i1KKy1CJ dQxO9pKLM9IyS3MTMHF1DA2O93NTi4sT01JzEpGK95PzcTYzA8GMAgh2MK7Z7HmKU5GBSEuXN YfEPF+JLyk+pzEgszogvKs1JLT7EKMPBoSTBOwEkJ1iUmp5akZaZA4wEmLQEB4+SCO9EZqA0b 3FBYm5xZjpE6hSjopQ4rytInwBIIqM0D64NFn2XGGWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJM zbATKFJzOvBG76K6DFTECL4zN8QBaXJCKkpBoY6zyb13GXGKUKsHnbXL9z0WNOYK0MtzjLRIt ZTm0CzFEuETazX/eLRj3e39IkdPxB7sJjs35/cQ9l/my79/MZLcZw3nMLWXta+za7vHsabiH2 g+Frq1b2rMa6iofv+Y5c5hGrNudpWpOz76m5/ZxXy6NfPDsw4TWXh/GKOXLXj8ppzO1xObNRi aU4I9FQi7moOBEAhHSQ/7kCAAA= X-Env-Sender: prvs=953b1074e=wei.liu2@citrix.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1464796592!42648842!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46801 invoked from network); 1 Jun 2016 15:56:33 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 1 Jun 2016 15:56:33 -0000 X-IronPort-AV: E=Sophos;i="5.26,401,1459814400"; d="scan'208";a="364635385" Date: Wed, 1 Jun 2016 16:56:30 +0100 From: Wei Liu To: Ian Jackson Message-ID: <20160601155630.GN5160@citrix.com> References: <1464716523-29663-1-git-send-email-wei.liu2@citrix.com> <22351.991.967255.512153@mariner.uk.xensource.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <22351.991.967255.512153@mariner.uk.xensource.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-DLP: MIA1 Cc: George Dunlap , Xen-devel , Vitaly Kuznetsov , Wei Liu Subject: Re: [Xen-devel] [PATCH for-4.7] libxl: keep PoD target adjustment by memory fudge after reload_domain_config() 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Jun 01, 2016 at 04:48:47PM +0100, Ian Jackson wrote: > Wei Liu writes ("[Xen-devel] [PATCH for-4.7] libxl: keep PoD target adjustment by memory fudge after reload_domain_config()"): > > From: Vitaly Kuznetsov > > > > Commit 56fb5fd623 ("libxl: adjust PoD target by memory fudge, too") > > introduced target_memkb adjustment for HVM PoD domains on create. The > > adjustment is however being reset on reload_domain_config() (e.g. when > > we reboot the guest). For example: > > With George's revised commit message this patch makes sense for 4.7. > > I would like to see this function retain the name "fudge" though: > > > - ents[3] = GCSPRINTF("%"PRId64, info->target_memkb - info->video_memkb > > - - mem_target_fudge); > > + ents[3] = GCSPRINTF("%"PRId64, info->target_memkb - > > + libxl__get_targetmem_difference(gc, info)); > > ie: > > + ents[3] = GCSPRINTF("%"PRId64, info->target_memkb - > + libxl__get_targetmem_fudge(gc, info)); > > This makes it clear that there is still a problem here (and it will > help things like "git grep -G"). > > With that name changed, and George's commit message, you may put my > ack on this. > > Thanks everyone. Updated patch here and I will push it shortly. ---8<--- From b9d63c2da58471a767852ab68111d245ee8d195f Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Wed, 3 Feb 2016 16:53:03 +0100 Subject: [PATCH] libxl: keep PoD target adjustment by memory fudge after reload_domain_config() Commit 56fb5fd623 ("libxl: adjust PoD target by memory fudge, too") introduced target_memkb adjustment for HVM PoD domains on create, wherein the value it wrote to target is always 1MiB lower than the actual target_memkb. Unfortunately, on reboot, it is this value which is read *unmodified* to feed into the next domain creation; from which 1MiB is subtracted *again*. This means that any guest which reboots with memory < maxmem will have its memory target decreased by 1MiB on every boot. This patch makes it so that when reading target on reboot, we adjust the value we read *up* by 1MiB, so that the domain will be build with the appropriate amount of memory and the target will remain the same after reboot. This is still not quite a complete fix, as the 1MiB offset is only subtracted when creating or rebooting; it is not subtracted when 'xl set-memory' is called. But it will prevent any situations where memory is continually increased or decreased. A better fix will have to wait until after the release. Signed-off-by: Vitaly Kuznetsov Signed-off-by: Wei Liu Acked-by: Ian Jackson --- tools/libxl/libxl.c | 8 ++++---- tools/libxl/libxl_dom.c | 10 ++-------- tools/libxl/libxl_internal.h | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index b9d855b..306984b 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -7229,12 +7229,12 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, LOG(ERROR, "fail to get memory target for domain %d", domid); goto out; } - /* Target memory in xenstore is different from what user has - * asked for. The difference is video_memkb. See - * libxl_set_memory_target. + + /* libxl__get_targetmem_fudge() calculates the difference from + * what is in xenstore to what we have in the domain build info. */ d_config->b_info.target_memkb = target_memkb + - d_config->b_info.video_memkb; + libxl__get_targetmem_fudge(gc, &d_config->b_info); d_config->b_info.max_memkb = max_memkb; } diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 9b20cf5..805774f 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -490,7 +490,6 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid, xs_transaction_t t; char **ents; int i, rc; - int64_t mem_target_fudge; if (info->num_vnuma_nodes && !info->num_vcpu_soft_affinity) { rc = set_vnuma_affinity(gc, domid, info); @@ -523,17 +522,12 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid, } } - mem_target_fudge = - (info->type == LIBXL_DOMAIN_TYPE_HVM && - info->max_memkb > info->target_memkb) - ? LIBXL_MAXMEM_CONSTANT : 0; - ents = libxl__calloc(gc, 12 + (info->max_vcpus * 2) + 2, sizeof(char *)); ents[0] = "memory/static-max"; ents[1] = GCSPRINTF("%"PRId64, info->max_memkb); ents[2] = "memory/target"; - ents[3] = GCSPRINTF("%"PRId64, info->target_memkb - info->video_memkb - - mem_target_fudge); + ents[3] = GCSPRINTF("%"PRId64, info->target_memkb - + libxl__get_targetmem_fudge(gc, info)); ents[4] = "memory/videoram"; ents[5] = GCSPRINTF("%"PRId64, info->video_memkb); ents[6] = "domid"; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index fac5751..3bdeb3c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4107,6 +4107,21 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc, libxl_uuid_copy(CTX, &dst->uuid, &src->uuid); } +/* Target memory in xenstore is different from what user has + * asked for. The difference is video_memkb + (possible) fudge. + * See libxl_set_memory_target. + */ +static inline +uint64_t libxl__get_targetmem_fudge(libxl__gc *gc, + const libxl_domain_build_info *info) +{ + int64_t mem_target_fudge = (info->type == LIBXL_DOMAIN_TYPE_HVM && + info->max_memkb > info->target_memkb) + ? LIBXL_MAXMEM_CONSTANT : 0; + + return info->video_memkb + mem_target_fudge; +} + /* Macros used to compare device identifier. Returns true if the two * devices have same identifier. */ #define COMPARE_DEVID(a, b) ((a)->devid == (b)->devid)