Skip to content

Commit 075e333

Browse files
committed
Merge tag 'memblock-v6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
Pull memblock updates from Mike Rapoport: - add test for memblock_alloc_node() - minor coding style fixes - add flags and nid info in memblock debugfs * tag 'memblock-v6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock: memblock: Update nid info in memblock debugfs memblock: Add flags and nid info in memblock debugfs Fix some coding style errors in memblock.c Add tests for memblock_alloc_node()
2 parents ea3f827 + de649e7 commit 075e333

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

mm/memblock.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ static __refdata struct memblock_type *memblock_memory = &memblock.memory;
156156
} while (0)
157157

158158
static int memblock_debug __initdata_memblock;
159-
static bool system_has_some_mirror __initdata_memblock = false;
159+
static bool system_has_some_mirror __initdata_memblock;
160160
static int memblock_can_resize __initdata_memblock;
161-
static int memblock_memory_in_slab __initdata_memblock = 0;
162-
static int memblock_reserved_in_slab __initdata_memblock = 0;
161+
static int memblock_memory_in_slab __initdata_memblock;
162+
static int memblock_reserved_in_slab __initdata_memblock;
163163

164164
static enum memblock_flags __init_memblock choose_memblock_flags(void)
165165
{
@@ -2178,20 +2178,44 @@ void __init memblock_free_all(void)
21782178
}
21792179

21802180
#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK)
2181+
static const char * const flagname[] = {
2182+
[ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG",
2183+
[ilog2(MEMBLOCK_MIRROR)] = "MIRROR",
2184+
[ilog2(MEMBLOCK_NOMAP)] = "NOMAP",
2185+
[ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG",
2186+
};
21812187

21822188
static int memblock_debug_show(struct seq_file *m, void *private)
21832189
{
21842190
struct memblock_type *type = m->private;
21852191
struct memblock_region *reg;
2186-
int i;
2192+
int i, j, nid;
2193+
unsigned int count = ARRAY_SIZE(flagname);
21872194
phys_addr_t end;
21882195

21892196
for (i = 0; i < type->cnt; i++) {
21902197
reg = &type->regions[i];
21912198
end = reg->base + reg->size - 1;
2199+
nid = memblock_get_region_node(reg);
21922200

21932201
seq_printf(m, "%4d: ", i);
2194-
seq_printf(m, "%pa..%pa\n", &reg->base, &end);
2202+
seq_printf(m, "%pa..%pa ", &reg->base, &end);
2203+
if (nid != MAX_NUMNODES)
2204+
seq_printf(m, "%4d ", nid);
2205+
else
2206+
seq_printf(m, "%4c ", 'x');
2207+
if (reg->flags) {
2208+
for (j = 0; j < count; j++) {
2209+
if (reg->flags & (1U << j)) {
2210+
seq_printf(m, "%s\n", flagname[j]);
2211+
break;
2212+
}
2213+
}
2214+
if (j == count)
2215+
seq_printf(m, "%s\n", "UNKNOWN");
2216+
} else {
2217+
seq_printf(m, "%s\n", "NONE");
2218+
}
21952219
}
21962220
return 0;
21972221
}

tools/testing/memblock/tests/alloc_nid_api.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,35 @@ static int alloc_nid_numa_split_all_reserved_generic_check(void)
24942494
return 0;
24952495
}
24962496

2497+
/*
2498+
* A simple test that tries to allocate a memory region through the
2499+
* memblock_alloc_node() on a NUMA node with id `nid`. Expected to have the
2500+
* correct NUMA node set for the new region.
2501+
*/
2502+
static int alloc_node_on_correct_nid(void)
2503+
{
2504+
int nid_req = 2;
2505+
void *allocated_ptr = NULL;
2506+
#ifdef CONFIG_NUMA
2507+
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
2508+
#endif
2509+
phys_addr_t size = SZ_512;
2510+
2511+
PREFIX_PUSH();
2512+
setup_numa_memblock(node_fractions);
2513+
2514+
allocated_ptr = memblock_alloc_node(size, SMP_CACHE_BYTES, nid_req);
2515+
2516+
ASSERT_NE(allocated_ptr, NULL);
2517+
#ifdef CONFIG_NUMA
2518+
ASSERT_EQ(nid_req, req_node->nid);
2519+
#endif
2520+
2521+
test_pass_pop();
2522+
2523+
return 0;
2524+
}
2525+
24972526
/* Test case wrappers for NUMA tests */
24982527
static int alloc_nid_numa_simple_check(void)
24992528
{
@@ -2632,6 +2661,15 @@ static int alloc_nid_numa_split_all_reserved_check(void)
26322661
return 0;
26332662
}
26342663

2664+
static int alloc_node_numa_on_correct_nid(void)
2665+
{
2666+
test_print("\tRunning %s...\n", __func__);
2667+
run_top_down(alloc_node_on_correct_nid);
2668+
run_bottom_up(alloc_node_on_correct_nid);
2669+
2670+
return 0;
2671+
}
2672+
26352673
int __memblock_alloc_nid_numa_checks(void)
26362674
{
26372675
test_print("Running %s NUMA tests...\n",
@@ -2652,6 +2690,8 @@ int __memblock_alloc_nid_numa_checks(void)
26522690
alloc_nid_numa_reserved_full_merge_check();
26532691
alloc_nid_numa_split_all_reserved_check();
26542692

2693+
alloc_node_numa_on_correct_nid();
2694+
26552695
return 0;
26562696
}
26572697

0 commit comments

Comments
 (0)