Skip to content

Commit b842f4f

Browse files
migliiorppt
authored andcommitted
Add tests for memblock_alloc_node()
This test is aimed at verifying the memblock_alloc_node() to work as expected, so setting the correct NUMA node for the new allocated region. The memblock_alloc_node() is called directly without using any stub. The core check is between the requested NUMA node and the `nid` field inside the memblock_region structure. These two are supposed to be equal for the test to succeed. Signed-off-by: Claudio Migliorelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (IBM) <[email protected]>
1 parent 44c026a commit b842f4f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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)