From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Hering Subject: Re: [PATCH v2 3/3] tools/libxc: use superpages during restore of HVM guest Date: Wed, 23 Aug 2017 16:32:29 +0200 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 Content-Type: multipart/mixed; boundary="===============3583881885010789300==" Return-path: In-Reply-To: <20170823134430.GD6372@aepfle.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Wei Liu Cc: Andrew Cooper , Ian Jackson , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org --===============3583881885010789300== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="z+pzSjdB7cqptWpS" Content-Disposition: inline --z+pzSjdB7cqptWpS Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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: 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 =20 int send_back_fd; unsigned long p2m_size; + unsigned long max_pages; + unsigned long tot_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; =20 /* From Image Header. */ @@ -375,6 +377,7 @@ static inline bool xc_sr_bitmap_resize(struct xc_sr_bit= map *bm, unsigned long bi static inline void xc_sr_bitmap_free(struct xc_sr_bitmap *bm) { free(bm->p); + bm->p =3D NULL; } =20 static inline bool xc_sr_set_bit(unsigned long bit, struct xc_sr_bitmap *b= m) 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, uin= t32_t dom, return -1; } =20 + /* See xc_domain_getinfo */ + ctx.restore.max_pages =3D ctx.dominfo.max_memkb >> (PAGE_SHIFT-10); + ctx.restore.tot_pages =3D ctx.dominfo.nr_pages; ctx.restore.p2m_size =3D nr_pfns; =20 if ( ctx.dominfo.hvm ) diff --git a/tools/libxc/xc_sr_restore_x86_hvm.c b/tools/libxc/xc_sr_restor= e_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 =3D ctx->xch; - bool success =3D false; + struct xc_sr_bitmap *bm; + bool success =3D false, do_sp; int rc =3D -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 =3D &ctx->x86_hvm.restore.attempted_1g; order =3D SUPERPAGE_1GB_SHIFT; count =3D 1UL << order; + do_sp =3D ctx->restore.tot_pages + count <=3D ctx->restore.max_pages; + if ( do_sp && !xc_sr_test_and_set_bit(idx_1g, bm) ) { base_pfn =3D (pfn >> order) << order; extnt =3D base_pfn; done =3D 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 =3D &ctx->x86_hvm.restore.attempted_2m; + bm =3D &ctx->x86_hvm.restore.attempted_2m; success =3D true; stat_1g =3D done; for ( i =3D 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) } } =20 - if (!xc_sr_test_and_set_bit(idx_2m, &ctx->x86_hvm.restore.attempted_2m= )) { + bm =3D &ctx->x86_hvm.restore.attempted_2m; order =3D SUPERPAGE_2MB_SHIFT; count =3D 1UL << order; + do_sp =3D ctx->restore.tot_pages + count <=3D ctx->restore.max_pages; + if ( do_sp && !xc_sr_test_and_set_bit(idx_2m, bm) ) { base_pfn =3D (pfn >> order) << order; extnt =3D base_pfn; done =3D 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 *c= tx, xen_pfn_t pfn) if ( success =3D=3D true ) { do { count--; + ctx->restore.tot_pages++; rc =3D 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++; } Olaf --z+pzSjdB7cqptWpS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSkRyP6Rn//f03pRUBdQqD6ppg2fgUCWZ2R+gAKCRBdQqD6ppg2 fu0LAKDlqheVJKnTgQyid8Bp0NELTh62pQCgk5xcDCHvnvfiFAXVO67l4bOMmSE= =qM7b -----END PGP SIGNATURE----- --z+pzSjdB7cqptWpS-- --===============3583881885010789300== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --===============3583881885010789300==--