tools/libxc: use superpages
v9 cover tools/libxc: use superpages
Using superpages on the receiving dom0 will avoid performance regressions.
Olaf
v9:
update hole checking in x86_hvm_populate_pfns
add out of bounds check to xc_sr_test_and_set/clear_bit
v8:
remove double check of 1G/2M idx in x86_hvm_populate_pfns
v7:
cover holes that span multiple superpages
v6:
handle freeing of partly populated superpages correctly more DPRINTFs
v5:
send correct version, rebase was not fully finished
v4:
restore trailing "_bit" in bitmap function names keep track of gaps between previous and current batch split alloc functionality in x86_hvm_allocate_pfn
v3:
clear pointer in xc_sr_bitmap_free
some coding style changes
use getdomaininfo.max_pages to avoid Over-allocation check trim bitmap function names, drop trailing "_bit" add some comments
v2:
split into individual commits
based on staging c39cf093fc ("x86/asm: add .file directives")
Olaf Hering (3):
tools/libxc: move SUPERPAGE macros to common header tools/libxc: add API for bitmap access for restore tools/libxc: use superpages during restore of HVM guest
tools/libxc/xc_dom_x86.c | 5 - tools/libxc/xc_private.h | 5 + tools/libxc/xc_sr_common.c | 41 +++++ tools/libxc/xc_sr_common.h | 98 +++++++++-- tools/libxc/xc_sr_restore.c | 141 +-------------- tools/libxc/xc_sr_restore_x86_hvm.c | 341 ++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_restore_x86_pv.c | 72 +++++++- 7 files changed, 555 insertions(+), 148 deletions(-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 1/3 tools/libxc: move SUPERPAGE macros to common header
The macros SUPERPAGE_2MB_SHIFT and SUPERPAGE_1GB_SHIFT will be used by other code in libxc. Move the macros to a header file.
--- tools/libxc/xc_dom_x86.c | 5 ----- tools/libxc/xc_private.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-)
tools/libxc/xc_dom_x86.c +0 -5
@@ -43,11 +43,6 @@#define SUPERPAGE_BATCH_SIZE 512 -#define SUPERPAGE_2MB_SHIFT 9 -#define SUPERPAGE_2MB_NR_PFNS (1UL << SUPERPAGE_2MB_SHIFT) -#define SUPERPAGE_1GB_SHIFT 18 -#define SUPERPAGE_1GB_NR_PFNS (1UL << SUPERPAGE_1GB_SHIFT) -#define X86_CR0_PE 0x01#define X86_CR0_ET 0x10
tools/libxc/xc_private.h +5 -0
@@ -66,6 +66,11 @@ struct iovec {#define DECLARE_FLASK_OP struct xen_flask_op op#define DECLARE_PLATFORM_OP struct xen_platform_op platform_op +#define SUPERPAGE_2MB_SHIFT 9 +#define SUPERPAGE_2MB_NR_PFNS (1UL << SUPERPAGE_2MB_SHIFT) +#define SUPERPAGE_1GB_SHIFT 18 +#define SUPERPAGE_1GB_NR_PFNS (1UL << SUPERPAGE_1GB_SHIFT) +#undef PAGE_SHIFT#undef PAGE_SIZE#undef PAGE_MASK
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 2/3 tools/libxc: add API for bitmap access for restore
In reply to Olaf HeringExtend API for managing bitmaps. Each bitmap is now represented by a generic struct xc_sr_bitmap.
Switch the existing populated_pfns to this API.
--- tools/libxc/xc_sr_common.c | 41 ++++++++++++++++++++++++++ tools/libxc/xc_sr_common.h | 72 +++++++++++++++++++++++++++++++++++++++++++-- tools/libxc/xc_sr_restore.c | 66 ++--------------------------------------- 3 files changed, 114 insertions(+), 65 deletions(-)
tools/libxc/xc_sr_common.c +41 -0
@@ -155,6 +155,47 @@ static void __attribute__((unused)) build_assertions(void)BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params ) !=8 ); } +/* +* Expand the tracking structures as needed. +* To avoid realloc()ing too excessively, the size increased to the nearest power +* of two large enough to contain the required number of bits. +*/ +bool _xc_sr_bitmap_resize (struct xc_sr_bitmap *bm,unsigned long bits) +{ +if (bits > bm->bits) + { +size_t new_max; +size_t old_sz, new_sz; +void *p; + +/* Round up to the nearest power of two larger than bit, less 1. */ + new_max = bits; + new_max |= new_max >>1 ; + new_max |= new_max >>2 ; + new_max |= new_max >>4 ; + new_max |= new_max >>8 ; + new_max |= new_max >>16 ; +#ifdef __x86_64__ + new_max |= new_max >>32 ; +#endif + + old_sz =bitmap_size (bm->bits +1 ); + new_sz =bitmap_size (new_max +1 ); + p =realloc (bm->p, new_sz); +if (!p) +return false; + +if (bm->p) +memset (p + old_sz,0 , new_sz - old_sz); +else +memset (p,0 , new_sz); + + bm->p = p; + bm->bits = new_max; + } +return true; +} +/* * Local variables: * mode: C
tools/libxc/xc_sr_common.h +70 -2
90 lines not on this page · raw message
tools/libxc/xc_sr_restore.c +3 -63
84 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 3/3 tools/libxc: use superpages during restore of HVM guest
In reply to Olaf HeringDuring creating of a HVM domU meminit_hvm() tries to map superpages. After save/restore or migration this mapping is lost, everything is allocated in single pages. This causes a performance degradition after migration.
Add neccessary code to preallocate a superpage for the chunk of pfns that is received. In case a pfn was not populated on the sending side it must be freed on the receiving side to avoid over-allocation.
The existing code for x86_pv is moved unmodified into its own file.
--- tools/libxc/xc_sr_common.h | 26 ++- tools/libxc/xc_sr_restore.c | 75 +------- tools/libxc/xc_sr_restore_x86_hvm.c | 341 ++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_restore_x86_pv.c | 72 +++++++- 4 files changed, 436 insertions(+), 78 deletions(-)
tools/libxc/xc_sr_common.h +18 -8
@@ -139,6 +139,16 @@ struct xc_sr_restore_ops*/ int (*setup)(struct xc_sr_context *ctx); +/** +* Populate PFNs +* +* Given a set of pfns, obtain memory from Xen to fill the physmap for the +* unpopulated subset. +*/ +int (*populate_pfns)(struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types); + +/** * Process an individual record from the stream. The caller shall take * care of processing common records (e.g. END, PAGE_DATA).
@@ -224,6 +234,8 @@ struct xc_sr_contextint 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. */
@@ -336,6 +348,12 @@ struct xc_sr_context/* HVM context blob. */ void *context;size_t contextsz; + +/* Bitmap of currently allocated PFNs during restore. */ +struct xc_sr_bitmap attempted_1g; +struct xc_sr_bitmap attempted_2m; +struct xc_sr_bitmap allocated_pfns; +xen_pfn_t idx1G_prev, idx2M_prev; } restore; }; } x86_hvm;
@@ -459,14 +477,6 @@ static inline int write_record(struct xc_sr_context *ctx,*/ int read_record (struct xc_sr_context *ctx,int fd,struct xc_sr_record *rec); -/* -* This would ideally be private in restore.c, but is needed by -* x86_pv_localise_page() if we receive pagetables frames ahead of the -* contents of the frames they point at. -*/ -int populate_pfns (struct xc_sr_context *ctx,unsigned count, -const xen_pfn_t *original_pfns,const uint32_t *types); -#endif /* * Local variables:
tools/libxc/xc_sr_restore.c +6 -69
94 lines not on this page · raw message
tools/libxc/xc_sr_restore_x86_hvm.c +341 -0
370 lines not on this page · raw message
tools/libxc/xc_sr_restore_x86_pv.c +71 -1
90 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
On Fri, Sep 01, 2017 at 06:08:43PM +0200, Olaf Hering wrote:
[...]
Quoted 7 lines
tools/libxc/xc_sr_common.h +0
-0@@ -139,6 +139,16 @@ struct xc_sr_restore_ops*/ int (*setup)(struct xc_sr_context *ctx);
tools/libxc/xc_sr_common.h struct xc_sr_restore_ops · line 150
Quoted 10 lines
tools/libxc/xc_sr_common.h +9
-0+/** +* Populate PFNs +* +* Given a set of pfns, obtain memory from Xen to fill the physmap for the +* unpopulated subset. +*/ +int (*populate_pfns)(struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types); +
One blank line is good enough.
Quoted 41 lines
tools/libxc/xc_sr_common.h +9
-8+/** * Process an individual record from the stream. The caller shall take * care of processing common records (e.g. END, PAGE_DATA). @@ -224,6 +234,8 @@ struct xc_sr_contextint 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. */ @@ -336,6 +348,12 @@ struct xc_sr_context/* HVM context blob. */ void *context;size_t contextsz; + +/* Bitmap of currently allocated PFNs during restore. */ +struct xc_sr_bitmap attempted_1g; +struct xc_sr_bitmap attempted_2m; +struct xc_sr_bitmap allocated_pfns; +xen_pfn_t idx1G_prev, idx2M_prev; } restore; }; } x86_hvm;@@ -459,14 +477,6 @@ static inline int write_record(struct xc_sr_context *ctx,*/ int read_record (struct xc_sr_context *ctx,int fd,struct xc_sr_record *rec); -/* -* This would ideally be private in restore.c, but is needed by -* x86_pv_localise_page() if we receive pagetables frames ahead of the -* contents of the frames they point at. -*/ -int populate_pfns (struct xc_sr_context *ctx,unsigned count, -const xen_pfn_t *original_pfns,const uint32_t *types); -#endif /* * Local variables:
[...]
Quoted 2 lines
+struct
x86_hvm_sp{
Forgot to ask: what does sp stand for?
tools/libxc/xc_sr_common.h
Quoted 6 lines
tools/libxc/xc_sr_common.h +6
-0+static bool x86_hvm_punch_hole (struct xc_sr_context *ctx,xen_pfn_t max_pfn) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_bitmap *bm; +xen_pfn_t _pfn, pfn, min_pfn; +uint32_t domid, freed =0 , order;
unsigned int / long for freed and order.
tools/libxc/xc_sr_common.h
Quoted 9 lines
tools/libxc/xc_sr_common.h +9
-0+int rc =-1 ; + +/* +* Scan the entire superpage because several batches will fit into +* a superpage, and it is unknown which pfn triggered the allocation. +*/ + order =SUPERPAGE_1GB_SHIFT ; + pfn = min_pfn = (max_pfn >> order) << order; +
min_pfn -> start_pfn?
tools/libxc/xc_sr_common.h
Quoted 2 lines
tools/libxc/xc_sr_common.h +2
-0+while ( pfn <= max_pfn ) + {
bm can be defined here.
tools/libxc/xc_sr_common.h
Quoted 8 lines
tools/libxc/xc_sr_common.h +8
-0+ bm = &ctx->x86_hvm.restore.allocated_pfns; +if ( !xc_sr_bitmap_resize (bm, pfn) ) + { +PERROR ("Failed to realloc allocated_pfns %" PRI_xen_pfn, pfn); +return false; + } +if ( !pfn_is_populated (ctx, pfn) && +xc_sr_test_and_clear_bit (pfn, bm) ) {
domid and _pfn can be defined here.
tools/libxc/xc_sr_common.h
Quoted 3 lines
tools/libxc/xc_sr_common.h +3
-0+ domid = ctx->domid; + _pfn = pfn; + rc =xc_domain_decrease_reservation_exact (xch, domid,1 ,0 , &_pfn);
Please batch the requests otherwise it is going to be very slow.
It should be feasible to construct an array of pfns here and issue a single decrease_reservation outside of this loop.
Quoted 10 lines
tools/libxc/xc_sr_common.h +10
-0+if ( rc ) + { +PERROR ("Failed to release pfn %" PRI_xen_pfn, pfn); +return false; + } + ctx->restore.tot_pages--; + freed++; + } + pfn++; + }
tools/libxc/xc_sr_common.h
Quoted 10 lines
tools/libxc/xc_sr_common.h +10
-0+if ( freed ) +DPRINTF ("freed %u between %" PRI_xen_pfn" %" PRI_xen_pfn"\n" , + freed, min_pfn, max_pfn); +return true; +} + +/* +* Try to allocate superpages. +* This works without memory map only if the pfns arrive in incremental order. +*/
I have said several times, one way or another, I don't want to make assumption on the stream of pfns. So I'm afraid I can't ack a patch like this.
If Ian or Andrew thinks this is OK, I won't stand in the way.
tools/libxc/xc_sr_common.h
Quoted 2 lines
tools/libxc/xc_sr_common.h +2
-0+static int x86_hvm_populate_pfns(struct xc_sr_context *ctx, unsigned count, + const xen_pfn_t *original_pfns,
original_pfns -> pfns?
The list is not copied and/or altered in any way afaict.
(I skipped the rest)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
Quoted 25 lines
Quoted 11 lines
tools/libxc/xc_sr_restore_x86_hvm.c +10
-0+if ( rc ) + { +PERROR ("Failed to release pfn %" PRI_xen_pfn, pfn); +return false; + } + ctx->restore.tot_pages--; + freed++; + } + pfn++; + }tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_stream_complete(struct xc_sr_context *ctx) · line 490
Quoted 10 lines
tools/libxc/xc_sr_restore_x86_hvm.c +10
-0+if ( freed ) +DPRINTF ("freed %u between %" PRI_xen_pfn" %" PRI_xen_pfn"\n" , + freed, min_pfn, max_pfn); +return true; +} + +/* +* Try to allocate superpages. +* This works without memory map only if the pfns arrive in incremental order. +*/ I have said several times, one way or another, I don't want to make assumption on the stream of pfns. So I'm afraid I can't ack a patch like this.
Quoted 1 line
If Ian or Andrew thinks this is OK, I won't stand in the way.
The stream has always been in-order for the first pass (even in the legacy days), and I don't forsee that changing. Reliance on the order was suggested by both myself and Jan during the early design.
It is certainly an acceptable assumption until we put a proper address map into the head of the stream.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] tools/libxc: add API for bitmap access for restore
In reply to Olaf HeringQuoted 18 lines · Olaf Hering
Extend API for managing bitmaps. Each bitmap is now represented by a generic struct
xc_sr_bitmap.
Switch the existingpopulated_pfnsto this API.Signed-off-by Olaf Hering <[email protected]>Acked-by Wei Liu <[email protected]>--- tools/libxc/xc_sr_common.c | 41 ++++++++++++++++++++++++++ tools/libxc/xc_sr_common.h | 72 +++++++++++++++++++++++++++++++++++++++++++-- tools/libxc/xc_sr_restore.c | 66 ++--------------------------------------- 3 files changed, 114 insertions(+), 65 deletions(-)tools/libxc/xc_sr_common.c +0
-0@@ -155,6 +155,47 @@ static void __attribute__((unused)) build_assertions(void)BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params ) !=8 );
tools/libxc/xc_sr_common.c static void __attribute__((unused)) build_assertions(void) · line 165
Quoted 10 lines
tools/libxc/xc_sr_common.c +8
-0} +/* +* Expand the tracking structures as needed. +* To avoid realloc()ing too excessively, the size increased to the nearest power +* of two large enough to contain the required number of bits. +*/ +bool _xc_sr_bitmap_resize (struct xc_sr_bitmap *bm,unsigned long bits) +{ +if (bits > bm->bits)
Libxc uses the hypervisor coding style, and xc_sr_* currently have a consistent style.
Quoted 64 lines
tools/libxc/xc_sr_common.c +33
-0+ { +size_t new_max; +size_t old_sz, new_sz; +void *p; + +/* Round up to the nearest power of two larger than bit, less 1. */ + new_max = bits; + new_max |= new_max >>1 ; + new_max |= new_max >>2 ; + new_max |= new_max >>4 ; + new_max |= new_max >>8 ; + new_max |= new_max >>16 ; +#ifdef __x86_64__ + new_max |= new_max >>32 ; +#endif + + old_sz =bitmap_size (bm->bits +1 ); + new_sz =bitmap_size (new_max +1 ); + p =realloc (bm->p, new_sz); +if (!p) +return false; + +if (bm->p) +memset (p + old_sz,0 , new_sz - old_sz); +else +memset (p,0 , new_sz); + + bm->p = p; + bm->bits = new_max; + } +return true; +} +/* * Local variables: * mode: C tools/libxc/xc_sr_common.h +7
-2@@ -172,6 +172,12 @@ struct xc_sr_x86_pv_restore_vcpusize_t basicsz, extdsz, xsavesz, msrsz; }; +struct xc_sr_bitmap +{ +void *p; +unsigned long bits; +}; +struct xc_sr_context {xc_interface *xch;@@ -255,8 +261,7 @@ struct xc_sr_contextdomid_t xenstore_domid, console_domid;/* Bitmap of currently populated PFNs during restore. */ -unsigned long *populated_pfns; -xen_pfn_t max_populated_pfn; +struct xc_sr_bitmap populated_pfns;/* Sender has invoked verify mode on the stream. */ bool verify;
tools/libxc/xc_sr_common.h extern struct xc_sr_save_ops save_ops_x86_hvm; · line 351
Quoted 4 lines
tools/libxc/xc_sr_common.h +1
-0@@ -343,6 +348,69 @@ extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv;extern struct xc_sr_restore_ops restore_ops_x86_hvm; +extern bool _xc_sr_bitmap_resize (struct xc_sr_bitmap *bm,unsigned long bits);
No need for extern on function prototypes.
tools/libxc/xc_sr_common.h extern struct xc_sr_save_ops save_ops_x86_hvm; · line 363
Quoted 12 lines
tools/libxc/xc_sr_common.h +12
-0+ +static inline bool xc_sr_bitmap_resize (struct xc_sr_bitmap *bm,unsigned long bits) +{ +if (bits > bm->bits) +return _xc_sr_bitmap_resize (bm, bits); +return true; +} + +static inline void xc_sr_bitmap_free (struct xc_sr_bitmap *bm) +{ +free (bm->p); + bm->p =NULL ;
bm->bits = 0, or a subsequent test/set/clear will fall over a NULL pointer.
tools/libxc/xc_sr_common.h extern struct xc_sr_save_ops save_ops_x86_hvm; · line 368
Quoted 5 lines
tools/libxc/xc_sr_common.h +5
-0+} + +static inline bool xc_sr_set_bit (unsigned long bit,struct xc_sr_bitmap *bm) +{ +if (!xc_sr_bitmap_resize (bm, bit))
There's a boundary condition here trying to test bit 0 of an empty bitmap.
Quoted 34 lines
tools/libxc/xc_sr_common.h +34
-0+return false; + +set_bit (bit, bm->p); +return true; +} + +static inline bool xc_sr_test_bit (unsigned long bit,struct xc_sr_bitmap *bm) +{ +if (bit > bm->bits) +return false; +return !!test_bit (bit, bm->p); +} + +static inline bool xc_sr_test_and_clear_bit (unsigned long bit,struct xc_sr_bitmap *bm) +{ +if (bit > bm->bits) +return false; +return !!test_and_clear_bit (bit, bm->p); +} + +static inline bool xc_sr_test_and_set_bit (unsigned long bit,struct xc_sr_bitmap *bm) +{ +if (bit > bm->bits) +return false; +return !!test_and_set_bit (bit, bm->p); +} + +static inline bool pfn_is_populated (struct xc_sr_context *ctx,xen_pfn_t pfn) +{ +return xc_sr_test_bit (pfn, &ctx->restore.populated_pfns); +} + +static inline int pfn_set_populated (struct xc_sr_context *ctx,xen_pfn_t pfn) +{
tools/libxc/xc_sr_common.h extern struct xc_sr_save_ops save_ops_x86_hvm; · line 412
Quoted 10 lines
tools/libxc/xc_sr_common.h +10
-0+xc_interface *xch = ctx->xch; + +if ( !xc_sr_set_bit (pfn, &ctx->restore.populated_pfns) ) + { +ERROR ("Failed to realloc populated_pfns bitmap" ); + errno =ENOMEM ; +return -1 ; + } +return 0 ; +}
Why are these moved? They are still restore specific.
~Andrew
Quoted 87 lines
tools/libxc/xc_sr_common.h +1
-0+struct xc_sr_record {uint32_t type;tools/libxc/xc_sr_restore.c +2
-62@@ -68,64 +68,6 @@ static int read_headers(struct xc_sr_context *ctx)return 0 ; } -/* -* Is a pfn populated? -*/ -static bool pfn_is_populated (const struct xc_sr_context *ctx,xen_pfn_t pfn) -{ -if ( pfn > ctx->restore.max_populated_pfn ) -return false; -return test_bit (pfn, ctx->restore.populated_pfns); -} - -/* -* Set a pfn as populated, expanding the tracking structures if needed. To -* avoid realloc()ing too excessively, the size increased to the nearest power -* of two large enough to contain the required pfn. -*/ -static int pfn_set_populated (struct xc_sr_context *ctx,xen_pfn_t pfn) -{ -xc_interface *xch = ctx->xch; - -if ( pfn > ctx->restore.max_populated_pfn ) - { -xen_pfn_t new_max; -size_t old_sz, new_sz; -unsigned long *p; - -/* Round up to the nearest power of two larger than pfn, less 1. */ - new_max = pfn; - new_max |= new_max >>1 ; - new_max |= new_max >>2 ; - new_max |= new_max >>4 ; - new_max |= new_max >>8 ; - new_max |= new_max >>16 ; -#ifdef __x86_64__ - new_max |= new_max >>32 ; -#endif - - old_sz =bitmap_size (ctx->restore.max_populated_pfn +1 ); - new_sz =bitmap_size (new_max +1 ); - p =realloc (ctx->restore.populated_pfns, new_sz); -if ( !p ) - { -ERROR ("Failed to realloc populated bitmap" ); - errno =ENOMEM ; -return -1 ; - } - -memset ((uint8_t *)p + old_sz,0x00 , new_sz - old_sz); - - ctx->restore.populated_pfns = p; - ctx->restore.max_populated_pfn = new_max; - } - -assert (!test_bit (pfn, ctx->restore.populated_pfns)); -set_bit (pfn, ctx->restore.populated_pfns); - -return 0 ; -} -/* * Given a set of pfns, obtain memory from Xen to fill the physmap for the * unpopulated subset. If types is NULL, no page type checking is performed @@ -684,10 +626,8 @@ static int setup(struct xc_sr_context *ctx)if ( rc ) goto err; - ctx->restore.max_populated_pfn = (32 *1024 /4 ) -1 ; - ctx->restore.populated_pfns =bitmap_alloc ( - ctx->restore.max_populated_pfn +1 ); -if ( !ctx->restore.populated_pfns ) + rc = !xc_sr_bitmap_resize (&ctx->restore.populated_pfns,32 *1024 /4 ); +if ( rc ) {ERROR ("Unable to allocate memory for populated_pfns bitmap" ); rc =-1 ;
tools/libxc/xc_sr_restore.c static void cleanup(struct xc_sr_context *ctx) · line 668
Quoted 8 lines
tools/libxc/xc_sr_restore.c +1
-1@@ -722,7 +662,7 @@ static void cleanup(struct xc_sr_context *ctx)xc_hypercall_buffer_free_pages (xch, dirty_bitmap,NRPAGES (bitmap_size (ctx->restore.p2m_size)));free (ctx->restore.buffered_records); -free (ctx->restore.populated_pfns); +xc_sr_bitmap_free (&ctx->restore.populated_pfns);if ( ctx->restore.ops.cleanup (ctx) )PERROR ("Failed to clean up" ); }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
In reply to Wei LiuAm Wed, 6 Sep 2017 12:34:10 +0100
schrieb Wei Liu <[email protected]>:
Quoted 2 lines
Quoted 1 line
+struct
x86_hvm_sp{Forgot to ask: what does sp stand for?
superpage. I will check if there is room to expand this string.
Quoted 6 lines
Quoted 3 lines
+ * Try to allocate superpages.
+ * This works without memory map only if the pfns arrive in incremental order.
+ */I have said several times, one way or another, I don't want to make assumption on the stream of pfns. So I'm afraid I can't ack a patch like this.
It will work with any order, I think. Just with incremental order the superpages will not be split once they are allocated.
Thanks for the review. I will send another series shortly.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
In reply to Olaf Heringtools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_setup(struct xc_sr_context *ctx) · line 171
Quoted 3 lines · Olaf Hering
tools/libxc/xc_sr_restore_x86_hvm.c +3
-0+/* No superpage in 1st 2MB due to VGA hole */ +xc_sr_set_bit (0 , &ctx->x86_hvm.restore.attempted_1g); +xc_sr_set_bit (0 , &ctx->x86_hvm.restore.attempted_2m);
This is false for PVH guests.
I still fail to understand why you need the bitmaps at all? You can calculate everything you need from the pfn list alone, which will also let you spot the presence or absence of the VGA hole.
You need to track which pfns you've see so far in the stream, and which pfns have been populated. When you find holes in the pfns in the stream, you need to undo the prospective superpage allocation. Unless I've missed something?
Also, please take care to use 2M decrease reservations wherever possible, or you will end up shattering the host superpage as part of trying to remove the memory.
~Andrew
tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_setup(struct xc_sr_context *ctx) · line 180
Quoted 10 lines
tools/libxc/xc_sr_restore_x86_hvm.c +5
-0+return 0 ; + +out: +ERROR ("Unable to allocate memory for pfn bitmaps" ); +return -1 ; }/*
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] tools/libxc: add API for bitmap access for restore
In reply to Andrew CooperQuoted 4 lines · Andrew Cooper
tools/libxc/xc_sr_common.h extern struct xc_sr_save_ops save_ops_x86_hvm; · line 401
Quoted 2 lines · Olaf Hering
tools/libxc/xc_sr_common.h +2
-0+static inline bool pfn_is_populated(struct xc_sr_context *ctx, xen_pfn_t pfn) +static inline int pfn_set_populated(struct xc_sr_context *ctx, xen_pfn_t pfn)Why are these moved? They are still restore specific.
There is no tools/libxc/xc_sr_restore.h, should I create one?
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
In reply to Andrew CooperQuoted 5 lines · Andrew Cooper
tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_setup(struct xc_sr_context *ctx) · line 171
Quoted 3 lines · Olaf Hering
tools/libxc/xc_sr_restore_x86_hvm.c +3
-0+/* No superpage in 1st 2MB due to VGA hole */ +xc_sr_set_bit (0 , &ctx->x86_hvm.restore.attempted_1g); +xc_sr_set_bit (0 , &ctx->x86_hvm.restore.attempted_2m);This is false for PVH guests.
How can I detect a PVH guest?
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
Quoted 8 lines · Olaf Hering
Quoted 5 lines · Andrew Cooper
tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_setup(struct xc_sr_context *ctx) · line 171
Quoted 3 lines · Olaf Hering
tools/libxc/xc_sr_restore_x86_hvm.c +3
-0+/* No superpage in 1st 2MB due to VGA hole */ +xc_sr_set_bit (0 , &ctx->x86_hvm.restore.attempted_1g); +xc_sr_set_bit (0 , &ctx->x86_hvm.restore.attempted_2m);This is false for PVH guests.
How can I detect a PVH guest?
You (hopefully) can't, and it would be a layering violation if you could.
The exact set of emulation available to/used by a guest is not relevant to how we move its memory.
If a PVH guest has got MTRRs disabled, then it genuinely can run on an unshattered 1G superpage at 0.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
In reply to Andrew CooperQuoted 3 lines · Andrew Cooper
I still fail to understand why you need the bitmaps at all? You can calculate everything you need from the pfn list alone, which will also let you spot the presence or absence of the VGA hole.
These bitmaps track if a range has been allocated as superpage or not. If there is a given pfn within a range of either 1G or 2M there might be double allocation of a 1G or 2M page. This is not related to the VGA hole. These two lines are just hints that in this range no superpage can be allocated.
Quoted 4 lines
You need to track which pfns you've see so far in the stream, and which pfns have been populated. When you find holes in the pfns in the stream, you need to undo the prospective superpage allocation. Unless I've missed something?
This is whats happening, holes will be created as soon as they are seen in the stream.
Quoted 3 lines
Also, please take care to use 2M decrease reservations wherever possible, or you will end up shattering the host superpage as part of trying to remove the memory.
This is what Wei suggested, build a list of pfns instead of releasing each pfn individually. I think with this new code it should be possible to decrease in 2M steps as needed.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
In reply to Andrew CooperQuoted 2 lines · Andrew Cooper
If a PVH guest has got MTRRs disabled, then it genuinely can run on an unshattered 1G superpage at 0.
Ok, the code will detect the holes and will release memory as needed. I will drop these two lines.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
In reply to Andrew CooperQuoted 3 lines · Andrew Cooper
The stream has always been in-order for the first pass (even in the legacy days), and I don't forsee that changing. Reliance on the order was suggested by both myself and Jan during the early design.
A related question: is it save to increase MAX_BATCH_SIZE from 1024 to (256*1024) to transfer a whole gigabyte at a time? That way it will be easier to handle holes within a 1GB superpage.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
Quoted 3 lines · Olaf Hering
A related question: is it save to increase
MAX_BATCH_SIZEfrom 1024 to (256*1024) to transfer a whole gigabyte at a time? That way it will be easier to handle holes within a 1GB superpage.
To answer my own question:
This change leads to this error:
-#define MAX_BATCH_SIZE 1024 /* up to 1024 pages (4MB) at a time */
+#define MAX_BATCH_SIZE SUPERPAGE_1GB_NR_PFNS /* up to 1GB at a time */
...
xc: info: Found x86 HVM domain from Xen 4.10
xc: detail: dom 9 p2m_size fee01 max_pages 100100
xc: info: Restoring domain
xc: error: Failed to read Record Header from stream (0 = Success): Internal error
xc: error: Restore failed (0 = Success): Internal error
...
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] tools/libxc: use superpages during restore of HVM guest
Review
Quoted 2 lines · Olaf Hering
(quoted diff) +1
-1-#define MAX_BATCH_SIZE 1024 /* up to 1024 pages (4MB) at a time */ +#define MAX_BATCH_SIZE SUPERPAGE_1GB_NR_PFNS /* up to 1GB at a time */
Actually the error is something else, I missed this in the debug output:
xc: error: Failed to get types for pfn batch (7 = Argument list too long): Internal error
write_batch() should probably split the requests when filling types[] because Xen has "1024" hardcoded in XEN_DOMCTL_getpageframeinfo3...
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel