memblock: updates for 7.2-rc1

Small fixes and a cleanup:
 * numa emulation: fix detection of under-allocated emulated nodes
 * memblock tests: fix NUMA tests to properly differentiate reserved areas
   with differnet flags
 * mm_init: use div64_ul() instead of do_div() to better express the intent
   of the division
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEeOVYVaWZL5900a/pOQOGJssO/ZEFAmoxCXEACgkQOQOGJssO
 /ZGDjwgAk4an63rSlJ5tEbOsYK9Ip2yqgDOA/UQlSKsxsGUhg8c3K3A5lUQLGyNn
 f2qL2QrxzYGk4a/2QtVptP2c9JNrJdPCbtlv588aZ13k7i+6WwxTtotgwNgFew0k
 C0tea45PnIbUafCco4T00LnmzeyVViib33+nmFb2HUEcxENlu1V3SLQMutpNm7YK
 G+i5l6Q/6tHV2QhAXOs9IIOPBXlQraDc+CL5+fsnNGKzsTFnRgn5rY17Gg69jctc
 TnCj8TubWpTkfa5A/N93zQqJlnj3CthBKkpdM3mUAzqcFSr/W/TBXevc/x7Gp9bI
 ox9zq11iKU2MakeTdmK72ldaNg6B+w==
 =zkPI
 -----END PGP SIGNATURE-----

Merge tag 'memblock-v7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock

Pull memblock updates from Mike Rapoport:
 "Small fixes and a cleanup:

   - numa emulation: fix detection of under-allocated emulated nodes

   - memblock tests: fix NUMA tests to properly differentiate reserved
     areas with differnet flags

   - mm_init: use div64_ul() instead of do_div() to better express the
     intent of the division"

* tag 'memblock-v7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock:
  mm: mm_init: use div64_ul() instead of do_div()
  tools/testing/memblock: fix stale NUMA reservation tests
  mm/fake-numa: fix under-allocation detection in uniform split
This commit is contained in:
Linus Torvalds 2026-06-17 12:16:28 -07:00
commit 21bd909c78
6 changed files with 23 additions and 17 deletions

View File

@ -2412,7 +2412,7 @@ void *__init alloc_large_system_hash(const char *tablename,
/* limit allocation size to 1/16 total memory by default */
if (max == 0) {
max = ((unsigned long long)nr_all_pages << PAGE_SHIFT) >> 4;
do_div(max, bucketsize);
max = div64_ul(max, bucketsize);
}
max = min(max, 0x80000000ULL);

View File

@ -214,7 +214,7 @@ static u64 uniform_size(u64 max_addr, u64 base, u64 hole, int nr_nodes)
* Sets up fake nodes of `size' interleaved over physical nodes ranging from
* `addr' to `max_addr'.
*
* Returns zero on success or negative on error.
* Returns node ID of the next node on success or negative error code.
*/
static int __init split_nodes_size_interleave_uniform(struct numa_meminfo *ei,
struct numa_meminfo *pi,
@ -398,7 +398,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
*/
if (strchr(emu_cmdline, 'U')) {
unsigned long n;
int nid = 0;
int nid = 0, nr_created;
n = simple_strtoul(emu_cmdline, &emu_cmdline, 0);
ret = -1;
@ -416,9 +416,18 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
n, &pi.blk[0], nid);
if (ret < 0)
break;
if (ret < n) {
/*
* If no memory was found for this physical node,
* skip the under-allocation check.
*/
if (ret == nid)
continue;
nr_created = ret - nid;
if (nr_created < n) {
pr_info("%s: phys: %d only got %d of %ld nodes, failing\n",
__func__, i, ret, n);
__func__, i, nr_created, n);
ret = -1;
break;
}

View File

@ -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.

View File

@ -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

View File

@ -368,7 +368,7 @@ 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);
__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);
@ -861,8 +861,8 @@ static int alloc_exact_nid_numa_reserved_full_merge_generic_check(void)
min_addr = r2.base + r2.size;
max_addr = r1.base;
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
__memblock_reserve(r1.base, r1.size, nid_req, MEMBLOCK_RSRV_KERN);
__memblock_reserve(r2.base, r2.size, nid_req, MEMBLOCK_RSRV_KERN);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,

View File

@ -1965,7 +1965,7 @@ 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);
__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);
@ -2412,8 +2412,8 @@ static int alloc_nid_numa_reserved_full_merge_generic_check(void)
min_addr = r2.base + r2.size;
max_addr = r1.base;
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
__memblock_reserve(r1.base, r1.size, nid_req, MEMBLOCK_RSRV_KERN);
__memblock_reserve(r2.base, r2.size, nid_req, MEMBLOCK_RSRV_KERN);
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);