tools/libxc: use superpages
v5 cover tools/libxc: use superpages
Using superpages on the receiving dom0 will avoid performance regressions.
Olaf
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
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 | 94 ++++++++++-- tools/libxc/xc_sr_restore.c | 141 ++---------------- tools/libxc/xc_sr_restore_x86_hvm.c | 276 ++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_restore_x86_pv.c | 72 +++++++++- 7 files changed, 486 insertions(+), 148 deletions(-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 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 v5 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 | 68 +++++++++++++++++++++++++++++++++++++++++++-- tools/libxc/xc_sr_restore.c | 66 ++----------------------------------------- 3 files changed, 110 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 +66 -2
86 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 v5 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 | 276 ++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_restore_x86_pv.c | 72 +++++++++- 4 files changed, 371 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 min_pfn; } restore; }; } x86_hvm;
@@ -455,14 +473,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 +276 -0
305 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 v5 3/3] tools/libxc: use superpages during restore of HVM guest
tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_stream_complete(struct xc_sr_context *ctx) · line 475
Quoted 6 lines · Olaf Hering
tools/libxc/xc_sr_restore_x86_hvm.c +5
-0+static int x86_hvm_populate_pfns (struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns, +const uint32_t *types) +{ +while ( min_pfn < max_pfn )
Beside this off-by-one error, there is still a bug in accounting somewhere. Ballooned guests sometimes fails due to allocation errors.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel