Skip to contentSkip to conversation

sparc64: Use node local allocations for IRQ stacks.

PATCH In review David Miller 2 participants 8 messages Apr 27, 2012

Subsystems (2)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 1/1 sparc64: Use node local allocations for IRQ stacks.

---

Committed to sparc-next

 arch/sparc/mm/init_64.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
arch/sparc/mm/init_64.c +14 -9
index 5b84559..def9223 100644
@@ -1748,22 +1748,27 @@ void __init paging_init(void)
 #endif
 	}
 
+	/* Setup bootmem... */
+	last_valid_pfn = end_pfn = bootmem_init(phys_base);
+
+#ifndef CONFIG_NEED_MULTIPLE_NODES
+	max_mapnr = last_valid_pfn;
+#endif
 	/* Once the OF device tree and MDESC have been setup, we know
 	 * the list of possible cpus.  Therefore we can allocate the
 	 * IRQ stacks.
 	 */
 	for_each_possible_cpu(i) {
-		/* XXX Use node local allocations... XXX */
-		softirq_stack[i] = __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
-		hardirq_stack[i] = __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
-	}
+		int node = cpu_to_node(i);
 
-	/* Setup bootmem... */
-	last_valid_pfn = end_pfn = bootmem_init(phys_base);
+		softirq_stack[i] = __alloc_bootmem_node(NODE_DATA(node),
+							THREAD_SIZE,
+							THREAD_SIZE, 0);
+		hardirq_stack[i] = __alloc_bootmem_node(NODE_DATA(node),
+							THREAD_SIZE,
+							THREAD_SIZE, 0);
+	}
 
-#ifndef CONFIG_NEED_MULTIPLE_NODES
-	max_mapnr = last_valid_pfn;
-#endif
 	kernel_physical_mapping_init();
 
 	{
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 6 lines
arch/sparc/mm/init_64.c +0 -0
index 5b84559..def9223 100644
@@ -1748,22 +1748,27 @@ void __init paging_init(void)
 #endif

arch/sparc/mm/init_64.c void __init paging_init(void) · line 1758

Quoted 10 lines
arch/sparc/mm/init_64.c +6 -0
 	}
 
+	/* Setup bootmem... */
+	last_valid_pfn = end_pfn = bootmem_init(phys_base);
+
 
 
+#ifndef CONFIG_NEED_MULTIPLE_NODES
+	max_mapnr = last_valid_pfn;
+#endif

This assignment looks redundant. I cannot see any uses of max_mapnr in the kernel (which is relevant for sparc64).

I am perfectly aware that this was not introduced by your patch, but I looked at it anyway.

Quoted 6 lines
arch/sparc/mm/init_64.c +0 -1
 	/* Once the OF device tree and MDESC have been setup, we know
 	 * the list of possible cpus.  Therefore we can allocate the
 	 * IRQ stacks.
 	 */
 	for_each_possible_cpu(i) {
-		/* XXX Use node local allocations... XXX */

arch/sparc/mm/init_64.c void __init paging_init(void) · line 1766

Quoted 10 lines
arch/sparc/mm/init_64.c +4 -5
-		softirq_stack[i] = __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
-		hardirq_stack[i] = __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
-	}
+		int node = cpu_to_node(i);
 
-	/* Setup bootmem... */
-	last_valid_pfn = end_pfn = bootmem_init(phys_base);
+		softirq_stack[i] = __alloc_bootmem_node(NODE_DATA(node),
+							THREAD_SIZE,
+							THREAD_SIZE, 0);

Knowing that sparc64 just got converted to NO_BOOTMEM it hurts my eyes to see memblock_alloc() be replaced by __alloc_bootmem_node().

It looks like memblock_alloc_try_nid() could be used.
It will try nid and revert back to all nodes if it fails to allocate memory on nid.

But you would then have to memset the memory manually and convert to __va() too.

Sam

author maintainer
#2 lore raw
In reply to David Miller

From: Sam Ravnborg <[email protected]>
Date: Fri, 27 Apr 2012 19:27:50 +0200

Quoted 2 lines

This assignment looks redundant. I cannot see any uses of max_mapnr in the kernel (which is relevant for sparc64).

pfn_valid() via asm-generic/page.h

Quoted 3 lines

Knowing that sparc64 just got converted to NO_BOOTMEM it hurts my eyes to see memblock_alloc() be replaced by __alloc_bootmem_node().

Since the stack allocations happen now (for the sake of setting up the NUMA mappings) after bootmem init, it's prudent to use the alloc_bootmem interfaces.

Not only visually, but syntactically as it provides:

1) fallbacks to non-NUMA allocations when NUMA node specific allocations fail.

2) a virtual pointer to zero'd memory so we don't need that __va() and memset crap

author maintainer
#3 lore raw
In reply to David Miller

From: David Miller <[email protected]>
Date: Fri, 27 Apr 2012 13:34:07 -0400 (EDT)

Quoted 7 lines

From: Sam Ravnborg <[email protected]>
Date: Fri, 27 Apr 2012 19:27:50 +0200

Quoted 2 lines

This assignment looks redundant. I cannot see any uses of max_mapnr in the kernel (which is relevant for sparc64).

pfn_valid() via asm-generic/page.h

Actually this isn't right. We don't use asm-generic/page.h on sparc64.

We get the pfn_valid() definition instead from linux/mmzone.h which doesn't make use of max_mapnr.

So yes we can remove this assignment and I will do so in the sparc-next tree, thanks!

#4 lore raw
In reply to David Miller
Quoted 7 lines · David Miller

From: Sam Ravnborg <[email protected]>
Date: Fri, 27 Apr 2012 19:27:50 +0200

Quoted 2 lines

This assignment looks redundant. I cannot see any uses of max_mapnr in the kernel (which is relevant for sparc64).

pfn_valid() via asm-generic/page.h

asm-generic/page.h is for non-MMU architectures.
It includes:
#ifdef CONFIG_MMU
#error need to prove a real asm/page.h
#endif

Quoted 8 lines
Quoted 4 lines

Knowing that sparc64 just got converted to NO_BOOTMEM it hurts my eyes to see memblock_alloc() be replaced by __alloc_bootmem_node().

Since the stack allocations happen now (for the sake of setting up the NUMA mappings) after bootmem init, it's prudent to use the alloc_bootmem interfaces.

It was my understanding that everything provided by mm/nobootmem.c is wrappers provided for backward compatibility with the old bootmem based early allocator.
And that we later would make this file optional when.

But I seems to be wrong here.

Sam

author maintainer
#5 lore raw
In reply to David Miller

From: Sam Ravnborg <[email protected]>
Date: Fri, 27 Apr 2012 19:58:16 +0200

Quoted 9 lines · David Miller
Quoted 7 lines
Quoted 3 lines

Knowing that sparc64 just got converted to NO_BOOTMEM it hurts my eyes to see memblock_alloc() be replaced by __alloc_bootmem_node().

Since the stack allocations happen now (for the sake of setting up the NUMA mappings) after bootmem init, it's prudent to use the alloc_bootmem interfaces.

Quoted 6 lines

It was my understanding that everything provided by mm/nobootmem.c is wrappers provided for backward compatibility with the old bootmem based early allocator.
And that we later would make this file optional when.

But I seems to be wrong here.

Once the memblock functions provide NUMA node fallbacks and __va()/memset wrappers, we can certainly use memblock directly :-)

#6 lore raw
In reply to David Miller
Quoted 17 lines · David Miller

From: Sam Ravnborg <[email protected]>
Date: Fri, 27 Apr 2012 19:58:16 +0200

Quoted 14 lines · David Miller
Quoted 7 lines
Quoted 3 lines

Knowing that sparc64 just got converted to NO_BOOTMEM it hurts my eyes to see memblock_alloc() be replaced by __alloc_bootmem_node().

Since the stack allocations happen now (for the sake of setting up the NUMA mappings) after bootmem init, it's prudent to use the alloc_bootmem interfaces.

It was my understanding that everything provided by mm/nobootmem.c is wrappers provided for backward compatibility with the old bootmem based early allocator.
And that we later would make this file optional when.

Quoted 4 lines
Quoted 1 line

But I seems to be wrong here.

Once the memblock functions provide NUMA node fallbacks and __va()/memset wrappers, we can certainly use memblock directly :-)

If I read the memblock code correct something like this should do it. Only as a principal idea - I may revist this another time.

Sam

include/linux/memblock.h +33 -0
index a6bb102..3e8d102 100644
@@ -148,6 +148,39 @@ phys_addr_t memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid)
 
 phys_addr_t memblock_alloc(phys_addr_t size, phys_addr_t align);
 
+static inline void * memblock_boot_alloc_nid(phys_addr_t size,
+					     phys_addr_t align, int nid)
+{
+	phys_addr_t addr;
+	void * ptr;
+
+	addr = memblock_boot_alloc_nid(size, align, nid);
+	if (addr = 0)
+		return NULL;
+
+	void * ptr = __va(addr);
+	memset(ptr, 0, size);
+	return ptr;
+}
+
+static inline void * memblock_boot_alloc_try_nid(phys_addr_t size,
+						 phys_addr_t align, int nid)
+{
+	phys_addr_t addr;
+	void * ptr;
+
+	addr = memblock_boot_alloc_try_nid(size, align, nid);
+	if (addr = 0)
+		return NULL;
+
+	ptr = __va(addr);
+	memset(ptr, 0, size);
+	return ptr;
+}
+
+void * memblock_boot_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid);
+void * memblock_boot_alloc(phys_addr_t size, phys_addr_t align);
+
 /* Flags for memblock_alloc_base() amd __memblock_alloc_base() */
 #define MEMBLOCK_ALLOC_ANYWHERE	(~(phys_addr_t)0)
 #define MEMBLOCK_ALLOC_ACCESSIBLE	0
Quoted 1 line
author maintainer
#7 lore raw
In reply to David Miller

From: Sam Ravnborg <[email protected]>
Date: Fri, 27 Apr 2012 20:29:35 +0200

Quoted 2 lines

If I read the memblock code correct something like this should do it. Only as a principal idea - I may revist this another time.

The interface wrappers you come up with have to cope with all of the generic bootmem calls we have in the tree. And therefore you'll need to provide limit, goal, and associated fallbacks.

Oh look, the alloc_bootmem wrappers already provide this and allow us to not have to edit all the call sites at all.

So it seems quite useless if you ask me. :-)