Skip to content

Commit 7888e96

Browse files
committed
x86, NUMA: Initialize and use remap allocator from setup_node_bootmem()
setup_node_bootmem() is taken from 64bit and doesn't use remap allocator. It's about to be shared with 32bit so add support for it. If NODE_DATA is remapped, it's noted in the debug message and node locality check is skipped as the __pa() of the remapped address doesn't reflect the actual physical address. On 64bit, remap allocator becomes noop and doesn't affect the behavior. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Yinghai Lu <yinghai@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com>
1 parent 99cca49 commit 7888e96

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

arch/x86/mm/numa.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ static void __init setup_node_bootmem(int nid, u64 start, u64 end)
197197
const u64 nd_low = PFN_PHYS(MAX_DMA_PFN);
198198
const u64 nd_high = PFN_PHYS(max_pfn_mapped);
199199
const size_t nd_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
200+
bool remapped = false;
200201
u64 nd_pa;
202+
void *nd;
201203
int tnid;
202204

203205
/*
@@ -207,34 +209,45 @@ static void __init setup_node_bootmem(int nid, u64 start, u64 end)
207209
if (end && (end - start) < NODE_MIN_SIZE)
208210
return;
209211

212+
/* initialize remap allocator before aligning to ZONE_ALIGN */
213+
init_alloc_remap(nid, start, end);
214+
210215
start = roundup(start, ZONE_ALIGN);
211216

212217
printk(KERN_INFO "Initmem setup node %d %016Lx-%016Lx\n",
213218
nid, start, end);
214219

215220
/*
216-
* Try to allocate node data on local node and then fall back to
217-
* all nodes. Never allocate in DMA zone.
221+
* Allocate node data. Try remap allocator first, node-local
222+
* memory and then any node. Never allocate in DMA zone.
218223
*/
219-
nd_pa = memblock_x86_find_in_range_node(nid, nd_low, nd_high,
224+
nd = alloc_remap(nid, nd_size);
225+
if (nd) {
226+
nd_pa = __pa(nd);
227+
remapped = true;
228+
} else {
229+
nd_pa = memblock_x86_find_in_range_node(nid, nd_low, nd_high,
220230
nd_size, SMP_CACHE_BYTES);
221-
if (nd_pa == MEMBLOCK_ERROR)
222-
nd_pa = memblock_find_in_range(nd_low, nd_high,
223-
nd_size, SMP_CACHE_BYTES);
224-
if (nd_pa == MEMBLOCK_ERROR) {
225-
pr_err("Cannot find %zu bytes in node %d\n", nd_size, nid);
226-
return;
231+
if (nd_pa == MEMBLOCK_ERROR)
232+
nd_pa = memblock_find_in_range(nd_low, nd_high,
233+
nd_size, SMP_CACHE_BYTES);
234+
if (nd_pa == MEMBLOCK_ERROR) {
235+
pr_err("Cannot find %zu bytes in node %d\n",
236+
nd_size, nid);
237+
return;
238+
}
239+
memblock_x86_reserve_range(nd_pa, nd_pa + nd_size, "NODE_DATA");
240+
nd = __va(nd_pa);
227241
}
228-
memblock_x86_reserve_range(nd_pa, nd_pa + nd_size, "NODE_DATA");
229242

230243
/* report and initialize */
231-
printk(KERN_INFO " NODE_DATA [%016Lx - %016Lx]\n",
232-
nd_pa, nd_pa + nd_size - 1);
244+
printk(KERN_INFO " NODE_DATA [%016Lx - %016Lx]%s\n",
245+
nd_pa, nd_pa + nd_size - 1, remapped ? " (remapped)" : "");
233246
tnid = early_pfn_to_nid(nd_pa >> PAGE_SHIFT);
234-
if (tnid != nid)
247+
if (!remapped && tnid != nid)
235248
printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nid, tnid);
236249

237-
node_data[nid] = __va(nd_pa);
250+
node_data[nid] = nd;
238251
memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
239252
NODE_DATA(nid)->node_id = nid;
240253
NODE_DATA(nid)->node_start_pfn = start >> PAGE_SHIFT;

arch/x86/mm/numa_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void resume_map_numa_kva(pgd_t *pgd_base)
265265
* opportunistically and the callers will fall back to other memory
266266
* allocation mechanisms on failure.
267267
*/
268-
static __init void init_alloc_remap(int nid, u64 start, u64 end)
268+
void __init init_alloc_remap(int nid, u64 start, u64 end)
269269
{
270270
unsigned long start_pfn = start >> PAGE_SHIFT;
271271
unsigned long end_pfn = end >> PAGE_SHIFT;

arch/x86/mm/numa_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ void __init numa_reset_distance(void);
2121

2222
void __init x86_numa_init(void);
2323

24+
#ifdef CONFIG_X86_64
25+
static inline void init_alloc_remap(int nid, u64 start, u64 end) { }
26+
#else
27+
void __init init_alloc_remap(int nid, u64 start, u64 end);
28+
#endif
29+
2430
#ifdef CONFIG_NUMA_EMU
2531
void __init numa_emulation(struct numa_meminfo *numa_meminfo,
2632
int numa_dist_cnt);

0 commit comments

Comments
 (0)