Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <claudio.migliorelli@mail.polimi.it>
Link: https://lore.kernel.org/r/ea5e938e-6b74-b188-af59-4b94b18bc0@mail.polimi.it
Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>

authored by

Claudio Migliorelli and committed by
Mike Rapoport (IBM)
b842f4f5 44c026a7

+40
+40
tools/testing/memblock/tests/alloc_nid_api.c
··· 2494 2494 return 0; 2495 2495 } 2496 2496 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 + 2497 2526 /* Test case wrappers for NUMA tests */ 2498 2527 static int alloc_nid_numa_simple_check(void) 2499 2528 { ··· 2661 2632 return 0; 2662 2633 } 2663 2634 2635 + static int alloc_node_numa_on_correct_nid(void) 2636 + { 2637 + test_print("\tRunning %s...\n", __func__); 2638 + run_top_down(alloc_node_on_correct_nid); 2639 + run_bottom_up(alloc_node_on_correct_nid); 2640 + 2641 + return 0; 2642 + } 2643 + 2664 2644 int __memblock_alloc_nid_numa_checks(void) 2665 2645 { 2666 2646 test_print("Running %s NUMA tests...\n", ··· 2689 2651 alloc_nid_numa_large_region_check(); 2690 2652 alloc_nid_numa_reserved_full_merge_check(); 2691 2653 alloc_nid_numa_split_all_reserved_check(); 2654 + 2655 + alloc_node_numa_on_correct_nid(); 2692 2656 2693 2657 return 0; 2694 2658 }