Skip to contentSkip to conversation

NUMA support for ARM.

RFC PATCH New Steve Capper 2 participants 6 messages Dec 12, 2012 – Dec 13, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

cover NUMA support for ARM.

Hello,

This RFC adds support for NUMA.

Where possible NUMA should be run with a sparse memory model. If a sparse memory model is not available; one can use the supplied discontiguous memory model.

At the moment, the number of nodes has to be specified on the commandline. One can also, optionally, specify the memory size of each node. (Otherwise the memory range is split roughly equally between nodes).

CPUs can be striped across nodes (cpu number modulo the number of nodes), or assigned to a node based on their topology_physical_package_id. So for instance on a TC2, the A7 cores can be grouped together in one node and the A15s grouped together in another node.

I've kept the code as minimal as possible to allow future NUMA systems to be supported with a minimum of hacking.

These patches have been tested on a Realview PBX (for sparsemem), a Versatile Express with TC2 tile (running both non-LPAE and LPAE with discontiguous memory) and an Arndale board (Exynos 5250, running sparse memory with LPAE and non-LPAE).

Any comments or feedback would be appreciated greatly.

Thanks,

Signature · 22 lines
Steve

Steve Capper (3):
  ARM: mm: Add discontiguous memory support.
  ARM: mm: Add NUMA support.
  ARM: syscall: wire up sys_migrate_pages.

 arch/arm/Kconfig                   |   41 ++++++
 arch/arm/include/asm/mmzone.h      |   49 +++++++
 arch/arm/include/asm/topology.h    |   15 ++
 arch/arm/include/uapi/asm/unistd.h |    1 +
 arch/arm/kernel/calls.S            |    1 +
 arch/arm/kernel/setup.c            |    6 +
 arch/arm/mm/Makefile               |    2 +
 arch/arm/mm/init.c                 |   62 +++-----
 arch/arm/mm/numa.c                 |  278 ++++++++++++++++++++++++++++++++++++
 9 files changed, 416 insertions(+), 39 deletions(-)
 create mode 100644 arch/arm/include/asm/mmzone.h
 create mode 100644 arch/arm/mm/numa.c

-- 
1.7.9.5
#1 lore raw

RFC PATCH 1/3 ARM: mm: Add discontiguous memory support.

This patch adds support for discontiguous memory, with a view to each discontiguous block being assigned to a NUMA node (in a future patch).

Discontiguous memory should only be used to back NUMA on systems where sparse memory is not available.

---
 arch/arm/Kconfig              |   15 +++++++++++++
 arch/arm/include/asm/mmzone.h |   37 ++++++++++++++++++++++++++++++
 arch/arm/mm/Makefile          |    2 ++
 arch/arm/mm/init.c            |    9 ++++++++
 arch/arm/mm/numa.c            |   50 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 113 insertions(+)
 create mode 100644 arch/arm/include/asm/mmzone.h
 create mode 100644 arch/arm/mm/numa.c
arch/arm/Kconfig +15 -0
index 9759fec..9846d89 100644
@@ -1159,8 +1159,23 @@ config ARM_TIMER_SP804
 	select CLKSRC_MMIO
 	select HAVE_SCHED_CLOCK
 
+config ARCH_FLATMEM_ENABLE
+	bool
+	depends on MMU
+	default y
+
+config ARCH_DISCONTIGMEM_ENABLE
+	bool
+	depends on MMU
+	default y
+
 source arch/arm/mm/Kconfig
 
+config NUMA_ALLOC_NODES
+	bool
+	depends on DISCONTIGMEM
+	default y
+
 config ARM_NR_BANKS
 	int
 	default 16 if ARCH_EP93XX
arch/arm/include/asm/mmzone.h new file +37 -0
new file mode 100644
index 0000000..f6d7337
@@ -0,0 +1,37 @@
+/*
+ * Discontiguous memory and NUMA support, based on the PowerPC implementation.
+ *
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __ASM_ARM_MMZONE_H_
+#define __ASM_ARM_MMZONE_H_
+#ifdef __KERNEL__
+
+#include <linux/cpumask.h>
+
+#ifdef CONFIG_NUMA_ALLOC_NODES
+#define NODE_DATA(nid)		(node_data[nid])
+extern void __init arm_numa_alloc_nodes(unsigned long max_low);
+extern struct pglist_data *node_data[];
+#else
+#define arm_numa_alloc_nodes(_mlow)	do {} while (0)
+#endif
+
+#define	pfn_to_nid(pfn)		(0)
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_ARM_MMZONE_H_ */
arch/arm/mm/Makefile +2 -0
index 8a9c4cb..57a7055 100644
@@ -96,3 +96,5 @@ obj-$(CONFIG_CACHE_FEROCEON_L2)	+= cache-feroceon-l2.o
 obj-$(CONFIG_CACHE_L2X0)	+= cache-l2x0.o
 obj-$(CONFIG_CACHE_XSC3L2)	+= cache-xsc3l2.o
 obj-$(CONFIG_CACHE_TAUROS2)	+= cache-tauros2.o
+
+obj-$(CONFIG_NUMA_ALLOC_NODES)	+= numa.o
arch/arm/mm/init.c +9 -0
index abe4eae..98488ee 100644
@@ -33,6 +33,7 @@
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
+#include <asm/mmzone.h>
 
 #include "mm.h"
 
@@ -178,6 +179,12 @@ static void __init arm_bootmem_init(unsigned long start_pfn,
 	pg_data_t *pgdat;
 
 	/*
+	 * If we have NUMA or discontiguous memory, allocate the required
+	 * nodes by reserving memblocks.
+	 */
+	arm_numa_alloc_nodes(end_pfn);
+
+	/*
 	 * Allocate the bootmem bitmap page.  This must be in a region
 	 * of memory which has already been mapped.
 	 */
@@ -620,7 +627,9 @@ void __init mem_init(void)
 	extern u32 itcm_end;
 #endif
 
+#ifdef CONFIG_FLATMEM
 	max_mapnr   = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
+#endif
 
 	/* this will put all unused low memory onto the freelists */
 	free_unused_memmap(&meminfo);
arch/arm/mm/numa.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

RFC PATCH 1/3 ARM: mm: Add discontiguous memory support.

Quoted 6 lines · Steve Capper

This patch adds support for discontiguous memory, with a view to each discontiguous block being assigned to a NUMA node (in a future patch).

Discontiguous memory should only be used to back NUMA on systems where sparse memory is not available.

Err, we had this, and then we ripped it all out. Do we have any NUMA ARM systems? I don't think we do.

#3 lore raw

RFC PATCH 1/3 ARM: mm: Add discontiguous memory support.

Quoted 10 lines · Russell King - ARM Linux
Quoted 6 lines · Steve Capper

This patch adds support for discontiguous memory, with a view to each discontiguous block being assigned to a NUMA node (in a future patch).

Discontiguous memory should only be used to back NUMA on systems where sparse memory is not available.

Err, we had this, and then we ripped it all out. Do we have any NUMA ARM systems? I don't think we do.

Hi Russell,
There aren't any ARM NUMA systems out at the moment, but the Linux NUMA subsystem can be used to group cores that share an L2 cache together into the same node. This can then potentially reduce the L3 traffic required to run certain tasks, as the scheduler has a notion of memory topology that matches the cache topology. (An example platform where this can be beneficial is the TC2).

Best,

Signature · 1 line
Steve
#4 lore raw

RFC PATCH 2/3 ARM: mm: Add NUMA support.

In reply to Steve Capper

This patch adds support for NUMA (running on either discontiguous and sparse memory).

At the moment, the number of nodes has to be specified on the commandline. One can also, optionally, specify the memory size of each node. (Otherwise the memory range is split roughly equally between nodes).

CPUs can be striped across nodes (cpu number modulo the number of nodes), or assigned to a node based on their topology_physical_package_id. So for instance on a TC2, the A7 cores can be grouped together in one node and the A15s grouped together in another node.

---
 arch/arm/Kconfig                |   28 ++++-
 arch/arm/include/asm/mmzone.h   |   14 ++-
 arch/arm/include/asm/topology.h |   15 +++
 arch/arm/kernel/setup.c         |    6 ++
 arch/arm/mm/init.c              |   53 +++------
 arch/arm/mm/numa.c              |  228 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 303 insertions(+), 41 deletions(-)
arch/arm/Kconfig +27 -1
index 9846d89..739ea5d 100644
@@ -55,6 +55,7 @@ config ARM
 	select SYS_SUPPORTS_APM_EMULATION
 	select HAVE_MOD_ARCH_SPECIFIC if ARM_UNWIND
 	select MODULES_USE_ELF_REL
+	select HAVE_MEMBLOCK_NODE_MAP
 	help
 	  The ARM series is a line of low-power-consumption RISC chip designs
 	  licensed by ARM Ltd and targeted at embedded applications and
@@ -1171,9 +1172,34 @@ config ARCH_DISCONTIGMEM_ENABLE
 
 source arch/arm/mm/Kconfig
 
+config NUMA
+	bool "NUMA Support (EXPERIMENTAL)"
+	depends on MMU && !FLATMEM && EXPERIMENTAL
+	help
+	  Say Y to compile the kernel to support NUMA (Non-Uniform Memory
+	  Access). At the moment, one has to specify the number of nodes using
+	  the commandline:
+	  numa=fake=x,[size0],[size1],...,[sizeN-1],[usetopology]
+	  where x is the number of nodes, and sizeY is the size of node Y in
+	  bytes (one can suffix m or g for megabytes or gigabytes). If no sizes
+	  are specified, the memory is distributed roughly evenly between nodes.
+	  If "usetopology" is specified, the "topology_physical_package_id" is
+	  used to assign CPUs to nodes (so for instance on the TC2, the A7s are
+	  grouped together in one node and the A15s are grouped together in
+	  another node).
+
+config NODES_SHIFT
+	int "Maximum NUMA Nodes (as a power of 2)" if NUMA
+	range 1 10
+	default "1"
+	depends on NEED_MULTIPLE_NODES
+	---help---
+	  Specify the maximum number of NUMA Nodes available on the target
+	  system.  Increases memory reserved to accommodate various tables.
+
 config NUMA_ALLOC_NODES
 	bool
-	depends on DISCONTIGMEM
+	depends on DISCONTIGMEM || NUMA
 	default y
 
 config ARM_NR_BANKS
arch/arm/include/asm/mmzone.h +13 -1
index f6d7337..628e503 100644
@@ -31,7 +31,19 @@ extern struct pglist_data *node_data[];
 #define arm_numa_alloc_nodes(_mlow)	do {} while (0)
 #endif
 
-#define	pfn_to_nid(pfn)		(0)
+#ifdef CONFIG_NUMA
+extern cpumask_var_t *node_to_cpumask_map;
+extern int numa_cpu_lookup_table[];
+extern int pfn_to_nid(unsigned long pfn);
+extern void __init arm_setup_nodes(unsigned long min, unsigned long max_high);
+extern void __init arm_numa_alloc_cpumask(unsigned long max_low);
+#else
+#define	pfn_to_nid(pfn)			(0)
+#define arm_setup_nodes(min, max_high) memblock_set_node(		\
+					__pfn_to_phys(min), 		\
+					__pfn_to_phys(max_high - min), 0)
+#define arm_numa_alloc_cpumask(max_low)	do {} while (0)
+#endif /* CONFIG_NUMA */
 
 #endif /* __KERNEL__ */
 #endif /* __ASM_ARM_MMZONE_H_ */
arch/arm/include/asm/topology.h +15 -0
index 58b8b84..44cba52 100644
@@ -34,6 +34,21 @@ static inline void store_cpu_topology(unsigned int cpuid) { }
 
 #endif
 
+#ifdef CONFIG_NUMA
+
+static inline int cpu_to_node(int cpu)
+{
+	return numa_cpu_lookup_table[cpu];
+}
+
+#define cpumask_of_node(node) ((node) == -1 ?				\
+			       cpu_all_mask :				\
+			       node_to_cpumask_map[node])
+
+#define parent_node(node)	(node)
+
+#endif /* CONFIG_NUMA */
+
 #include <asm-generic/topology.h>
 
 #endif /* _ASM_ARM_TOPOLOGY_H */
arch/arm/kernel/setup.c +6 -0
index d15f1c5..b7e5772 100644
@@ -795,6 +795,12 @@ static int __init topology_init(void)
 {
 	int cpu;
 
+#ifdef CONFIG_NUMA
+	int node;
+	for_each_online_node(node)
+		register_one_node(node);
+#endif
+
 	for_each_possible_cpu(cpu) {
 		struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
 		cpuinfo->cpu.hotpluggable = 1;
arch/arm/mm/init.c +14 -39

70 lines not on this page · raw message

arch/arm/mm/numa.c +228 -0

241 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

RFC PATCH 3/3 ARM: syscall: wire up sys_migrate_pages.

In reply to Steve Capper

For NUMA support, the sys_migrate_pages syscall is required by userspace. This patch allocates #379 for this syscall and plumbs it in.

---
 arch/arm/include/uapi/asm/unistd.h |    1 +
 arch/arm/kernel/calls.S            |    1 +
 2 files changed, 2 insertions(+)
arch/arm/include/uapi/asm/unistd.h +1 -0
index ac03bdb..23e3d59 100644
@@ -405,6 +405,7 @@
 #define __NR_process_vm_readv		(__NR_SYSCALL_BASE+376)
 #define __NR_process_vm_writev		(__NR_SYSCALL_BASE+377)
 					/* 378 for kcmp */
+#define __NR_migrate_pages		(__NR_SYSCALL_BASE+379)
 
 /*
  * This may need to be greater than __NR_last_syscall+1 in order to
arch/arm/kernel/calls.S +1 -0
index 831cd38..a96af99 100644
@@ -388,6 +388,7 @@
 		CALL(sys_process_vm_readv)
 		CALL(sys_process_vm_writev)
 		CALL(sys_ni_syscall)	/* reserved for sys_kcmp */
+		CALL(sys_migrate_pages)
 #ifndef syscalls_counted
 .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
 #define syscalls_counted
Signature · 1 line
1.7.9.5