x86: Get rid of p2m_host array allocation for HVM guests
PATCH 1/1 x86: Get rid of p2m_host array allocation for HVM guests
When allocating the guest memory for an HVM domain, libxc keeps the P2M mapping for the entirety of the guest memory around for the time of the launch as xc_dom_image->p2m_host. For guests that have a large memory (3904 GiB), the p2m_host allocation takes more than 7.5 GiB of space, and leaves xl susceptible to getting OOM-killed on guest creation.
Convert the p2m_host table lookups to an arch-specific function that returns the mapping on-the-fly for x86 HVM guests to avoid this allocation, bringing down xl's memory usage from > 8GiB to < 70Mib for such launches.
---
Applies to stable-4.11+.
tools/libxc/include/xc_dom.h | 11 +++- tools/libxc/xc_dom_arm.c | 2 + tools/libxc/xc_dom_core.c | 4 +- tools/libxc/xc_dom_x86.c | 126 ++++++++++++++++++++++++++++--------------- 4 files changed, 99 insertions(+), 44 deletions(-)
tools/libxc/include/xc_dom.h +10 -1
@@ -131,6 +131,9 @@ struct xc_dom_image {* a hybrid guest this means that it maps GPFNs to GPFNS. * * Note that the input is offset by rambase. +* +* This is not populated for guests that provide an arch-specific +* lookup hook in arch_hooks. */ xen_pfn_t *p2m_host;void *p2m_guest;
@@ -274,6 +277,10 @@ struct xc_dom_arch {int arch_private_size;struct xc_dom_arch *next; + +/* arch-specific p2m table lookup to get rid of the p2m_host array stored in +* xc_dom_image. */ +xen_pfn_t (*p2m_host) (struct xc_dom_image *dom,unsigned long idx); };void xc_dom_register_arch_hooks (struct xc_dom_arch *hooks);
@@ -437,7 +444,9 @@ static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)return pfn;if (pfn < dom->rambase_pfn || pfn >= dom->rambase_pfn + dom->total_pages)return INVALID_MFN ; - return dom->p2m_host[pfn - dom->rambase_pfn]; +return dom->arch_hooks->p2m_host ? + dom->arch_hooks->p2m_host (dom, pfn - dom->rambase_pfn) + : dom->p2m_host[pfn - dom->rambase_pfn]; }#endif /* _XC_DOM_H */
tools/libxc/xc_dom_arm.c +2 -0
@@ -547,6 +547,7 @@ static struct xc_dom_arch xc_dom_32 = { .meminit = meminit, .bootearly = bootearly, .bootlate = bootlate, + .p2m_host = NULL, };static struct xc_dom_arch xc_dom_64 = {
@@ -563,6 +564,7 @@ static struct xc_dom_arch xc_dom_64 = { .meminit = meminit, .bootearly = bootearly, .bootlate = bootlate, + .p2m_host = NULL, };static void __init register_arch_hooks (void )
tools/libxc/xc_dom_core.c +3 -1
@@ -985,7 +985,9 @@ int xc_dom_update_guest_p2m(struct xc_dom_image *dom) __FUNCTION__, dom->p2m_size); p2m_32 = dom->p2m_guest;for ( i =0 ; i < dom->p2m_size; i++ ) -if ( dom->p2m_host[i] !=INVALID_PFN ) +if ( dom->arch_hooks->p2m_host ) + p2m_32[i] = dom->arch_hooks->p2m_host (dom, i); +else if ( dom->p2m_host[i] !=INVALID_PFN ) p2m_32[i] = dom->p2m_host[i];else p2m_32[i] = (uint32_t ) -1 ;
tools/libxc/xc_dom_x86.c +84 -42
228 lines not on this page · raw message
Signature · 20 lines
2.7.4 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Varad Gautam
When allocating the guest memory for an HVM domain, libxc keeps the P2M mapping for the entirety of the guest memory around for the time of the launch as
xc_dom_image->p2m_host. For guests that have a large memory (3904 GiB), thep2m_hostallocation takes more than 7.5 GiB of space, and leaves xl susceptible to getting OOM-killed on guest creation.Convert the
p2m_hosttable lookups to an arch-specific function that returns the mapping on-the-fly for x86 HVM guests to avoid this allocation, bringing down xl's memory usage from > 8GiB to < 70Mib for such launches.Signed-off-by Varad Gautam <[email protected]>---
Quoted 7 lines
Applies to stable-4.11+.
tools/libxc/include/xc_dom.h | 11 +++- tools/libxc/xc_dom_arm.c | 2 + tools/libxc/xc_dom_core.c | 4 +- tools/libxc/xc_dom_x86.c | 126 ++++++++++++++++++++++++++++--------------- 4 files changed, 99 insertions(+), 44 deletions(-)
May I ask that you tag such patches correctly? Seeing the subject, I've assumed the Cc list isn't right, thus pulling it into my to-be-reviewed folder. The subject here really wants to contain e.g. libxc, like in "libxc/x86: ...".
Thanks, Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Varad Gautam
When allocating the guest memory for an HVM domain, libxc keeps the P2M mapping for the entirety of the guest memory around for the time of the launch as
xc_dom_image->p2m_host. For guests that have a large memory (3904 GiB),
This is slightly awkward phrasing. How about "For large memory guests (e.g. 3904 GiB), "
Quoted 9 lines
the
p2m_hostallocation takes more than 7.5 GiB of space, and
leaves xl susceptible to getting OOM-killed on guest creation.Convert the
p2m_hosttable lookups to an arch-specific function that returns the mapping on-the-fly for x86 HVM guests to avoid this allocation, bringing down xl's memory usage from > 8GiB to < 70Mib for such launches.Signed-off-by Varad Gautam <[email protected]>
I can definitely see why you want to avoid this overhead.
In practice, p2m_host looks to be a relic of x86 PV guests.
Now - first things first. Exactly the same reasoning applies to all ARM guests. (CC'ing the ARM maintainers for visibility)
However, in attempting to review this, I've got some bigger questions.
All ARM and x86 HVM (and PVH) guests return true for xc_dom_translated(), so should take the fastpath out of xc_dom_p2m() and never read from dom->p2m_host[]. Therefore, I don't see why the majority of this patch is necessary. On the ARM side, this also means that dom->rambase_pfn isn't being used as intended, which suggests there is further cleanup/correction to be done here.
xc_dom_update_guest_p2m() is clearly specific to x86 PV guests. No other guest types set dom->p2m_guest.
I don't see why anything is needed with the vmemranges[]. The result of the new p2m_host() hook never has its return value checked, and dom->p2m_host is still an identity transform within those ranges.
Unless I'm missing something, I think the result can be rather more simple, and strip out a fair amount of code, by moving p2m_host/p2m_guest into x86 PV's arch_private area.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Andrew,
Quoted 17 lines · Andrew Cooper
Quoted 4 lines · Varad Gautam
When allocating the guest memory for an HVM domain, libxc keeps the P2M mapping for the entirety of the guest memory around for the time of the launch as
xc_dom_image->p2m_host. For guests that have a large memory (3904 GiB),This is slightly awkward phrasing. How about "For large memory guests (e.g. 3904 GiB), "
Quoted 8 lines
the
p2m_hostallocation takes more than 7.5 GiB of space, and
leaves xl susceptible to getting OOM-killed on guest creation.Convert the
p2m_hosttable lookups to an arch-specific function that returns the mapping on-the-fly for x86 HVM guests to avoid this allocation, bringing down xl's memory usage from > 8GiB to < 70Mib for such launches.
Quoted 8 lines
Quoted 1 line
Signed-off-by Varad Gautam <[email protected]>I can definitely see why you want to avoid this overhead.
In practice,
p2m_hostlooks to be a relic of x86 PV guests.Now - first things first. Exactly the same reasoning applies to all ARM guests. (CC'ing the ARM maintainers for visibility)
It is already in my todo list to remove p2m_host for Arm, thanks to a discussion with Wei last year :). I have never had the chance to work on it so would be happy if someone pick it up!
Quoted 7 lines
However, in attempting to review this, I've got some bigger questions.
All ARM and x86 HVM (and PVH) guests return true for
xc_dom_translated(), so should take the fastpath out ofxc_dom_p2m()and never read from dom->p2m_host[]. Therefore, I don't see why the majority of this patch is necessary.
I agree that p2m_host will never get used by Arm. So this is a waste of memory.
Quoted 3 lines
On the ARM side, this also means
thatdom->rambase_pfnisn't being used as intended, which suggests there is further cleanup/correction to be done here.
I am not sure to follow this. Could you expand it?
Quoted 8 lines
xc_dom_update_guest_p2m()is clearly specific to x86 PV guests. No other guest types setdom->p2m_guest.I don't see why anything is needed with the vmemranges[]. The result of the new
p2m_host()hook never has its return value checked, anddom->p2m_hostis still an identity transform within those ranges.
Quoted 6 lines
Unless I'm missing something, I think the result can be rather more simple, and strip out a fair amount of code, by moving p2m_host/p2m_guest into x86 PV's
arch_privatearea.~Andrew
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines · Julien Grall
Quoted 7 lines
However, in attempting to review this, I've got some bigger questions.
All ARM and x86 HVM (and PVH) guests return true for
xc_dom_translated(), so should take the fastpath out ofxc_dom_p2m()and never read from dom->p2m_host[]. Therefore, I don't see why the majority of this patch is necessary.
Quoted 8 lines
I agree that
p2m_hostwill never get used by Arm. So this is a waste of memory.Quoted 3 lines
On the ARM side, this also means
thatdom->rambase_pfnisn't being used as intended, which suggests there is further cleanup/correction to be done here.I am not sure to follow this. Could you expand it?
dom->rambase_pfn was introduced for ARM, and the code which uses it in xc_dom_p2m() is dead (on ARM, not on x86).
It isn't functioning as intended.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Andrew,
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Julien Grall
Quoted 7 lines
However, in attempting to review this, I've got some bigger questions.
All ARM and x86 HVM (and PVH) guests return true for
xc_dom_translated(), so should take the fastpath out ofxc_dom_p2m()and never read from dom->p2m_host[]. Therefore, I don't see why the majority of this patch is necessary.I agree that
p2m_hostwill never get used by Arm. So this is a waste of memory.Quoted 3 lines
On the ARM side, this also means
thatdom->rambase_pfnisn't being used as intended, which suggests there is further cleanup/correction to be done here.
Quoted 6 lines
Quoted 1 line
I am not sure to follow this. Could you expand it?
dom->rambase_pfnwas introduced for ARM, and the code which uses it inxc_dom_p2m()is dead (on ARM, not on x86).It isn't functioning as intended.
I am afraid I still don't follow it... rambase_pfn is used in various place in xc_dom_core.c and xc_dom_armzimageloader.c.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel