From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH] x86: adjust Dom0 initial memory allocation strategy Date: Mon, 15 Mar 2010 08:58:51 +0000 Message-ID: <4B9E04DB0200007800034CD8@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part93B948DB.0__=" Return-path: 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 This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part93B948DB.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Simply trying order-9 allocations until they won't succeed anymore may consume unnecessarily much memory from the DMA zone (since the page allocator will try to fulfill the request by using memory from that zone when only lower order memory blocks are left in all other zones). To avoid using DMA zone memory, make alloc_chunk() try to allocate a second smaller chunk and use that one in favor of the first one if it came from a higher addressed memory. This way, all memory outside the DMA zone will be consumed before eating into that zone. Signed-off-by: Jan Beulich --- 2010-03-09.orig/xen/arch/x86/domain_build.c 2010-03-12 12:25:18.0000000= 00 +0100 +++ 2010-03-09/xen/arch/x86/domain_build.c 2010-03-12 17:24:11.0000000= 00 +0100 @@ -127,7 +131,8 @@ static struct page_info * __init alloc_c struct domain *d, unsigned long max_pages) { struct page_info *page; - unsigned int order; + unsigned int order, free_order; + /* * Allocate up to 2MB at a time: It prevents allocating very large = chunks * from DMA pools before the >4GB pool is fully depleted. @@ -140,6 +145,26 @@ static struct page_info * __init alloc_c while ( (page =3D alloc_domheap_pages(d, order, 0)) =3D=3D NULL ) if ( order-- =3D=3D 0 ) break; + /* + * Make a reasonable attempt at finding a smaller chunk at a higher + * address, to avoid allocating from low memory as much as possible. + */ + for ( free_order =3D order; page && order--; ) + { + struct page_info *pg2; + + if ( d->tot_pages + (1 << order) > d->max_pages ) + continue; + pg2 =3D alloc_domheap_pages(d, order, 0); + if ( pg2 > page ) + { + free_domheap_pages(page, free_order); + page =3D pg2; + free_order =3D order; + } + else if ( pg2 ) + free_domheap_pages(pg2, order); + } return page; } =20 --=__Part93B948DB.0__= Content-Type: text/plain; name="x86-dom0-alloc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-dom0-alloc.patch" Simply trying order-9 allocations until they won't succeed anymore=0Amay = consume unnecessarily much memory from the DMA zone (since the=0Apage = allocator will try to fulfill the request by using memory from=0Athat zone = when only lower order memory blocks are left in all other=0Azones). To = avoid using DMA zone memory, make alloc_chunk() try to=0Aallocate a second = smaller chunk and use that one in favor of the=0Afirst one if it came from = a higher addressed memory. This way, all=0Amemory outside the DMA zone = will be consumed before eating into that=0Azone.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- 2010-03-09.orig/xen/arch/x86/domain_= build.c 2010-03-12 12:25:18.000000000 +0100=0A+++ 2010-03-09/xen/arch/x86/d= omain_build.c 2010-03-12 17:24:11.000000000 +0100=0A@@ -127,7 +131,8 @@ = static struct page_info * __init alloc_c=0A struct domain *d, unsigned = long max_pages)=0A {=0A struct page_info *page;=0A- unsigned int = order;=0A+ unsigned int order, free_order;=0A+=0A /*=0A * = Allocate up to 2MB at a time: It prevents allocating very large chunks=0A = * from DMA pools before the >4GB pool is fully depleted.=0A@@ -140,6 = +145,26 @@ static struct page_info * __init alloc_c=0A while ( (page = =3D alloc_domheap_pages(d, order, 0)) =3D=3D NULL )=0A if ( = order-- =3D=3D 0 )=0A break;=0A+ /*=0A+ * Make a = reasonable attempt at finding a smaller chunk at a higher=0A+ * = address, to avoid allocating from low memory as much as possible.=0A+ = */=0A+ for ( free_order =3D order; page && order--; )=0A+ {=0A+ = struct page_info *pg2;=0A+=0A+ if ( d->tot_pages + (1 << order) > = d->max_pages )=0A+ continue;=0A+ pg2 =3D alloc_domheap_pa= ges(d, order, 0);=0A+ if ( pg2 > page )=0A+ {=0A+ = free_domheap_pages(page, free_order);=0A+ page =3D pg2;=0A+ = free_order =3D order;=0A+ }=0A+ else if ( pg2 )=0A+ = free_domheap_pages(pg2, order);=0A+ }=0A return page;=0A = }=0A =0A --=__Part93B948DB.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part93B948DB.0__=--