From: Tim Deegan Subject: [PATCH] xen: make the shadow allocation hypercalls include the p2m Date: Wed, 7 Jul 2010 14:49:50 +0100 Message-ID: <20100707134950.GV31695@whitby.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org xen: make the shadow allocation hypercalls include the p2m memory in the total shadow allocation. This makes the effect of allocation changes consistent regardless of p2m activity on boot. Signed-off-by: Tim Deegan diff -r f84ac3cbeb0d xen/arch/x86/mm/hap/hap.c --- a/xen/arch/x86/mm/hap/hap.c Fri Jun 05 11:42:07 2009 +0100 +++ b/xen/arch/x86/mm/hap/hap.c Mon Jun 08 11:20:54 2009 +0100 @@ -181,7 +181,8 @@ static unsigned int hap_get_allocation(struct domain *d) { - unsigned int pg = d->arch.paging.hap.total_pages; + unsigned int pg = d->arch.paging.hap.total_pages + + d->arch.paging.hap.p2m_pages; return ((pg >> (20 - PAGE_SHIFT)) + ((pg & ((1 << (20 - PAGE_SHIFT)) - 1)) ? 1 : 0)); @@ -195,6 +196,11 @@ struct page_info *pg; ASSERT(hap_locked_by_me(d)); + + if ( pages < d->arch.paging.hap.p2m_pages ) + pages = 0; + else + pages -= d->arch.paging.hap.p2m_pages; while ( d->arch.paging.hap.total_pages != pages ) { @@ -214,6 +220,11 @@ else if ( d->arch.paging.hap.total_pages > pages ) { /* Need to return memory to domheap */ + if ( page_list_empty(&d->arch.paging.hap.freelist) ) + { + HAP_PRINTK("failed to free enough hap pages.\n"); + return -ENOMEM; + } pg = page_list_remove_head(&d->arch.paging.hap.freelist); ASSERT(pg); d->arch.paging.hap.free_pages--; diff -r f84ac3cbeb0d xen/arch/x86/mm/shadow/common.c --- a/xen/arch/x86/mm/shadow/common.c Fri Jun 05 11:42:07 2009 +0100 +++ b/xen/arch/x86/mm/shadow/common.c Mon Jun 08 11:20:54 2009 +0100 @@ -1788,14 +1788,24 @@ unsigned int j, order = shadow_max_order(d); ASSERT(shadow_locked_by_me(d)); - - /* Don't allocate less than the minimum acceptable, plus one page per - * megabyte of RAM (for the p2m table) */ - lower_bound = shadow_min_acceptable_pages(d) + (d->tot_pages / 256); - if ( pages > 0 && pages < lower_bound ) - pages = lower_bound; - /* Round up to largest block size */ - pages = (pages + ((1< 0 ) + { + /* Check for minimum value. */ + if ( pages < d->arch.paging.shadow.p2m_pages ) + pages = 0; + else + pages -= d->arch.paging.shadow.p2m_pages; + + /* Don't allocate less than the minimum acceptable, plus one page per + * megabyte of RAM (for the p2m table) */ + lower_bound = shadow_min_acceptable_pages(d) + (d->tot_pages / 256); + if ( pages < lower_bound ) + pages = lower_bound; + + /* Round up to largest block size */ + pages = (pages + ((1<arch.paging.shadow.total_pages, pages); @@ -1855,7 +1865,8 @@ /* Return the size of the shadow pool, rounded up to the nearest MB */ static unsigned int shadow_get_allocation(struct domain *d) { - unsigned int pg = d->arch.paging.shadow.total_pages; + unsigned int pg = d->arch.paging.shadow.total_pages + + d->arch.paging.shadow.p2m_pages; return ((pg >> (20 - PAGE_SHIFT)) + ((pg & ((1 << (20 - PAGE_SHIFT)) - 1)) ? 1 : 0)); }