From: priyanshukumarpu@gmail.com
To: rppt@kernel.org
Cc: akpm@linux-foundation.org, changyuanl@google.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Priyanshu Kumar <priyanshukumarpu@gmail.com>
Subject: [PATCH] tools/testing/memblock: fix stale NUMA reservation tests
Date: Mon, 13 Apr 2026 09:14:58 +0000 [thread overview]
Message-ID: <20260413091458.774770-1-priyanshukumarpu@gmail.com> (raw)
From: Priyanshu Kumar <priyanshukumarpu@gmail.com>
memblock allocations now reserve memory with MEMBLOCK_RSRV_KERN and,
on NUMA configurations, record the requested node on the reserved
region. Several memblock simulator NUMA tests still expected merges
that only worked before those reservation semantics changed, so the
suite aborted even though the allocator behavior was correct.
Update the NUMA merge expectations in the memblock_alloc_try_nid()
and memblock_alloc_exact_nid_raw() tests to match the current reserved
region metadata rules. For cases that should still merge, create the
pre-existing reservation with matching nid and MEMBLOCK_RSRV_KERN
metadata. Also strengthen the memblock_alloc_node() coverage by
checking the newly created reserved region directly instead of
re-reading the source memory node descriptor.
Finally, drop the stale README/TODO notes that still claimed
memblock_alloc_node() could not be tested.
The memblock simulator passes again with NUMA enabled after these
updates.
Signed-off-by: Priyanshu Kumar <priyanshukumarpu@gmail.com>
---
tools/testing/memblock/README | 5 +--
tools/testing/memblock/TODO | 4 +-
.../memblock/tests/alloc_exact_nid_api.c | 29 +++++++-----
tools/testing/memblock/tests/alloc_nid_api.c | 44 +++++++++++++------
4 files changed, 53 insertions(+), 29 deletions(-)
diff --git a/tools/testing/memblock/README b/tools/testing/memblock/README
index 7ca437d81806..b435f48d8a70 100644
--- a/tools/testing/memblock/README
+++ b/tools/testing/memblock/README
@@ -104,10 +104,7 @@ called at the beginning of each test.
Known issues
============
-1. Requesting a specific NUMA node via memblock_alloc_node() does not work as
- intended. Once the fix is in place, tests for this function can be added.
-
-2. Tests for memblock_alloc_low() can't be easily implemented. The function uses
+1. Tests for memblock_alloc_low() can't be easily implemented. The function uses
ARCH_LOW_ADDRESS_LIMIT marco, which can't be changed to point at the low
memory of the memory_block.
diff --git a/tools/testing/memblock/TODO b/tools/testing/memblock/TODO
index e306c90c535f..c13ad0dae776 100644
--- a/tools/testing/memblock/TODO
+++ b/tools/testing/memblock/TODO
@@ -1,5 +1,5 @@
TODO
=====
-1. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
- for the new region
+1. Add tests for memblock_alloc_low() once the simulator can model
+ ARCH_LOW_ADDRESS_LIMIT against the low memory in memory_block
diff --git a/tools/testing/memblock/tests/alloc_exact_nid_api.c b/tools/testing/memblock/tests/alloc_exact_nid_api.c
index 6e14447da6e1..3f5ab994f63a 100644
--- a/tools/testing/memblock/tests/alloc_exact_nid_api.c
+++ b/tools/testing/memblock/tests/alloc_exact_nid_api.c
@@ -368,7 +368,8 @@ static int alloc_exact_nid_bottom_up_numa_part_reserved_check(void)
max_addr = memblock_end_of_DRAM();
total_size = size + r1.size;
- memblock_reserve(r1.base, r1.size);
+ ASSERT_EQ(0, __memblock_reserve(r1.base, r1.size, nid_req,
+ MEMBLOCK_RSRV_KERN));
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
@@ -831,14 +832,17 @@ static int alloc_exact_nid_numa_large_region_generic_check(void)
* | | r2 | new | r1 | |
* +-------------+----+-----------------------+----+------------------+
*
- * Expect to merge all of the regions into one. The region counter and total
- * size fields get updated.
+ * Expect to allocate the requested node as a separate kernel-reserved region.
+ * The neighboring reservations remain distinct because the new region records
+ * the requested NUMA node and MEMBLOCK_RSRV_KERN flag.
*/
static int alloc_exact_nid_numa_reserved_full_merge_generic_check(void)
{
int nid_req = 6;
int nid_next = nid_req + 1;
- struct memblock_region *new_rgn = &memblock.reserved.regions[0];
+ struct memblock_region *left_rgn = &memblock.reserved.regions[0];
+ struct memblock_region *new_rgn = &memblock.reserved.regions[1];
+ struct memblock_region *right_rgn = &memblock.reserved.regions[2];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *next_node = &memblock.memory.regions[nid_next];
void *allocated_ptr = NULL;
@@ -871,13 +875,18 @@ static int alloc_exact_nid_numa_reserved_full_merge_generic_check(void)
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
- ASSERT_EQ(new_rgn->size, total_size);
- ASSERT_EQ(new_rgn->base, r2.base);
-
- ASSERT_LE(new_rgn->base, req_node->base);
- ASSERT_LE(region_end(req_node), region_end(new_rgn));
+ ASSERT_EQ(left_rgn->base, r2.base);
+ ASSERT_EQ(left_rgn->size, r2.size);
+ ASSERT_EQ(right_rgn->base, r1.base);
+ ASSERT_EQ(right_rgn->size, r1.size);
+ ASSERT_EQ(new_rgn->base, req_node->base);
+ ASSERT_EQ(new_rgn->size, size);
+ ASSERT_EQ(new_rgn->flags, MEMBLOCK_RSRV_KERN);
+ ASSERT_EQ(memblock_get_region_node(new_rgn), nid_req);
+ ASSERT_LE(req_node->base, new_rgn->base);
+ ASSERT_LE(region_end(new_rgn), region_end(req_node));
- ASSERT_EQ(memblock.reserved.cnt, 1);
+ ASSERT_EQ(memblock.reserved.cnt, 3);
ASSERT_EQ(memblock.reserved.total_size, total_size);
test_pass_pop();
diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c
index 562e4701b0e0..3d7a8c370844 100644
--- a/tools/testing/memblock/tests/alloc_nid_api.c
+++ b/tools/testing/memblock/tests/alloc_nid_api.c
@@ -1965,7 +1965,8 @@ static int alloc_nid_bottom_up_numa_part_reserved_check(void)
max_addr = memblock_end_of_DRAM();
total_size = size + r1.size;
- memblock_reserve(r1.base, r1.size);
+ ASSERT_EQ(0, __memblock_reserve(r1.base, r1.size, nid_req,
+ MEMBLOCK_RSRV_KERN));
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
@@ -2382,14 +2383,17 @@ static int alloc_nid_numa_large_region_generic_check(void)
* | | r2 | new | r1 | |
* +-------------+----+-----------------------+----+------------------+
*
- * Expect to merge all of the regions into one. The region counter and total
- * size fields get updated.
+ * Expect to allocate the requested node as a separate kernel-reserved region.
+ * The neighboring reservations remain distinct because the new region records
+ * the requested NUMA node and MEMBLOCK_RSRV_KERN flag.
*/
static int alloc_nid_numa_reserved_full_merge_generic_check(void)
{
int nid_req = 6;
int nid_next = nid_req + 1;
- struct memblock_region *new_rgn = &memblock.reserved.regions[0];
+ struct memblock_region *left_rgn = &memblock.reserved.regions[0];
+ struct memblock_region *new_rgn = &memblock.reserved.regions[1];
+ struct memblock_region *right_rgn = &memblock.reserved.regions[2];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *next_node = &memblock.memory.regions[nid_next];
void *allocated_ptr = NULL;
@@ -2421,13 +2425,18 @@ static int alloc_nid_numa_reserved_full_merge_generic_check(void)
ASSERT_NE(allocated_ptr, NULL);
assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
- ASSERT_EQ(new_rgn->size, total_size);
- ASSERT_EQ(new_rgn->base, r2.base);
-
- ASSERT_LE(new_rgn->base, req_node->base);
- ASSERT_LE(region_end(req_node), region_end(new_rgn));
+ ASSERT_EQ(left_rgn->base, r2.base);
+ ASSERT_EQ(left_rgn->size, r2.size);
+ ASSERT_EQ(right_rgn->base, r1.base);
+ ASSERT_EQ(right_rgn->size, r1.size);
+ ASSERT_EQ(new_rgn->base, req_node->base);
+ ASSERT_EQ(new_rgn->size, size);
+ ASSERT_EQ(new_rgn->flags, MEMBLOCK_RSRV_KERN);
+ ASSERT_EQ(memblock_get_region_node(new_rgn), nid_req);
+ ASSERT_LE(req_node->base, new_rgn->base);
+ ASSERT_LE(region_end(new_rgn), region_end(req_node));
- ASSERT_EQ(memblock.reserved.cnt, 1);
+ ASSERT_EQ(memblock.reserved.cnt, 3);
ASSERT_EQ(memblock.reserved.total_size, total_size);
test_pass_pop();
@@ -2496,15 +2505,18 @@ static int alloc_nid_numa_split_all_reserved_generic_check(void)
/*
* A simple test that tries to allocate a memory region through the
- * memblock_alloc_node() on a NUMA node with id `nid`. Expected to have the
- * correct NUMA node set for the new region.
+ * memblock_alloc_node() on a NUMA node with id `nid`. Expected to allocate
+ * the region within the requested node and mark the new reservation with the
+ * correct NUMA node.
*/
static int alloc_node_on_correct_nid(void)
{
int nid_req = 2;
void *allocated_ptr = NULL;
#ifdef CONFIG_NUMA
+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
+ phys_addr_t req_node_end = region_end(req_node);
#endif
phys_addr_t size = SZ_512;
@@ -2515,7 +2527,13 @@ static int alloc_node_on_correct_nid(void)
ASSERT_NE(allocated_ptr, NULL);
#ifdef CONFIG_NUMA
- ASSERT_EQ(nid_req, req_node->nid);
+ ASSERT_EQ(memblock.reserved.cnt, 1);
+ ASSERT_EQ(new_rgn->size, size);
+ ASSERT_EQ(new_rgn->base, (phys_addr_t)allocated_ptr);
+ ASSERT_EQ(new_rgn->flags, MEMBLOCK_RSRV_KERN);
+ ASSERT_EQ(nid_req, memblock_get_region_node(new_rgn));
+ ASSERT_LE(req_node->base, new_rgn->base);
+ ASSERT_LE(region_end(new_rgn), req_node_end);
#endif
test_pass_pop();
--
2.43.0
reply other threads:[~2026-04-13 9:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260413091458.774770-1-priyanshukumarpu@gmail.com \
--to=priyanshukumarpu@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=changyuanl@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox