From: "Jan Beulich" Subject: [PATCH v2 1/2] page-alloc/x86: don't restrict DMA heap to node 0 Date: Thu, 11 Aug 2016 04:44:42 -0600 Message-ID: <57AC733A0200007800104FD1@prv-mh.provo.novell.com> References: <57AB0D5C020000780010493B@prv-mh.provo.novell.com> <57AB0EAE020000780010494F@prv-mh.provo.novell.com> <57AB1C3302000078001049EB@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartCEF8380A.4__=" Return-path: Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bXnTj-0005Ji-3W for xen-devel@lists.xenproject.org; Thu, 11 Aug 2016 10:44:47 +0000 In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , IanJackson , Tim Deegan , Julien Grall 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. --=__PartCEF8380A.4__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When node zero has no memory, the DMA bit width will end up getting set to 9, which is obviously not helpful to hold back a reasonable amount of low enough memory for Dom0 to use for DMA purposes. Find the lowest node with memory below 4Gb instead. Introduce arch_get_dma_bitsize() to keep this arch-specific logic out of common code. Also adjust the original calculation: I think the subtraction of 1 should have been part of the flsl() argument rather than getting applied to its result. And while previously the division by 4 was valid to be done on the flsl() result, this now also needs to be converted, as is should only be applied to the spanned pages value. Signed-off-by: Jan Beulich Acked-by: Julien Grall --- v2: Extend commit message to reason about the calculation change. Add a comment to the calculation. --- a/xen/arch/x86/numa.c +++ b/xen/arch/x86/numa.c @@ -355,11 +355,25 @@ void __init init_cpu_to_node(void) } } =20 -EXPORT_SYMBOL(cpu_to_node); -EXPORT_SYMBOL(node_to_cpumask); -EXPORT_SYMBOL(memnode_shift); -EXPORT_SYMBOL(memnodemap); -EXPORT_SYMBOL(node_data); +unsigned int __init arch_get_dma_bitsize(void) +{ + unsigned int node; + + for_each_online_node(node) + if ( node_spanned_pages(node) && + !(node_start_pfn(node) >> (32 - PAGE_SHIFT)) ) + break; + if ( node >=3D MAX_NUMNODES ) + panic("No node with memory below 4Gb"); + + /* + * Try to not reserve the whole node's memory for DMA, but dividing + * its spanned pages by (arbitrarily chosen) 4. + */ + return min_t(unsigned int, + flsl(node_start_pfn(node) + node_spanned_pages(node) / 4 = - 1) + + PAGE_SHIFT, 32); +} =20 static void dump_numa(unsigned char key) { --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1368,16 +1368,7 @@ void __init end_boot_allocator(void) init_heap_pages(virt_to_page(bootmem_region_list), 1); =20 if ( !dma_bitsize && (num_online_nodes() > 1) ) - { -#ifdef CONFIG_X86 - dma_bitsize =3D min_t(unsigned int, - flsl(NODE_DATA(0)->node_spanned_pages) - 1 - + PAGE_SHIFT - 2, - 32); -#else - dma_bitsize =3D 32; -#endif - } + dma_bitsize =3D arch_get_dma_bitsize(); =20 printk("Domain heap initialised"); if ( dma_bitsize ) --- a/xen/include/asm-arm/numa.h +++ b/xen/include/asm-arm/numa.h @@ -17,6 +17,11 @@ static inline __attribute__((pure)) node #define node_start_pfn(nid) (pdx_to_pfn(frametable_base_pdx)) #define __node_distance(a, b) (20) =20 +static inline unsigned int arch_get_dma_bitsize(void) +{ + return 32; +} + #endif /* __ARCH_ARM_NUMA_H */ /* * Local variables: --- a/xen/include/asm-x86/numa.h +++ b/xen/include/asm-x86/numa.h @@ -86,5 +86,6 @@ extern int valid_numa_range(u64 start, u =20 void srat_parse_regions(u64 addr); extern u8 __node_distance(nodeid_t a, nodeid_t b); +unsigned int arch_get_dma_bitsize(void); =20 #endif --=__PartCEF8380A.4__= Content-Type: text/plain; name="DMA-heap-fallback.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="DMA-heap-fallback.patch" page-alloc/x86: don't restrict DMA heap to node 0=0A=0AWhen node zero has = no memory, the DMA bit width will end up getting set=0Ato 9, which is = obviously not helpful to hold back a reasonable amount=0Aof low enough = memory for Dom0 to use for DMA purposes. Find the lowest=0Anode with = memory below 4Gb instead.=0A=0AIntroduce arch_get_dma_bitsize() to keep = this arch-specific logic out=0Aof common code.=0A=0AAlso adjust the = original calculation: I think the subtraction of 1=0Ashould have been part = of the flsl() argument rather than getting=0Aapplied to its result. And = while previously the division by 4 was valid=0Ato be done on the flsl() = result, this now also needs to be converted,=0Aas is should only be = applied to the spanned pages value.=0A=0ASigned-off-by: Jan Beulich = =0AAcked-by: Julien Grall =0A---= =0Av2: Extend commit message to reason about the calculation change. = Add=0A a comment to the calculation.=0A=0A--- a/xen/arch/x86/numa.c=0A++= + b/xen/arch/x86/numa.c=0A@@ -355,11 +355,25 @@ void __init init_cpu_to_nod= e(void)=0A }=0A }=0A =0A-EXPORT_SYMBOL(cpu_to_node);=0A-EXPORT_SYMBOL(n= ode_to_cpumask);=0A-EXPORT_SYMBOL(memnode_shift);=0A-EXPORT_SYMBOL(memnodem= ap);=0A-EXPORT_SYMBOL(node_data);=0A+unsigned int __init arch_get_dma_bitsi= ze(void)=0A+{=0A+ unsigned int node;=0A+=0A+ for_each_online_node(nod= e)=0A+ if ( node_spanned_pages(node) &&=0A+ !(node_start= _pfn(node) >> (32 - PAGE_SHIFT)) )=0A+ break;=0A+ if ( node = >=3D MAX_NUMNODES )=0A+ panic("No node with memory below 4Gb");=0A+= =0A+ /*=0A+ * Try to not reserve the whole node's memory for DMA, = but dividing=0A+ * its spanned pages by (arbitrarily chosen) 4.=0A+ = */=0A+ return min_t(unsigned int,=0A+ flsl(node_start_p= fn(node) + node_spanned_pages(node) / 4 - 1)=0A+ + = PAGE_SHIFT, 32);=0A+}=0A =0A static void dump_numa(unsigned char key)=0A = {=0A--- a/xen/common/page_alloc.c=0A+++ b/xen/common/page_alloc.c=0A@@ = -1368,16 +1368,7 @@ void __init end_boot_allocator(void)=0A init_heap_p= ages(virt_to_page(bootmem_region_list), 1);=0A =0A if ( !dma_bitsize = && (num_online_nodes() > 1) )=0A- {=0A-#ifdef CONFIG_X86=0A- = dma_bitsize =3D min_t(unsigned int,=0A- = flsl(NODE_DATA(0)->node_spanned_pages) - 1=0A- = + PAGE_SHIFT - 2,=0A- 32);=0A-#else=0A- = dma_bitsize =3D 32;=0A-#endif=0A- }=0A+ dma_bitsize =3D = arch_get_dma_bitsize();=0A =0A printk("Domain heap initialised");=0A = if ( dma_bitsize )=0A--- a/xen/include/asm-arm/numa.h=0A+++ b/xen/include= /asm-arm/numa.h=0A@@ -17,6 +17,11 @@ static inline __attribute__((pure)) = node=0A #define node_start_pfn(nid) (pdx_to_pfn(frametable_base_pdx))=0A = #define __node_distance(a, b) (20)=0A =0A+static inline unsigned int = arch_get_dma_bitsize(void)=0A+{=0A+ return 32;=0A+}=0A+=0A #endif /* = __ARCH_ARM_NUMA_H */=0A /*=0A * Local variables:=0A--- a/xen/include/asm-x= 86/numa.h=0A+++ b/xen/include/asm-x86/numa.h=0A@@ -86,5 +86,6 @@ extern = int valid_numa_range(u64 start, u=0A =0A void srat_parse_regions(u64 = addr);=0A extern u8 __node_distance(nodeid_t a, nodeid_t b);=0A+unsigned = int arch_get_dma_bitsize(void);=0A =0A #endif=0A --=__PartCEF8380A.4__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__PartCEF8380A.4__=--