2 * NUMA support for s390
4 * Implement NUMA core code.
6 * Copyright IBM Corp. 2015
9 #define KMSG_COMPONENT "numa"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kernel.h>
13 #include <linux/mmzone.h>
14 #include <linux/cpumask.h>
15 #include <linux/bootmem.h>
16 #include <linux/memblock.h>
17 #include <linux/slab.h>
18 #include <linux/node.h>
21 #include "numa_mode.h"
23 pg_data_t *node_data[MAX_NUMNODES];
24 EXPORT_SYMBOL(node_data);
26 cpumask_t node_to_cpumask_map[MAX_NUMNODES];
27 EXPORT_SYMBOL(node_to_cpumask_map);
29 const struct numa_mode numa_mode_plain = {
33 static const struct numa_mode *mode = &numa_mode_plain;
35 int numa_pfn_to_nid(unsigned long pfn)
37 return mode->__pfn_to_nid ? mode->__pfn_to_nid(pfn) : 0;
40 void numa_update_cpu_topology(void)
42 if (mode->update_cpu_topology)
43 mode->update_cpu_topology();
46 int __node_distance(int a, int b)
48 return mode->distance ? mode->distance(a, b) : 0;
51 int numa_debug_enabled;
54 * alloc_node_data() - Allocate node data
56 static __init pg_data_t *alloc_node_data(void)
60 res = (pg_data_t *) memblock_alloc(sizeof(pg_data_t), 8);
61 memset(res, 0, sizeof(pg_data_t));
66 * numa_setup_memory() - Assign bootmem to nodes
68 * The memory is first added to memblock without any respect to nodes.
69 * This is fixed before remaining memblock memory is handed over to the
71 * An important side effect is that large bootmem allocations might easily
72 * cross node boundaries, which can be needed for large allocations with
73 * smaller memory stripes in each node (i.e. when using NUMA emulation).
75 * Memory defines nodes:
76 * Therefore this routine also sets the nodes online with memory.
78 static void __init numa_setup_memory(void)
80 unsigned long cur_base, align, end_of_dram;
83 end_of_dram = memblock_end_of_DRAM();
84 align = mode->align ? mode->align() : ULONG_MAX;
87 * Step through all available memory and assign it to the nodes
88 * indicated by the mode implementation.
89 * All nodes which are seen here will be set online.
93 nid = numa_pfn_to_nid(PFN_DOWN(cur_base));
95 memblock_set_node(cur_base, align, &memblock.memory, nid);
97 } while (cur_base < end_of_dram);
99 /* Allocate and fill out node_data */
100 for (nid = 0; nid < MAX_NUMNODES; nid++)
101 NODE_DATA(nid) = alloc_node_data();
103 for_each_online_node(nid) {
104 unsigned long start_pfn, end_pfn;
105 unsigned long t_start, t_end;
108 start_pfn = ULONG_MAX;
110 for_each_mem_pfn_range(i, nid, &t_start, &t_end, NULL) {
111 if (t_start < start_pfn)
116 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
117 NODE_DATA(nid)->node_id = nid;
122 * numa_setup() - Earliest initialization
124 * Assign the mode and call the mode's setup routine.
126 void __init numa_setup(void)
128 pr_info("NUMA mode: %s\n", mode->name);
137 * numa_init_early() - Initialization initcall
139 * This runs when only one CPU is online and before the first
140 * topology update is called for by the scheduler.
142 static int __init numa_init_early(void)
144 /* Attach all possible CPUs to node 0 for now. */
145 cpumask_copy(&node_to_cpumask_map[0], cpu_possible_mask);
148 early_initcall(numa_init_early);
151 * numa_init_late() - Initialization initcall
153 * Register NUMA nodes.
155 static int __init numa_init_late(void)
159 for_each_online_node(nid)
160 register_one_node(nid);
163 arch_initcall(numa_init_late);
165 static int __init parse_debug(char *parm)
167 numa_debug_enabled = 1;
170 early_param("numa_debug", parse_debug);
172 static int __init parse_numa(char *parm)
174 if (strcmp(parm, numa_mode_plain.name) == 0)
175 mode = &numa_mode_plain;
176 #ifdef CONFIG_NUMA_EMU
177 if (strcmp(parm, numa_mode_emu.name) == 0)
178 mode = &numa_mode_emu;
182 early_param("numa", parse_numa);