From patchwork Wed Aug 23 14:32:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 9917479 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 E5BF360327 for ; Wed, 23 Aug 2017 14:34:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4C7828766 for ; Wed, 23 Aug 2017 14:34:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C83EB2885E; Wed, 23 Aug 2017 14:34:44 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 89A0728766 for ; Wed, 23 Aug 2017 14:34:43 +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 1dkWhv-0001Kc-3U; Wed, 23 Aug 2017 14:32:35 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkWhs-0001K8-Sh for xen-devel@lists.xen.org; Wed, 23 Aug 2017 14:32:33 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 86/6D-18185-0029D995; Wed, 23 Aug 2017 14:32:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrAIsWRWlGSWpSXmKPExsUSuHLSXd3/E+d GGqxbIm2x5ONiFgdGj6O7fzMFMEaxZuYl5VcksGacmfWKteCHWsXmXVUNjGfluhi5OFgEFjFL vHmznr2LkYNDQiBTYtm8MAhTROLJ/zSQEiGB00wSZy4tY+pi5ASqV5X4c+g1M4jNJqAksffgc UYQW0RAUeLBy5usIDazQIHEmpXfwOLCAiESe/88YgOxeQV0JY7eesAEMfQfo8Ss7TNZIRKCEi dnPmGBaC6W2P7tHBPIEcwC0hLL/3GAhDkF9CSWnznBCBIWFZCVeP9YYgKjwCwkzbOQNM9CaIY Iq0v8mXeJGUNYW2LZwtfMELatxLp171kWMLKvYlQvTi0qSy3StdRLKspMzyjJTczM0TU0MNPL TS0uTkxPzUlMKtZLzs/dxAgMeQYg2MF4d1PAIUZJDiYlUV5NnbmRQnxJ+SmVGYnFGfFFpTmpx YcYZTg4lCR4BYAxJCRYlJqeWpGWmQOMPpi0BAePkgivJEiat7ggMbc4Mx0idYpRUUqc99YEoI QASCKjNA+uDRbxlxhlpYR5GYEOEeIpSC3KzSxBlX/FKM7BqCTM+xVkCk9mXgnc9FdAi5mAFk8 6MQdkcUkiQkqqgbH7xeZ/erL7V20/W+F+5brMEfVP6ZXmE6Jn1c/SPPrnYYpwb4Sovs+nheK9 G2bev1F0lXfS2jtsn201md7tCVWsu1E3+Yaytsb1Rtc5d2w7b21UWfBdVfvEdh6xBexrtm46a 1wZXFDFLsTHdPnz120f/fWmGOq8+m9olbW9eWv/p+B9uwOdJkcqsRRnJBpqMRcVJwIAnjbi1/ MCAAA= X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-15.tower-21.messagelabs.com!1503498751!79071678!1 X-Originating-IP: [81.169.146.221] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11449 invoked from network); 23 Aug 2017 14:32:31 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.221) by server-15.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Aug 2017 14:32:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1503498751; s=domk; d=aepfle.de; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Subject:Cc:To:From:Date; bh=gCcMB63T4POGDega/3wKaDgwgahxUANWTY74qEGnnAg=; b=EUz3do8tvdVEn1ZqGJDTXPn8rKwY7uW8aLEqxG67uDcU3I6AbebhCE+qXD2z6AV3qC 5z39GHH7QP3I8uCwqAOcwRWmGPbU9dJ2Qa9HAWUWUrYi4GcBg9wD3bTUmMraW8Y1B538 ndYUXDoce7TrhoTPbznDyc5h6Dc66rxyIa2Bk= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWi/zfN1cLnAYQz4mzReZKAqPT2tb6Nx5EL7HQvAw3tBGHnS2eB9 X-RZG-CLASS-ID: mo00 Received: from aepfle.de ([2001:a61:3430:dff:75aa:c36f:225e:fcee]) by smtp.strato.de (RZmta 41.4 AUTH) with ESMTPSA id z09640t7NEWU2ZE (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 23 Aug 2017 16:32:30 +0200 (CEST) Date: Wed, 23 Aug 2017 16:32:29 +0200 From: Olaf Hering To: Wei Liu Message-ID: <20170823143229.GE6372@aepfle.de> References: <20170817170133.30939-1-olaf@aepfle.de> <20170817170133.30939-4-olaf@aepfle.de> <20170822153116.xi6tcqumodcxmrfd@citrix.com> <20170822155325.GA6372@aepfle.de> <20170823103339.pl3fq7bh46awiuwu@citrix.com> <20170823134430.GD6372@aepfle.de> MIME-Version: 1.0 In-Reply-To: <20170823134430.GD6372@aepfle.de> User-Agent: Mutt/1.8.3 (7113) Cc: Andrew Cooper , Ian Jackson , xen-devel@lists.xen.org Subject: Re: [Xen-devel] [PATCH v2 3/3] tools/libxc: use superpages during restore of HVM guest 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, Aug 23, Olaf Hering wrote: > The value of p2m_size does not represent the actual number of pages > assigned to a domU. This info is stored in getdomaininfo.max_pages, > which is currently not used by restore. I will see if using this value > will avoid triggering the Over-allocation check. This untested change ontop of this series (done with git diff -w -b base..HEAD) does some accounting to avoid Over-allocation: Olaf diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h index 26c45fdd6d..e0321ea224 100644 --- a/tools/libxc/xc_sr_common.h +++ b/tools/libxc/xc_sr_common.h @@ -234,6 +234,8 @@ struct xc_sr_context int send_back_fd; unsigned long p2m_size; + unsigned long max_pages; + unsigned long tot_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; /* From Image Header. */ @@ -375,6 +377,7 @@ static inline bool xc_sr_bitmap_resize(struct xc_sr_bitmap *bm, unsigned long bi static inline void xc_sr_bitmap_free(struct xc_sr_bitmap *bm) { free(bm->p); + bm->p = NULL; } static inline bool xc_sr_set_bit(unsigned long bit, struct xc_sr_bitmap *bm) diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c index 1f9fe25b8f..eff24d3805 100644 --- a/tools/libxc/xc_sr_restore.c +++ b/tools/libxc/xc_sr_restore.c @@ -758,6 +758,9 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, return -1; } + /* See xc_domain_getinfo */ + ctx.restore.max_pages = ctx.dominfo.max_memkb >> (PAGE_SHIFT-10); + ctx.restore.tot_pages = ctx.dominfo.nr_pages; ctx.restore.p2m_size = nr_pfns; if ( ctx.dominfo.hvm ) diff --git a/tools/libxc/xc_sr_restore_x86_hvm.c b/tools/libxc/xc_sr_restore_x86_hvm.c index 60454148db..f2932dafb7 100644 --- a/tools/libxc/xc_sr_restore_x86_hvm.c +++ b/tools/libxc/xc_sr_restore_x86_hvm.c @@ -278,7 +278,8 @@ static int pfn_set_allocated(struct xc_sr_context *ctx, xen_pfn_t pfn) static int x86_hvm_allocate_pfn(struct xc_sr_context *ctx, xen_pfn_t pfn) { xc_interface *xch = ctx->xch; - bool success = false; + struct xc_sr_bitmap *bm; + bool success = false, do_sp; int rc = -1, done; unsigned int order; unsigned long i; @@ -303,15 +304,18 @@ static int x86_hvm_allocate_pfn(struct xc_sr_context *ctx, xen_pfn_t pfn) return -1; } DPRINTF("idx_1g %lu idx_2m %lu\n", idx_1g, idx_2m); - if (!xc_sr_test_and_set_bit(idx_1g, &ctx->x86_hvm.restore.attempted_1g)) { + + bm = &ctx->x86_hvm.restore.attempted_1g; order = SUPERPAGE_1GB_SHIFT; count = 1UL << order; + do_sp = ctx->restore.tot_pages + count <= ctx->restore.max_pages; + if ( do_sp && !xc_sr_test_and_set_bit(idx_1g, bm) ) { base_pfn = (pfn >> order) << order; extnt = base_pfn; done = xc_domain_populate_physmap(xch, ctx->domid, 1, order, 0, &extnt); DPRINTF("1G base_pfn %" PRI_xen_pfn " done %d\n", base_pfn, done); if ( done > 0 ) { - struct xc_sr_bitmap *bm = &ctx->x86_hvm.restore.attempted_2m; + bm = &ctx->x86_hvm.restore.attempted_2m; success = true; stat_1g = done; for ( i = 0; i < (count >> SUPERPAGE_2MB_SHIFT); i++ ) @@ -319,9 +323,11 @@ static int x86_hvm_allocate_pfn(struct xc_sr_context *ctx, xen_pfn_t pfn) } } - if (!xc_sr_test_and_set_bit(idx_2m, &ctx->x86_hvm.restore.attempted_2m)) { + bm = &ctx->x86_hvm.restore.attempted_2m; order = SUPERPAGE_2MB_SHIFT; count = 1UL << order; + do_sp = ctx->restore.tot_pages + count <= ctx->restore.max_pages; + if ( do_sp && !xc_sr_test_and_set_bit(idx_2m, bm) ) { base_pfn = (pfn >> order) << order; extnt = base_pfn; done = xc_domain_populate_physmap(xch, ctx->domid, 1, order, 0, &extnt); @@ -344,6 +350,7 @@ static int x86_hvm_allocate_pfn(struct xc_sr_context *ctx, xen_pfn_t pfn) if ( success == true ) { do { count--; + ctx->restore.tot_pages++; rc = pfn_set_allocated(ctx, base_pfn + count); if ( rc ) break; @@ -396,6 +403,7 @@ static int x86_hvm_populate_pfns(struct xc_sr_context *ctx, unsigned count, PERROR("Failed to release pfn %" PRI_xen_pfn, min_pfn); goto err; } + ctx->restore.tot_pages--; } min_pfn++; }