From: "Jan Beulich" Subject: [PATCH] x86: fix Dom0 booting time regression Date: Tue, 04 May 2010 10:05:21 +0100 Message-ID: <4BDFFF71020000780000118A@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5E74C741.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. --=__Part5E74C741.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Unfortunately the changes in c/s 21035 caused boot time to go up significantly on certain large systems. To rectify this without going back to the old behavior, introduce a new memory allocation flag so that Dom0 allocations can exhaust non-DMA memory before starting to consume DMA memory. For the latter, the behavior introduced in aforementioned c/s gets retained, while for the former we can now even try larger chunks first. This builds on the fact that alloc_chunk() gets called with non- increasing 'max_pages' arguments, end hence it can store locally the allocation order last used (as larger order allocations can't succeed during subsequent invocations if they failed once). Signed-off-by: Jan Beulich --- 2010-04-30.orig/xen/arch/x86/domain_build.c 2010-05-04 10:30:34.0000000= 00 +0200 +++ 2010-04-30/xen/arch/x86/domain_build.c 2010-05-04 10:31:32.0000000= 00 +0200 @@ -126,26 +126,36 @@ string_param("dom0_ioports_disable", opt static struct page_info * __init alloc_chunk( struct domain *d, unsigned long max_pages) { + static unsigned int __initdata last_order =3D MAX_ORDER; + static unsigned int __initdata memflags =3D MEMF_no_dma; struct page_info *page; - unsigned int order, free_order; + unsigned int order =3D get_order_from_pages(max_pages), free_order; =20 - /* - * Allocate up to 2MB at a time: It prevents allocating very large = chunks - * from DMA pools before the >4GB pool is fully depleted. - */ - if ( max_pages > (2UL << (20 - PAGE_SHIFT)) ) - max_pages =3D 2UL << (20 - PAGE_SHIFT); - order =3D get_order_from_pages(max_pages); - if ( (max_pages & (max_pages-1)) !=3D 0 ) - order--; - while ( (page =3D alloc_domheap_pages(d, order, 0)) =3D=3D NULL ) + if ( order > last_order ) + order =3D last_order; + else if ( max_pages & (max_pages - 1) ) + --order; + while ( (page =3D alloc_domheap_pages(d, order, memflags)) =3D=3D = NULL ) if ( order-- =3D=3D 0 ) break; + if ( page ) + last_order =3D order; + else if ( memflags ) + { + /* + * Allocate up to 2MB at a time: It prevents allocating very = large + * chunks from DMA pools before the >4GB pool is fully depleted. + */ + last_order =3D 21 - PAGE_SHIFT; + memflags =3D 0; + return alloc_chunk(d, max_pages); + } + /* * 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--; ) + for ( free_order =3D order; !memflags && page && order--; ) { struct page_info *pg2; =20 --- 2010-04-30.orig/xen/common/page_alloc.c 2010-05-04 10:30:34.0000000= 00 +0200 +++ 2010-04-30/xen/common/page_alloc.c 2010-04-26 14:40:53.000000000 = +0200 @@ -1157,8 +1157,9 @@ struct page_info *alloc_domheap_pages( pg =3D alloc_heap_pages(dma_zone + 1, zone_hi, node, order, = memflags); =20 if ( (pg =3D=3D NULL) && - ((pg =3D alloc_heap_pages(MEMZONE_XEN + 1, zone_hi, - node, order, memflags)) =3D=3D NULL) ) + ((memflags & MEMF_no_dma) || + ((pg =3D alloc_heap_pages(MEMZONE_XEN + 1, zone_hi, + node, order, memflags)) =3D=3D NULL)) ) return NULL; =20 if ( (d !=3D NULL) && assign_pages(d, pg, order, memflags) ) --- 2010-04-30.orig/xen/include/xen/mm.h 2010-05-04 10:30:34.0000000= 00 +0200 +++ 2010-04-30/xen/include/xen/mm.h 2010-04-26 17:46:32.000000000 = +0200 @@ -79,6 +79,8 @@ int assign_pages( #define MEMF_populate_on_demand (1U<<_MEMF_populate_on_demand) #define _MEMF_tmem 2 #define MEMF_tmem (1U<<_MEMF_tmem) +#define _MEMF_no_dma 3 +#define MEMF_no_dma (1U<<_MEMF_no_dma) #define _MEMF_node 8 #define MEMF_node(n) ((((n)+1)&0xff)<<_MEMF_node) #define _MEMF_bits 24 --=__Part5E74C741.0__= Content-Type: text/plain; name="x86-dom0-alloc-performance.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-dom0-alloc-performance.patch" Unfortunately the changes in c/s 21035 caused boot time to go up=0Asignific= antly on certain large systems. To rectify this without going=0Aback to = the old behavior, introduce a new memory allocation flag so=0Athat Dom0 = allocations can exhaust non-DMA memory before starting to=0Aconsume DMA = memory. For the latter, the behavior introduced in=0Aaforementioned c/s = gets retained, while for the former we can now even=0Atry larger chunks = first.=0A=0AThis builds on the fact that alloc_chunk() gets called with = non-=0Aincreasing 'max_pages' arguments, end hence it can store locally = the=0Aallocation order last used (as larger order allocations can't = succeed=0Aduring subsequent invocations if they failed once).=0A=0ASigned-o= ff-by: Jan Beulich =0A=0A--- 2010-04-30.orig/xen/arch/= x86/domain_build.c 2010-05-04 10:30:34.000000000 +0200=0A+++ = 2010-04-30/xen/arch/x86/domain_build.c 2010-05-04 10:31:32.000000000 = +0200=0A@@ -126,26 +126,36 @@ string_param("dom0_ioports_disable", opt=0A = static struct page_info * __init alloc_chunk(=0A struct domain *d, = unsigned long max_pages)=0A {=0A+ static unsigned int __initdata = last_order =3D MAX_ORDER;=0A+ static unsigned int __initdata memflags = =3D MEMF_no_dma;=0A struct page_info *page;=0A- unsigned int order, = free_order;=0A+ unsigned int order =3D get_order_from_pages(max_pages), = 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- */=0A- if ( max_pages > (2UL << = (20 - PAGE_SHIFT)) )=0A- max_pages =3D 2UL << (20 - PAGE_SHIFT);=0A-= order =3D get_order_from_pages(max_pages);=0A- if ( (max_pages & = (max_pages-1)) !=3D 0 )=0A- order--;=0A- while ( (page =3D = alloc_domheap_pages(d, order, 0)) =3D=3D NULL )=0A+ if ( order > = last_order )=0A+ order =3D last_order;=0A+ else if ( max_pages & = (max_pages - 1) )=0A+ --order;=0A+ while ( (page =3D alloc_domhea= p_pages(d, order, memflags)) =3D=3D NULL )=0A if ( order-- =3D=3D = 0 )=0A break;=0A+ if ( page )=0A+ last_order =3D = order;=0A+ else if ( memflags )=0A+ {=0A+ /*=0A+ * = Allocate up to 2MB at a time: It prevents allocating very large=0A+ = * chunks from DMA pools before the >4GB pool is fully depleted.=0A+ = */=0A+ last_order =3D 21 - PAGE_SHIFT;=0A+ memflags =3D = 0;=0A+ return alloc_chunk(d, max_pages);=0A+ }=0A+=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+ for ( = free_order =3D order; !memflags && page && order--; )=0A {=0A = struct page_info *pg2;=0A =0A--- 2010-04-30.orig/xen/common/page_alloc.c = 2010-05-04 10:30:34.000000000 +0200=0A+++ 2010-04-30/xen/common/page_alloc.= c 2010-04-26 14:40:53.000000000 +0200=0A@@ -1157,8 +1157,9 @@ struct = page_info *alloc_domheap_pages(=0A pg =3D alloc_heap_pages(dma_zone= + 1, zone_hi, node, order, memflags);=0A =0A if ( (pg =3D=3D NULL) = &&=0A- ((pg =3D alloc_heap_pages(MEMZONE_XEN + 1, zone_hi,=0A- = node, order, memflags)) =3D=3D NULL) )=0A+ = ((memflags & MEMF_no_dma) ||=0A+ ((pg =3D alloc_heap_pages(MEM= ZONE_XEN + 1, zone_hi,=0A+ node, order, = memflags)) =3D=3D NULL)) )=0A return NULL;=0A =0A if ( (d = !=3D NULL) && assign_pages(d, pg, order, memflags) )=0A--- 2010-04-30.orig/= xen/include/xen/mm.h 2010-05-04 10:30:34.000000000 +0200=0A+++ = 2010-04-30/xen/include/xen/mm.h 2010-04-26 17:46:32.000000000 +0200=0A@@ = -79,6 +79,8 @@ int assign_pages(=0A #define MEMF_populate_on_demand = (1U<<_MEMF_populate_on_demand)=0A #define _MEMF_tmem 2=0A #define = MEMF_tmem (1U<<_MEMF_tmem)=0A+#define _MEMF_no_dma 3=0A+#define= MEMF_no_dma (1U<<_MEMF_no_dma)=0A #define _MEMF_node 8=0A = #define MEMF_node(n) ((((n)+1)&0xff)<<_MEMF_node)=0A #define = _MEMF_bits 24=0A --=__Part5E74C741.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 --=__Part5E74C741.0__=--