tools/libxc: use superpages during restore of HVM guest
PATCH 1/1 tools/libxc: use superpages during restore of HVM guest
During 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.
---
based on RELEASE-4.9.0
tools/libxc/xc_sr_common.c | 41 ++++++++ tools/libxc/xc_sr_common.h | 79 +++++++++++++++- tools/libxc/xc_sr_restore.c | 135 +------------------------- tools/libxc/xc_sr_restore_x86_hvm.c | 183 ++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_restore_x86_pv.c | 72 +++++++++++++- 5 files changed, 376 insertions(+), 134 deletions(-)
tools/libxc/xc_sr_common.c +41 -0
@@ -156,6 +156,47 @@ static void __attribute__((unused)) build_assertions(void) }/* +* 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 * c-file-style: "BSD"
tools/libxc/xc_sr_common.h +77 -2
109 lines not on this page · raw message
tools/libxc/xc_sr_restore.c +4 -131
159 lines not on this page · raw message
tools/libxc/xc_sr_restore_x86_hvm.c +183 -0
218 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
tools/libxc/xc_sr_restore_x86_hvm.c line 9
Quoted 6 lines · Olaf Hering
+++
b/tools/libxc/xc_sr_restore_x86_hvm.ctools/libxc/xc_sr_restore_x86_hvm.c +4
-0+#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)
I think these can be moved to a header file. xc_dom_x86.c and xc_sr_restore_x86_hvm.c use xc_dom.h.
Quoted 8 lines
tools/libxc/xc_sr_restore_x86_hvm.c +8
-0+static int x86_hvm_populate_pfns (struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns, +const uint32_t *types) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t min_pfn = original_pfns[0 ], max_pfn = original_pfns[0 ]; +unsigned i; +int rc =-1 ;
tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_stream_complete(struct xc_sr_context *ctx) · line 376
Quoted 10 lines
tools/libxc/xc_sr_restore_x86_hvm.c +10
-0+ +for ( i =0 ; i < count; ++i ) + { +if (original_pfns[i] < min_pfn) + min_pfn = original_pfns[i]; +if (original_pfns[i] > max_pfn) + max_pfn = original_pfns[i]; +if ( (types[i] !=XEN_DOMCTL_PFINFO_XTAB && + types[i] !=XEN_DOMCTL_PFINFO_BROKEN ) && + !pfn_is_populated (ctx, original_pfns[i]) )
Are these types used at all for a HVM domU? Otherwise this condition can be simplified to just check the populated state.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 25 lines · Olaf Hering
tools/libxc/xc_sr_restore_x86_hvm.c line 9
Quoted 6 lines · Olaf Hering
+++
b/tools/libxc/xc_sr_restore_x86_hvm.ctools/libxc/xc_sr_restore_x86_hvm.c +4
-0+#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)I think these can be moved to a header file.
xc_dom_x86.candxc_sr_restore_x86_hvm.cusexc_dom.h.Quoted 13 lines
tools/libxc/xc_sr_restore_x86_hvm.c +13
-0+static int x86_hvm_populate_pfns (struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns, +const uint32_t *types) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t min_pfn = original_pfns[0 ], max_pfn = original_pfns[0 ]; +unsigned i; +int rc =-1 ; + +for ( i =0 ; i < count; ++i ) + { +if (original_pfns[i] < min_pfn) + min_pfn = original_pfns[i];
Quoted 8 lines
tools/libxc/xc_sr_restore_x86_hvm.c static int x86_hvm_stream_complete(struct xc_sr_context *ctx) · line 376
Quoted 5 lines
tools/libxc/xc_sr_restore_x86_hvm.c +5
-0+if (original_pfns[i] > max_pfn) + max_pfn = original_pfns[i]; +if ( (types[i] !=XEN_DOMCTL_PFINFO_XTAB && + types[i] !=XEN_DOMCTL_PFINFO_BROKEN ) && + !pfn_is_populated (ctx, original_pfns[i]) )Are these types used at all for a HVM domU? Otherwise this condition can be simplified to just check the populated state.
I *think* XTAB is PV only but BROKEN applies to both PV and HVM.
Maybe someone more familiar with the bit can chime in to provide more information.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 11 lines · Olaf Hering
During 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_pvis moved unmodified into its own file.
Can you split this patch into several:
1. code movement
2. refactoring / introduction of new hooks
3. implementing the new algorithm
Thanks
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 4 lines · Wei Liu
Can you split this patch into several:
1. code movement
2. refactoring / introduction of new hooks
3. implementing the new algorithm
I tried that, it did not work well. But, I can try again if required.
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel