History

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

Pull memblock updates from Mike Rapoport: "Extend test coverage: - add tests that trigger reallocation of memblock structures from memblock itself via memblock_double_array() - add tests for memblock_alloc_exact_nid_raw() that verify that requested node and memory range constraints are respected" * tag 'memblock-v6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock: memblock tests: remove completed TODO item memblock tests: add generic NUMA tests for memblock_alloc_exact_nid_raw memblock tests: add bottom-up NUMA tests for memblock_alloc_exact_nid_raw memblock tests: add top-down NUMA tests for memblock_alloc_exact_nid_raw memblock tests: introduce range tests for memblock_alloc_exact_nid_raw memblock test: Update TODO list memblock test: Add test to memblock_reserve() 129th region memblock test: Add test to memblock_add() 129th region

Linus Torvalds committed 3 years ago

Commit ad76bf12 parents 6f1f5ca 80c2fe010 files · +1622 −280Browse files

Unified · Split

10 files
  1. tools/testing/memblock/Makefile +1 −1
  2. tools/testing/memblock/TODO +1 −13
  3. tools/testing/memblock/main.c +2 −0
  4. tools/testing/memblock/tests/alloc_exact_nid_api.c +1113 −0
  5. tools/testing/memblock/tests/alloc_exact_nid_api.h +25 −0
  6. tools/testing/memblock/tests/alloc_nid_api.c +283 −263
  7. tools/testing/memblock/tests/alloc_nid_api.h +1 −0
  8. tools/testing/memblock/tests/basic_api.c +184 −0
  9. tools/testing/memblock/tests/common.c +5 −2
  10. tools/testing/memblock/tests/common.h +7 −1
tools/testing/memblock/Makefile+1−1
@@ -7,7 +7,7 @@ CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \ · 6 unmodified lines
77 LDFLAGS += -fsanitize=address -fsanitize=undefined
88 TARGETS = main
99 TEST_OFILES = tests/alloc_nid_api.o tests/alloc_helpers_api.o tests/alloc_api.o \
10− tests/basic_api.o tests/common.o
10+ tests/basic_api.o tests/common.o tests/alloc_exact_nid_api.o
1111 DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o
1212 OFILES = main.o $(DEP_OFILES) $(TEST_OFILES)
1313 EXTR_SRC = ../../../mm/memblock.c
tools/testing/memblock/TODO+1−13
@@ -1,17 +1,5 @@
11 TODO
22 =====
33
4−1. Add tests trying to memblock_add() or memblock_reserve() 129th region.
5− This will trigger memblock_double_array(), make sure it succeeds.
6− *Important:* These tests require valid memory ranges, use dummy physical
7− memory block from common.c to implement them. It is also very
8− likely that the current MEM_SIZE won't be enough for these
9− test cases. Use realloc to adjust the size accordingly.
10−
11−2. Add test cases using this functions (implement them for both directions):
12− + memblock_alloc_raw()
13− + memblock_alloc_exact_nid_raw()
14− + memblock_alloc_try_nid_raw()
15−
16−3. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
4+1. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
175 for the new region
tools/testing/memblock/main.c+2−0
@@ -3,6 +3,7 @@ · 2 unmodified lines
33 #include "tests/alloc_api.h"
44 #include "tests/alloc_helpers_api.h"
55 #include "tests/alloc_nid_api.h"
6+#include "tests/alloc_exact_nid_api.h"
67 #include "tests/common.h"
78
89 int main(int argc, char **argv)
@@ -12,6 +13,7 @@ int main(int argc, char **argv) · 3 unmodified lines
1213 memblock_alloc_checks();
1314 memblock_alloc_helpers_checks();
1415 memblock_alloc_nid_checks();
16+ memblock_alloc_exact_nid_checks();
1517
1618 return 0;
1719 }
tools/testing/memblock/tests/alloc_exact_nid_api.c+1113−0
@@ -0,0 +1,1113 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+#include "alloc_exact_nid_api.h"
3+#include "alloc_nid_api.h"
4+
5+#define FUNC_NAME "memblock_alloc_exact_nid_raw"
6+
7+/*
8+ * contains the fraction of MEM_SIZE contained in each node in basis point
9+ * units (one hundredth of 1% or 1/10000)
10+ */
11+static const unsigned int node_fractions[] = {
12+ 2500, /* 1/4 */
13+ 625, /* 1/16 */
14+ 1250, /* 1/8 */
15+ 1250, /* 1/8 */
16+ 625, /* 1/16 */
17+ 625, /* 1/16 */
18+ 2500, /* 1/4 */
19+ 625, /* 1/16 */
20+};
21+
22+/*
23+ * A test that tries to allocate a memory region in a specific NUMA node that
24+ * has enough memory to allocate a region of the requested size.
25+ * Expect to allocate an aligned region at the end of the requested node.
26+ */
27+static int alloc_exact_nid_top_down_numa_simple_check(void)
28+{
29+ int nid_req = 3;
30+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
31+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
32+ void *allocated_ptr = NULL;
33+ phys_addr_t size;
34+ phys_addr_t min_addr;
35+ phys_addr_t max_addr;
36+
37+ PREFIX_PUSH();
38+ setup_numa_memblock(node_fractions);
39+
40+ ASSERT_LE(SZ_4, req_node->size);
41+ size = req_node->size / SZ_4;
42+ min_addr = memblock_start_of_DRAM();
43+ max_addr = memblock_end_of_DRAM();
44+
45+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
46+ min_addr, max_addr,
47+ nid_req);
48+
49+ ASSERT_NE(allocated_ptr, NULL);
50+ ASSERT_MEM_NE(allocated_ptr, 0, size);
51+
52+ ASSERT_EQ(new_rgn->size, size);
53+ ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
54+ ASSERT_LE(req_node->base, new_rgn->base);
55+
56+ ASSERT_EQ(memblock.reserved.cnt, 1);
57+ ASSERT_EQ(memblock.reserved.total_size, size);
58+
59+ test_pass_pop();
60+
61+ return 0;
62+}
63+
64+/*
65+ * A test that tries to allocate a memory region in a specific NUMA node that
66+ * is partially reserved but has enough memory for the allocated region:
67+ *
68+ * | +---------------------------------------+ |
69+ * | | requested | |
70+ * +-----------+---------------------------------------+----------+
71+ *
72+ * | +------------------+ +-----+ |
73+ * | | reserved | | new | |
74+ * +-----------+------------------+--------------+-----+----------+
75+ *
76+ * Expect to allocate an aligned region at the end of the requested node. The
77+ * region count and total size get updated.
78+ */
79+static int alloc_exact_nid_top_down_numa_part_reserved_check(void)
80+{
81+ int nid_req = 4;
82+ struct memblock_region *new_rgn = &memblock.reserved.regions[1];
83+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
84+ void *allocated_ptr = NULL;
85+ struct region r1;
86+ phys_addr_t size;
87+ phys_addr_t min_addr;
88+ phys_addr_t max_addr;
89+
90+ PREFIX_PUSH();
91+ setup_numa_memblock(node_fractions);
92+
93+ ASSERT_LE(SZ_8, req_node->size);
94+ r1.base = req_node->base;
95+ r1.size = req_node->size / SZ_2;
96+ size = r1.size / SZ_4;
97+ min_addr = memblock_start_of_DRAM();
98+ max_addr = memblock_end_of_DRAM();
99+
100+ memblock_reserve(r1.base, r1.size);
101+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
102+ min_addr, max_addr,
103+ nid_req);
104+
105+ ASSERT_NE(allocated_ptr, NULL);
106+ ASSERT_MEM_NE(allocated_ptr, 0, size);
107+
108+ ASSERT_EQ(new_rgn->size, size);
109+ ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
110+ ASSERT_LE(req_node->base, new_rgn->base);
111+
112+ ASSERT_EQ(memblock.reserved.cnt, 2);
113+ ASSERT_EQ(memblock.reserved.total_size, size + r1.size);
114+
115+ test_pass_pop();
116+
117+ return 0;
118+}
119+
120+/*
121+ * A test that tries to allocate a memory region that spans over the min_addr
122+ * and max_addr range and overlaps with two different nodes, where the first
123+ * node is the requested node:
124+ *
125+ * min_addr
126+ * | max_addr
127+ * | |
128+ * v v
129+ * | +-----------------------+-----------+ |
130+ * | | requested | node3 | |
131+ * +-----------+-----------------------+-----------+--------------+
132+ * + +
133+ * | +-----------+ |
134+ * | | rgn | |
135+ * +-----------------------+-----------+--------------------------+
136+ *
137+ * Expect to drop the lower limit and allocate a memory region that ends at
138+ * the end of the requested node.
139+ */
140+static int alloc_exact_nid_top_down_numa_split_range_low_check(void)
141+{
142+ int nid_req = 2;
143+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
144+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
145+ void *allocated_ptr = NULL;
146+ phys_addr_t size = SZ_512;
147+ phys_addr_t min_addr;
148+ phys_addr_t max_addr;
149+ phys_addr_t req_node_end;
150+
151+ PREFIX_PUSH();
152+ setup_numa_memblock(node_fractions);
153+
154+ req_node_end = region_end(req_node);
155+ min_addr = req_node_end - SZ_256;
156+ max_addr = min_addr + size;
157+
158+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
159+ min_addr, max_addr,
160+ nid_req);
161+
162+ ASSERT_NE(allocated_ptr, NULL);
163+ ASSERT_MEM_NE(allocated_ptr, 0, size);
164+
165+ ASSERT_EQ(new_rgn->size, size);
166+ ASSERT_EQ(new_rgn->base, req_node_end - size);
167+ ASSERT_LE(req_node->base, new_rgn->base);
168+
169+ ASSERT_EQ(memblock.reserved.cnt, 1);
170+ ASSERT_EQ(memblock.reserved.total_size, size);
171+
172+ test_pass_pop();
173+
174+ return 0;
175+}
176+
177+/*
178+ * A test that tries to allocate a memory region that spans over the min_addr
179+ * and max_addr range and overlaps with two different nodes, where the requested
180+ * node ends before min_addr:
181+ *
182+ * min_addr
183+ * | max_addr
184+ * | |
185+ * v v
186+ * | +---------------+ +-------------+---------+ |
187+ * | | requested | | node1 | node2 | |
188+ * +----+---------------+--------+-------------+---------+----------+
189+ * + +
190+ * | +---------+ |
191+ * | | rgn | |
192+ * +----------+---------+-------------------------------------------+
193+ *
194+ * Expect to drop the lower limit and allocate a memory region that ends at
195+ * the end of the requested node.
196+ */
197+static int alloc_exact_nid_top_down_numa_no_overlap_split_check(void)
198+{
199+ int nid_req = 2;
200+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
201+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
202+ struct memblock_region *node2 = &memblock.memory.regions[6];
203+ void *allocated_ptr = NULL;
204+ phys_addr_t size;
205+ phys_addr_t min_addr;
206+ phys_addr_t max_addr;
207+
208+ PREFIX_PUSH();
209+ setup_numa_memblock(node_fractions);
210+
211+ size = SZ_512;
212+ min_addr = node2->base - SZ_256;
213+ max_addr = min_addr + size;
214+
215+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
216+ min_addr, max_addr,
217+ nid_req);
218+
219+ ASSERT_NE(allocated_ptr, NULL);
220+ ASSERT_MEM_NE(allocated_ptr, 0, size);
221+
222+ ASSERT_EQ(new_rgn->size, size);
223+ ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
224+ ASSERT_LE(req_node->base, new_rgn->base);
225+
226+ ASSERT_EQ(memblock.reserved.cnt, 1);
227+ ASSERT_EQ(memblock.reserved.total_size, size);
228+
229+ test_pass_pop();
230+
231+ return 0;
232+}
233+
234+/*
235+ * A test that tries to allocate memory within min_addr and max_add range when
236+ * the requested node and the range do not overlap, and requested node ends
237+ * before min_addr. The range overlaps with multiple nodes along node
238+ * boundaries:
239+ *
240+ * min_addr
241+ * | max_addr
242+ * | |
243+ * v v
244+ * |-----------+ +----------+----...----+----------+ |
245+ * | requested | | min node | ... | max node | |
246+ * +-----------+-----------+----------+----...----+----------+------+
247+ * + +
248+ * | +-----+ |
249+ * | | rgn | |
250+ * +-----+-----+----------------------------------------------------+
251+ *
252+ * Expect to drop the lower limit and allocate a memory region that ends at
253+ * the end of the requested node.
254+ */
255+static int alloc_exact_nid_top_down_numa_no_overlap_low_check(void)
256+{
257+ int nid_req = 0;
258+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
259+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
260+ struct memblock_region *min_node = &memblock.memory.regions[2];
261+ struct memblock_region *max_node = &memblock.memory.regions[5];
262+ void *allocated_ptr = NULL;
263+ phys_addr_t size = SZ_64;
264+ phys_addr_t max_addr;
265+ phys_addr_t min_addr;
266+
267+ PREFIX_PUSH();
268+ setup_numa_memblock(node_fractions);
269+
270+ min_addr = min_node->base;
271+ max_addr = region_end(max_node);
272+
273+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
274+ min_addr, max_addr,
275+ nid_req);
276+
277+ ASSERT_NE(allocated_ptr, NULL);
278+ ASSERT_MEM_NE(allocated_ptr, 0, size);
279+
280+ ASSERT_EQ(new_rgn->size, size);
281+ ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
282+
283+ ASSERT_EQ(memblock.reserved.cnt, 1);
284+ ASSERT_EQ(memblock.reserved.total_size, size);
285+
286+ test_pass_pop();
287+
288+ return 0;
289+}
290+
291+/*
292+ * A test that tries to allocate a memory region in a specific NUMA node that
293+ * has enough memory to allocate a region of the requested size.
294+ * Expect to allocate an aligned region at the beginning of the requested node.
295+ */
296+static int alloc_exact_nid_bottom_up_numa_simple_check(void)
297+{
298+ int nid_req = 3;
299+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
300+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
301+ void *allocated_ptr = NULL;
302+ phys_addr_t size;
303+ phys_addr_t min_addr;
304+ phys_addr_t max_addr;
305+
306+ PREFIX_PUSH();
307+ setup_numa_memblock(node_fractions);
308+
309+ ASSERT_LE(SZ_4, req_node->size);
310+ size = req_node->size / SZ_4;
311+ min_addr = memblock_start_of_DRAM();
312+ max_addr = memblock_end_of_DRAM();
313+
314+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
315+ min_addr, max_addr,
316+ nid_req);
317+
318+ ASSERT_NE(allocated_ptr, NULL);
319+ ASSERT_MEM_NE(allocated_ptr, 0, size);
320+
321+ ASSERT_EQ(new_rgn->size, size);
322+ ASSERT_EQ(new_rgn->base, req_node->base);
323+ ASSERT_LE(region_end(new_rgn), region_end(req_node));
324+
325+ ASSERT_EQ(memblock.reserved.cnt, 1);
326+ ASSERT_EQ(memblock.reserved.total_size, size);
327+
328+ test_pass_pop();
329+
330+ return 0;
331+}
332+
333+/*
334+ * A test that tries to allocate a memory region in a specific NUMA node that
335+ * is partially reserved but has enough memory for the allocated region:
336+ *
337+ * | +---------------------------------------+ |
338+ * | | requested | |
339+ * +-----------+---------------------------------------+---------+
340+ *
341+ * | +------------------+-----+ |
342+ * | | reserved | new | |
343+ * +-----------+------------------+-----+------------------------+
344+ *
345+ * Expect to allocate an aligned region in the requested node that merges with
346+ * the existing reserved region. The total size gets updated.
347+ */
348+static int alloc_exact_nid_bottom_up_numa_part_reserved_check(void)
349+{
350+ int nid_req = 4;
351+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
352+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
353+ void *allocated_ptr = NULL;
354+ struct region r1;
355+ phys_addr_t size;
356+ phys_addr_t min_addr;
357+ phys_addr_t max_addr;
358+ phys_addr_t total_size;
359+
360+ PREFIX_PUSH();
361+ setup_numa_memblock(node_fractions);
362+
363+ ASSERT_LE(SZ_8, req_node->size);
364+ r1.base = req_node->base;
365+ r1.size = req_node->size / SZ_2;
366+ size = r1.size / SZ_4;
367+ min_addr = memblock_start_of_DRAM();
368+ max_addr = memblock_end_of_DRAM();
369+ total_size = size + r1.size;
370+
371+ memblock_reserve(r1.base, r1.size);
372+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
373+ min_addr, max_addr,
374+ nid_req);
375+
376+ ASSERT_NE(allocated_ptr, NULL);
377+ ASSERT_MEM_NE(allocated_ptr, 0, size);
378+
379+ ASSERT_EQ(new_rgn->size, total_size);
380+ ASSERT_EQ(new_rgn->base, req_node->base);
381+ ASSERT_LE(region_end(new_rgn), region_end(req_node));
382+
383+ ASSERT_EQ(memblock.reserved.cnt, 1);
384+ ASSERT_EQ(memblock.reserved.total_size, total_size);
385+
386+ test_pass_pop();
387+
388+ return 0;
389+}
390+
391+/*
392+ * A test that tries to allocate a memory region that spans over the min_addr
393+ * and max_addr range and overlaps with two different nodes, where the first
394+ * node is the requested node:
395+ *
396+ * min_addr
397+ * | max_addr
398+ * | |
399+ * v v
400+ * | +-----------------------+-----------+ |
401+ * | | requested | node3 | |
402+ * +-----------+-----------------------+-----------+--------------+
403+ * + +
404+ * | +-----------+ |
405+ * | | rgn | |
406+ * +-----------+-----------+--------------------------------------+
407+ *
408+ * Expect to drop the lower limit and allocate a memory region at the beginning
409+ * of the requested node.
410+ */
411+static int alloc_exact_nid_bottom_up_numa_split_range_low_check(void)
412+{
413+ int nid_req = 2;
414+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
415+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
416+ void *allocated_ptr = NULL;
417+ phys_addr_t size = SZ_512;
418+ phys_addr_t min_addr;
419+ phys_addr_t max_addr;
420+ phys_addr_t req_node_end;
421+
422+ PREFIX_PUSH();
423+ setup_numa_memblock(node_fractions);
424+
425+ req_node_end = region_end(req_node);
426+ min_addr = req_node_end - SZ_256;
427+ max_addr = min_addr + size;
428+
429+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
430+ min_addr, max_addr,
431+ nid_req);
432+
433+ ASSERT_NE(allocated_ptr, NULL);
434+ ASSERT_MEM_NE(allocated_ptr, 0, size);
435+
436+ ASSERT_EQ(new_rgn->size, size);
437+ ASSERT_EQ(new_rgn->base, req_node->base);
438+ ASSERT_LE(region_end(new_rgn), req_node_end);
439+
440+ ASSERT_EQ(memblock.reserved.cnt, 1);
441+ ASSERT_EQ(memblock.reserved.total_size, size);
442+
443+ test_pass_pop();
444+
445+ return 0;
446+}
447+
448+/*
449+ * A test that tries to allocate a memory region that spans over the min_addr
450+ * and max_addr range and overlaps with two different nodes, where the requested
451+ * node ends before min_addr:
452+ *
453+ * min_addr
454+ * | max_addr
455+ * | |
456+ * v v
457+ * | +---------------+ +-------------+---------+ |
458+ * | | requested | | node1 | node2 | |
459+ * +----+---------------+--------+-------------+---------+---------+
460+ * + +
461+ * | +---------+ |
462+ * | | rgn | |
463+ * +----+---------+------------------------------------------------+
464+ *
465+ * Expect to drop the lower limit and allocate a memory region that starts at
466+ * the beginning of the requested node.
467+ */
468+static int alloc_exact_nid_bottom_up_numa_no_overlap_split_check(void)
469+{
470+ int nid_req = 2;
471+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
472+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
473+ struct memblock_region *node2 = &memblock.memory.regions[6];
474+ void *allocated_ptr = NULL;
475+ phys_addr_t size;
476+ phys_addr_t min_addr;
477+ phys_addr_t max_addr;
478+
479+ PREFIX_PUSH();
480+ setup_numa_memblock(node_fractions);
481+
482+ size = SZ_512;
483+ min_addr = node2->base - SZ_256;
484+ max_addr = min_addr + size;
485+
486+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
487+ min_addr, max_addr,
488+ nid_req);
489+
490+ ASSERT_NE(allocated_ptr, NULL);
491+ ASSERT_MEM_NE(allocated_ptr, 0, size);
492+
493+ ASSERT_EQ(new_rgn->size, size);
494+ ASSERT_EQ(new_rgn->base, req_node->base);
495+ ASSERT_LE(region_end(new_rgn), region_end(req_node));
496+
497+ ASSERT_EQ(memblock.reserved.cnt, 1);
498+ ASSERT_EQ(memblock.reserved.total_size, size);
499+
500+ test_pass_pop();
501+
502+ return 0;
503+}
504+
505+/*
506+ * A test that tries to allocate memory within min_addr and max_add range when
507+ * the requested node and the range do not overlap, and requested node ends
508+ * before min_addr. The range overlaps with multiple nodes along node
509+ * boundaries:
510+ *
511+ * min_addr
512+ * | max_addr
513+ * | |
514+ * v v
515+ * |-----------+ +----------+----...----+----------+ |
516+ * | requested | | min node | ... | max node | |
517+ * +-----------+-----------+----------+----...----+----------+------+
518+ * + +
519+ * |-----+ |
520+ * | rgn | |
521+ * +-----+----------------------------------------------------------+
522+ *
523+ * Expect to drop the lower limit and allocate a memory region that starts at
524+ * the beginning of the requested node.
525+ */
526+static int alloc_exact_nid_bottom_up_numa_no_overlap_low_check(void)
527+{
528+ int nid_req = 0;
529+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
530+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
531+ struct memblock_region *min_node = &memblock.memory.regions[2];
532+ struct memblock_region *max_node = &memblock.memory.regions[5];
533+ void *allocated_ptr = NULL;
534+ phys_addr_t size = SZ_64;
535+ phys_addr_t max_addr;
536+ phys_addr_t min_addr;
537+
538+ PREFIX_PUSH();
539+ setup_numa_memblock(node_fractions);
540+
541+ min_addr = min_node->base;
542+ max_addr = region_end(max_node);
543+
544+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
545+ min_addr, max_addr,
546+ nid_req);
547+
548+ ASSERT_NE(allocated_ptr, NULL);
549+ ASSERT_MEM_NE(allocated_ptr, 0, size);
550+
551+ ASSERT_EQ(new_rgn->size, size);
552+ ASSERT_EQ(new_rgn->base, req_node->base);
553+ ASSERT_LE(region_end(new_rgn), region_end(req_node));
554+
555+ ASSERT_EQ(memblock.reserved.cnt, 1);
556+ ASSERT_EQ(memblock.reserved.total_size, size);
557+
558+ test_pass_pop();
559+
560+ return 0;
561+}
562+
563+/*
564+ * A test that tries to allocate a memory region in a specific NUMA node that
565+ * does not have enough memory to allocate a region of the requested size:
566+ *
567+ * | +-----+ |
568+ * | | req | |
569+ * +---+-----+----------------------------+
570+ *
571+ * +---------+
572+ * | rgn |
573+ * +---------+
574+ *
575+ * Expect no allocation to happen.
576+ */
577+static int alloc_exact_nid_numa_small_node_generic_check(void)
578+{
579+ int nid_req = 1;
580+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
581+ void *allocated_ptr = NULL;
582+ phys_addr_t size;
583+ phys_addr_t min_addr;
584+ phys_addr_t max_addr;
585+
586+ PREFIX_PUSH();
587+ setup_numa_memblock(node_fractions);
588+
589+ size = SZ_2 * req_node->size;
590+ min_addr = memblock_start_of_DRAM();
591+ max_addr = memblock_end_of_DRAM();
592+
593+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
594+ min_addr, max_addr,
595+ nid_req);
596+
597+ ASSERT_EQ(allocated_ptr, NULL);
598+
599+ test_pass_pop();
600+
601+ return 0;
602+}
603+
604+/*
605+ * A test that tries to allocate a memory region in a specific NUMA node that
606+ * is fully reserved:
607+ *
608+ * | +---------+ |
609+ * | |requested| |
610+ * +--------------+---------+-------------+
611+ *
612+ * | +---------+ |
613+ * | | reserved| |
614+ * +--------------+---------+-------------+
615+ *
616+ * Expect no allocation to happen.
617+ */
618+static int alloc_exact_nid_numa_node_reserved_generic_check(void)
619+{
620+ int nid_req = 2;
621+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
622+ void *allocated_ptr = NULL;
623+ phys_addr_t size;
624+ phys_addr_t min_addr;
625+ phys_addr_t max_addr;
626+
627+ PREFIX_PUSH();
628+ setup_numa_memblock(node_fractions);
629+
630+ size = req_node->size;
631+ min_addr = memblock_start_of_DRAM();
632+ max_addr = memblock_end_of_DRAM();
633+
634+ memblock_reserve(req_node->base, req_node->size);
635+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
636+ min_addr, max_addr,
637+ nid_req);
638+
639+ ASSERT_EQ(allocated_ptr, NULL);
640+
641+ test_pass_pop();
642+
643+ return 0;
644+}
645+
646+/*
647+ * A test that tries to allocate a memory region in a specific NUMA node that
648+ * is partially reserved and does not have enough contiguous memory for the
649+ * allocated region:
650+ *
651+ * | +-----------------------+ |
652+ * | | requested | |
653+ * +-----------+-----------------------+----+
654+ *
655+ * | +----------+ |
656+ * | | reserved | |
657+ * +-----------------+----------+-----------+
658+ *
659+ * Expect no allocation to happen.
660+ */
661+static int alloc_exact_nid_numa_part_reserved_fail_generic_check(void)
662+{
663+ int nid_req = 4;
664+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
665+ void *allocated_ptr = NULL;
666+ struct region r1;
667+ phys_addr_t size;
668+ phys_addr_t min_addr;
669+ phys_addr_t max_addr;
670+
671+ PREFIX_PUSH();
672+ setup_numa_memblock(node_fractions);
673+
674+ ASSERT_LE(SZ_4, req_node->size);
675+ size = req_node->size / SZ_2;
676+ r1.base = req_node->base + (size / SZ_2);
677+ r1.size = size;
678+
679+ min_addr = memblock_start_of_DRAM();
680+ max_addr = memblock_end_of_DRAM();
681+
682+ memblock_reserve(r1.base, r1.size);
683+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
684+ min_addr, max_addr,
685+ nid_req);
686+
687+ ASSERT_EQ(allocated_ptr, NULL);
688+
689+ test_pass_pop();
690+
691+ return 0;
692+}
693+
694+/*
695+ * A test that tries to allocate a memory region that spans over the min_addr
696+ * and max_addr range and overlaps with two different nodes, where the second
697+ * node is the requested node:
698+ *
699+ * min_addr
700+ * | max_addr
701+ * | |
702+ * v v
703+ * | +--------------------------+---------+ |
704+ * | | first node |requested| |
705+ * +------+--------------------------+---------+----------------+
706+ *
707+ * Expect no allocation to happen.
708+ */
709+static int alloc_exact_nid_numa_split_range_high_generic_check(void)
710+{
711+ int nid_req = 3;
712+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
713+ void *allocated_ptr = NULL;
714+ phys_addr_t size = SZ_512;
715+ phys_addr_t min_addr;
716+ phys_addr_t max_addr;
717+
718+ PREFIX_PUSH();
719+ setup_numa_memblock(node_fractions);
720+
721+ min_addr = req_node->base - SZ_256;
722+ max_addr = min_addr + size;
723+
724+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
725+ min_addr, max_addr,
726+ nid_req);
727+
728+ ASSERT_EQ(allocated_ptr, NULL);
729+
730+ test_pass_pop();
731+
732+ return 0;
733+}
734+
735+/*
736+ * A test that tries to allocate memory within min_addr and max_add range when
737+ * the requested node and the range do not overlap, and requested node starts
738+ * after max_addr. The range overlaps with multiple nodes along node
739+ * boundaries:
740+ *
741+ * min_addr
742+ * | max_addr
743+ * | |
744+ * v v
745+ * | +----------+----...----+----------+ +-----------+ |
746+ * | | min node | ... | max node | | requested | |
747+ * +-----+----------+----...----+----------+--------+-----------+---+
748+ *
749+ * Expect no allocation to happen.
750+ */
751+static int alloc_exact_nid_numa_no_overlap_high_generic_check(void)
752+{
753+ int nid_req = 7;
754+ struct memblock_region *min_node = &memblock.memory.regions[2];
755+ struct memblock_region *max_node = &memblock.memory.regions[5];
756+ void *allocated_ptr = NULL;
757+ phys_addr_t size = SZ_64;
758+ phys_addr_t max_addr;
759+ phys_addr_t min_addr;
760+
761+ PREFIX_PUSH();
762+ setup_numa_memblock(node_fractions);
763+
764+ min_addr = min_node->base;
765+ max_addr = region_end(max_node);
766+
767+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
768+ min_addr, max_addr,
769+ nid_req);
770+
771+ ASSERT_EQ(allocated_ptr, NULL);
772+
773+ test_pass_pop();
774+
775+ return 0;
776+}
777+
778+/*
779+ * A test that tries to allocate a memory region in a specific NUMA node that
780+ * does not have enough memory to allocate a region of the requested size.
781+ * Additionally, none of the nodes have enough memory to allocate the region:
782+ *
783+ * +-----------------------------------+
784+ * | new |
785+ * +-----------------------------------+
786+ * |-------+-------+-------+-------+-------+-------+-------+-------|
787+ * | node0 | node1 | node2 | node3 | node4 | node5 | node6 | node7 |
788+ * +-------+-------+-------+-------+-------+-------+-------+-------+
789+ *
790+ * Expect no allocation to happen.
791+ */
792+static int alloc_exact_nid_numa_large_region_generic_check(void)
793+{
794+ int nid_req = 3;
795+ void *allocated_ptr = NULL;
796+ phys_addr_t size = MEM_SIZE / SZ_2;
797+ phys_addr_t min_addr;
798+ phys_addr_t max_addr;
799+
800+ PREFIX_PUSH();
801+ setup_numa_memblock(node_fractions);
802+
803+ min_addr = memblock_start_of_DRAM();
804+ max_addr = memblock_end_of_DRAM();
805+
806+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
807+ min_addr, max_addr,
808+ nid_req);
809+ ASSERT_EQ(allocated_ptr, NULL);
810+
811+ test_pass_pop();
812+
813+ return 0;
814+}
815+
816+/*
817+ * A test that tries to allocate memory within min_addr and max_addr range when
818+ * there are two reserved regions at the borders. The requested node starts at
819+ * min_addr and ends at max_addr and is the same size as the region to be
820+ * allocated:
821+ *
822+ * min_addr
823+ * | max_addr
824+ * | |
825+ * v v
826+ * | +-----------+-----------------------+-----------------------|
827+ * | | node5 | requested | node7 |
828+ * +------+-----------+-----------------------+-----------------------+
829+ * + +
830+ * | +----+-----------------------+----+ |
831+ * | | r2 | new | r1 | |
832+ * +-------------+----+-----------------------+----+------------------+
833+ *
834+ * Expect to merge all of the regions into one. The region counter and total
835+ * size fields get updated.
836+ */
837+static int alloc_exact_nid_numa_reserved_full_merge_generic_check(void)
838+{
839+ int nid_req = 6;
840+ int nid_next = nid_req + 1;
841+ struct memblock_region *new_rgn = &memblock.reserved.regions[0];
842+ struct memblock_region *req_node = &memblock.memory.regions[nid_req];
843+ struct memblock_region *next_node = &memblock.memory.regions[nid_next];
844+ void *allocated_ptr = NULL;
845+ struct region r1, r2;
846+ phys_addr_t size = req_node->size;
847+ phys_addr_t total_size;
848+ phys_addr_t max_addr;
849+ phys_addr_t min_addr;
850+
851+ PREFIX_PUSH();
852+ setup_numa_memblock(node_fractions);
853+
854+ r1.base = next_node->base;
855+ r1.size = SZ_128;
856+
857+ r2.size = SZ_128;
858+ r2.base = r1.base - (size + r2.size);
859+
860+ total_size = r1.size + r2.size + size;
861+ min_addr = r2.base + r2.size;
862+ max_addr = r1.base;
863+
864+ memblock_reserve(r1.base, r1.size);
865+ memblock_reserve(r2.base, r2.size);
866+
867+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
868+ min_addr, max_addr,
869+ nid_req);
870+
871+ ASSERT_NE(allocated_ptr, NULL);
872+ ASSERT_MEM_NE(allocated_ptr, 0, size);
873+
874+ ASSERT_EQ(new_rgn->size, total_size);
875+ ASSERT_EQ(new_rgn->base, r2.base);
876+
877+ ASSERT_LE(new_rgn->base, req_node->base);
878+ ASSERT_LE(region_end(req_node), region_end(new_rgn));
879+
880+ ASSERT_EQ(memblock.reserved.cnt, 1);
881+ ASSERT_EQ(memblock.reserved.total_size, total_size);
882+
883+ test_pass_pop();
884+
885+ return 0;
886+}
887+
888+/*
889+ * A test that tries to allocate memory within min_addr and max_add range,
890+ * where the total range can fit the region, but it is split between two nodes
891+ * and everything else is reserved. Additionally, nid is set to NUMA_NO_NODE
892+ * instead of requesting a specific node:
893+ *
894+ * +-----------+
895+ * | new |
896+ * +-----------+
897+ * | +---------------------+-----------|
898+ * | | prev node | next node |
899+ * +------+---------------------+-----------+
900+ * + +
901+ * |----------------------+ +-----|
902+ * | r1 | | r2 |
903+ * +----------------------+-----------+-----+
904+ * ^ ^
905+ * | |
906+ * | max_addr
907+ * |
908+ * min_addr
909+ *
910+ * Expect no allocation to happen.
911+ */
912+static int alloc_exact_nid_numa_split_all_reserved_generic_check(void)
913+{
914+ void *allocated_ptr = NULL;
915+ struct memblock_region *next_node = &memblock.memory.regions[7];
916+ struct region r1, r2;
917+ phys_addr_t size = SZ_256;
918+ phys_addr_t max_addr;
919+ phys_addr_t min_addr;
920+
921+ PREFIX_PUSH();
922+ setup_numa_memblock(node_fractions);
923+
924+ r2.base = next_node->base + SZ_128;
925+ r2.size = memblock_end_of_DRAM() - r2.base;
926+
927+ r1.size = MEM_SIZE - (r2.size + size);
928+ r1.base = memblock_start_of_DRAM();
929+
930+ min_addr = r1.base + r1.size;
931+ max_addr = r2.base;
932+
933+ memblock_reserve(r1.base, r1.size);
934+ memblock_reserve(r2.base, r2.size);
935+
936+ allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
937+ min_addr, max_addr,
938+ NUMA_NO_NODE);
939+
940+ ASSERT_EQ(allocated_ptr, NULL);
941+
942+ test_pass_pop();
943+
944+ return 0;
945+}
946+
947+/* Test case wrappers for NUMA tests */
948+static int alloc_exact_nid_numa_simple_check(void)
949+{
950+ test_print("\tRunning %s...\n", __func__);
951+ memblock_set_bottom_up(false);
952+ alloc_exact_nid_top_down_numa_simple_check();
953+ memblock_set_bottom_up(true);
954+ alloc_exact_nid_bottom_up_numa_simple_check();
955+
956+ return 0;
957+}
958+
959+static int alloc_exact_nid_numa_part_reserved_check(void)
960+{
961+ test_print("\tRunning %s...\n", __func__);
962+ memblock_set_bottom_up(false);
963+ alloc_exact_nid_top_down_numa_part_reserved_check();
964+ memblock_set_bottom_up(true);
965+ alloc_exact_nid_bottom_up_numa_part_reserved_check();
966+
967+ return 0;
968+}
969+
970+static int alloc_exact_nid_numa_split_range_low_check(void)
971+{
972+ test_print("\tRunning %s...\n", __func__);
973+ memblock_set_bottom_up(false);
974+ alloc_exact_nid_top_down_numa_split_range_low_check();
975+ memblock_set_bottom_up(true);
976+ alloc_exact_nid_bottom_up_numa_split_range_low_check();
977+
978+ return 0;
979+}
980+
981+static int alloc_exact_nid_numa_no_overlap_split_check(void)
982+{
983+ test_print("\tRunning %s...\n", __func__);
984+ memblock_set_bottom_up(false);
985+ alloc_exact_nid_top_down_numa_no_overlap_split_check();
986+ memblock_set_bottom_up(true);
987+ alloc_exact_nid_bottom_up_numa_no_overlap_split_check();
988+
989+ return 0;
990+}
991+
992+static int alloc_exact_nid_numa_no_overlap_low_check(void)
993+{
994+ test_print("\tRunning %s...\n", __func__);
995+ memblock_set_bottom_up(false);
996+ alloc_exact_nid_top_down_numa_no_overlap_low_check();
997+ memblock_set_bottom_up(true);
998+ alloc_exact_nid_bottom_up_numa_no_overlap_low_check();
999+
1000+ return 0;
1001+}
1002+
1003+static int alloc_exact_nid_numa_small_node_check(void)
1004+{
1005+ test_print("\tRunning %s...\n", __func__);
1006+ run_top_down(alloc_exact_nid_numa_small_node_generic_check);
1007+ run_bottom_up(alloc_exact_nid_numa_small_node_generic_check);
1008+
1009+ return 0;
1010+}
1011+
1012+static int alloc_exact_nid_numa_node_reserved_check(void)
1013+{
1014+ test_print("\tRunning %s...\n", __func__);
1015+ run_top_down(alloc_exact_nid_numa_node_reserved_generic_check);
1016+ run_bottom_up(alloc_exact_nid_numa_node_reserved_generic_check);
1017+
1018+ return 0;
1019+}
1020+
1021+static int alloc_exact_nid_numa_part_reserved_fail_check(void)
1022+{
1023+ test_print("\tRunning %s...\n", __func__);
1024+ run_top_down(alloc_exact_nid_numa_part_reserved_fail_generic_check);
1025+ run_bottom_up(alloc_exact_nid_numa_part_reserved_fail_generic_check);
1026+
1027+ return 0;
1028+}
1029+
1030+static int alloc_exact_nid_numa_split_range_high_check(void)
1031+{
1032+ test_print("\tRunning %s...\n", __func__);
1033+ run_top_down(alloc_exact_nid_numa_split_range_high_generic_check);
1034+ run_bottom_up(alloc_exact_nid_numa_split_range_high_generic_check);
1035+
1036+ return 0;
1037+}
1038+
1039+static int alloc_exact_nid_numa_no_overlap_high_check(void)
1040+{
1041+ test_print("\tRunning %s...\n", __func__);
1042+ run_top_down(alloc_exact_nid_numa_no_overlap_high_generic_check);
1043+ run_bottom_up(alloc_exact_nid_numa_no_overlap_high_generic_check);
1044+
1045+ return 0;
1046+}
1047+
1048+static int alloc_exact_nid_numa_large_region_check(void)
1049+{
1050+ test_print("\tRunning %s...\n", __func__);
1051+ run_top_down(alloc_exact_nid_numa_large_region_generic_check);
1052+ run_bottom_up(alloc_exact_nid_numa_large_region_generic_check);
1053+
1054+ return 0;
1055+}
1056+
1057+static int alloc_exact_nid_numa_reserved_full_merge_check(void)
1058+{
1059+ test_print("\tRunning %s...\n", __func__);
1060+ run_top_down(alloc_exact_nid_numa_reserved_full_merge_generic_check);
1061+ run_bottom_up(alloc_exact_nid_numa_reserved_full_merge_generic_check);
1062+
1063+ return 0;
1064+}
1065+
1066+static int alloc_exact_nid_numa_split_all_reserved_check(void)
1067+{
1068+ test_print("\tRunning %s...\n", __func__);
1069+ run_top_down(alloc_exact_nid_numa_split_all_reserved_generic_check);
1070+ run_bottom_up(alloc_exact_nid_numa_split_all_reserved_generic_check);
1071+
1072+ return 0;
1073+}
1074+
1075+int __memblock_alloc_exact_nid_numa_checks(void)
1076+{
1077+ test_print("Running %s NUMA tests...\n", FUNC_NAME);
1078+
1079+ alloc_exact_nid_numa_simple_check();
1080+ alloc_exact_nid_numa_part_reserved_check();
1081+ alloc_exact_nid_numa_split_range_low_check();
1082+ alloc_exact_nid_numa_no_overlap_split_check();
1083+ alloc_exact_nid_numa_no_overlap_low_check();
1084+
1085+ alloc_exact_nid_numa_small_node_check();
1086+ alloc_exact_nid_numa_node_reserved_check();
1087+ alloc_exact_nid_numa_part_reserved_fail_check();
1088+ alloc_exact_nid_numa_split_range_high_check();
1089+ alloc_exact_nid_numa_no_overlap_high_check();
1090+ alloc_exact_nid_numa_large_region_check();
1091+ alloc_exact_nid_numa_reserved_full_merge_check();
1092+ alloc_exact_nid_numa_split_all_reserved_check();
1093+
1094+ return 0;
1095+}
1096+
1097+int memblock_alloc_exact_nid_checks(void)
1098+{
1099+ prefix_reset();
1100+ prefix_push(FUNC_NAME);
1101+
1102+ reset_memblock_attributes();
1103+ dummy_physical_memory_init();
1104+
1105+ memblock_alloc_exact_nid_range_checks();
1106+ memblock_alloc_exact_nid_numa_checks();
1107+
1108+ dummy_physical_memory_cleanup();
1109+
1110+ prefix_pop();
1111+
1112+ return 0;
1113+}
tools/testing/memblock/tests/alloc_exact_nid_api.h+25−0
@@ -0,0 +1,25 @@
1+/* SPDX-License-Identifier: GPL-2.0-or-later */
2+#ifndef _MEMBLOCK_ALLOC_EXACT_NID_H
3+#define _MEMBLOCK_ALLOC_EXACT_NID_H
4+
5+#include "common.h"
6+
7+int memblock_alloc_exact_nid_checks(void);
8+int __memblock_alloc_exact_nid_numa_checks(void);
9+
10+#ifdef CONFIG_NUMA
11+static inline int memblock_alloc_exact_nid_numa_checks(void)
12+{
13+ __memblock_alloc_exact_nid_numa_checks();
14+ return 0;
15+}
16+
17+#else
18+static inline int memblock_alloc_exact_nid_numa_checks(void)
19+{
20+ return 0;
21+}
22+
23+#endif /* CONFIG_NUMA */
24+
25+#endif
tools/testing/memblock/tests/alloc_nid_api.c+283−263
@@ -18,18 +18,29 @@ static const unsigned int node_fractions[] = { · 17 unmodified lines
1818 625, /* 1/16 */
1919 };
2020
21−static inline const char * const get_memblock_alloc_try_nid_name(int flags)
21+static inline const char * const get_memblock_alloc_nid_name(int flags)
2222 {
23+ if (flags & TEST_F_EXACT)
24+ return "memblock_alloc_exact_nid_raw";
2325 if (flags & TEST_F_RAW)
2426 return "memblock_alloc_try_nid_raw";
2527 return "memblock_alloc_try_nid";
2628 }
2729
28−static inline void *run_memblock_alloc_try_nid(phys_addr_t size,
29− phys_addr_t align,
30− phys_addr_t min_addr,
31− phys_addr_t max_addr, int nid)
32−{
30+static inline void *run_memblock_alloc_nid(phys_addr_t size,
31+ phys_addr_t align,
32+ phys_addr_t min_addr,
33+ phys_addr_t max_addr, int nid)
34+{
35+ assert(!(alloc_nid_test_flags & TEST_F_EXACT) ||
36+ (alloc_nid_test_flags & TEST_F_RAW));
37+ /*
38+ * TEST_F_EXACT should be checked before TEST_F_RAW since
39+ * memblock_alloc_exact_nid_raw() performs raw allocations.
40+ */
41+ if (alloc_nid_test_flags & TEST_F_EXACT)
42+ return memblock_alloc_exact_nid_raw(size, align, min_addr,
43+ max_addr, nid);
3344 if (alloc_nid_test_flags & TEST_F_RAW)
3445 return memblock_alloc_try_nid_raw(size, align, min_addr,
3546 max_addr, nid);
@@ -50,7 +61,7 @@ static inline void *run_memblock_alloc_try_nid(phys_addr_t size, · 14 unmodified lines
5061 *
5162 * Expect to allocate a region that ends at max_addr.
5263 */
53−static int alloc_try_nid_top_down_simple_check(void)
64+static int alloc_nid_top_down_simple_check(void)
5465 {
5566 struct memblock_region *rgn = &memblock.reserved.regions[0];
5667 void *allocated_ptr = NULL;
@@ -65,9 +76,9 @@ static int alloc_try_nid_top_down_simple_check(void) · 8 unmodified lines
6576 min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
6677 max_addr = min_addr + SZ_512;
6778
68− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
69− min_addr, max_addr,
70− NUMA_NO_NODE);
79+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
80+ min_addr, max_addr,
81+ NUMA_NO_NODE);
7182 rgn_end = rgn->base + rgn->size;
7283
7384 ASSERT_NE(allocated_ptr, NULL);
@@ -102,7 +113,7 @@ static int alloc_try_nid_top_down_simple_check(void) · 28 unmodified lines
102113 *
103114 * Expect to allocate an aligned region that ends before max_addr.
104115 */
105−static int alloc_try_nid_top_down_end_misaligned_check(void)
116+static int alloc_nid_top_down_end_misaligned_check(void)
106117 {
107118 struct memblock_region *rgn = &memblock.reserved.regions[0];
108119 void *allocated_ptr = NULL;
@@ -118,9 +129,9 @@ static int alloc_try_nid_top_down_end_misaligned_check(void) · 9 unmodified lines
118129 min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
119130 max_addr = min_addr + SZ_512 + misalign;
120131
121− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
122− min_addr, max_addr,
123− NUMA_NO_NODE);
132+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
133+ min_addr, max_addr,
134+ NUMA_NO_NODE);
124135 rgn_end = rgn->base + rgn->size;
125136
126137 ASSERT_NE(allocated_ptr, NULL);
@@ -153,7 +164,7 @@ static int alloc_try_nid_top_down_end_misaligned_check(void) · 26 unmodified lines
153164 * Expect to allocate a region that starts at min_addr and ends at
154165 * max_addr, given that min_addr is aligned.
155166 */
156−static int alloc_try_nid_exact_address_generic_check(void)
167+static int alloc_nid_exact_address_generic_check(void)
157168 {
158169 struct memblock_region *rgn = &memblock.reserved.regions[0];
159170 void *allocated_ptr = NULL;
@@ -168,9 +179,9 @@ static int alloc_try_nid_exact_address_generic_check(void) · 8 unmodified lines
168179 min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES;
169180 max_addr = min_addr + size;
170181
171− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
172− min_addr, max_addr,
173− NUMA_NO_NODE);
182+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
183+ min_addr, max_addr,
184+ NUMA_NO_NODE);
174185 rgn_end = rgn->base + rgn->size;
175186
176187 ASSERT_NE(allocated_ptr, NULL);
@@ -205,7 +216,7 @@ static int alloc_try_nid_exact_address_generic_check(void) · 28 unmodified lines
205216 * Expect to drop the lower limit and allocate a memory region which
206217 * ends at max_addr (if the address is aligned).
207218 */
208−static int alloc_try_nid_top_down_narrow_range_check(void)
219+static int alloc_nid_top_down_narrow_range_check(void)
209220 {
210221 struct memblock_region *rgn = &memblock.reserved.regions[0];
211222 void *allocated_ptr = NULL;
@@ -219,9 +230,9 @@ static int alloc_try_nid_top_down_narrow_range_check(void) · 7 unmodified lines
219230 min_addr = memblock_start_of_DRAM() + SZ_512;
220231 max_addr = min_addr + SMP_CACHE_BYTES;
221232
222− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
223− min_addr, max_addr,
224− NUMA_NO_NODE);
233+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
234+ min_addr, max_addr,
235+ NUMA_NO_NODE);
225236
226237 ASSERT_NE(allocated_ptr, NULL);
227238 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -257,7 +268,7 @@ static int alloc_try_nid_top_down_narrow_range_check(void) · 29 unmodified lines
257268 *
258269 * Expect no allocation to happen.
259270 */
260−static int alloc_try_nid_low_max_generic_check(void)
271+static int alloc_nid_low_max_generic_check(void)
261272 {
262273 void *allocated_ptr = NULL;
263274 phys_addr_t size = SZ_1K;
@@ -270,9 +281,9 @@ static int alloc_try_nid_low_max_generic_check(void) · 6 unmodified lines
270281 min_addr = memblock_start_of_DRAM();
271282 max_addr = min_addr + SMP_CACHE_BYTES;
272283
273− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
274− min_addr, max_addr,
275− NUMA_NO_NODE);
284+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
285+ min_addr, max_addr,
286+ NUMA_NO_NODE);
276287
277288 ASSERT_EQ(allocated_ptr, NULL);
278289
@@ -295,7 +306,7 @@ static int alloc_try_nid_low_max_generic_check(void) · 16 unmodified lines
295306 *
296307 * Expect a merge of both regions. Only the region size gets updated.
297308 */
298−static int alloc_try_nid_min_reserved_generic_check(void)
309+static int alloc_nid_min_reserved_generic_check(void)
299310 {
300311 struct memblock_region *rgn = &memblock.reserved.regions[0];
301312 void *allocated_ptr = NULL;
@@ -315,9 +326,9 @@ static int alloc_try_nid_min_reserved_generic_check(void) · 13 unmodified lines
315326
316327 memblock_reserve(reserved_base, r1_size);
317328
318− allocated_ptr = run_memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES,
319− min_addr, max_addr,
320− NUMA_NO_NODE);
329+ allocated_ptr = run_memblock_alloc_nid(r2_size, SMP_CACHE_BYTES,
330+ min_addr, max_addr,
331+ NUMA_NO_NODE);
321332
322333 ASSERT_NE(allocated_ptr, NULL);
323334 assert_mem_content(allocated_ptr, r2_size, alloc_nid_test_flags);
@@ -347,7 +358,7 @@ static int alloc_try_nid_min_reserved_generic_check(void) · 23 unmodified lines
347358 *
348359 * Expect a merge of regions. Only the region size gets updated.
349360 */
350−static int alloc_try_nid_max_reserved_generic_check(void)
361+static int alloc_nid_max_reserved_generic_check(void)
351362 {
352363 struct memblock_region *rgn = &memblock.reserved.regions[0];
353364 void *allocated_ptr = NULL;
@@ -365,9 +376,9 @@ static int alloc_try_nid_max_reserved_generic_check(void) · 11 unmodified lines
365376
366377 memblock_reserve(max_addr, r1_size);
367378
368− allocated_ptr = run_memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES,
369− min_addr, max_addr,
370− NUMA_NO_NODE);
379+ allocated_ptr = run_memblock_alloc_nid(r2_size, SMP_CACHE_BYTES,
380+ min_addr, max_addr,
381+ NUMA_NO_NODE);
371382
372383 ASSERT_NE(allocated_ptr, NULL);
373384 assert_mem_content(allocated_ptr, r2_size, alloc_nid_test_flags);
@@ -400,7 +411,7 @@ static int alloc_try_nid_max_reserved_generic_check(void) · 26 unmodified lines
400411 * updated. The total size field gets updated.
401412 */
402413
403−static int alloc_try_nid_top_down_reserved_with_space_check(void)
414+static int alloc_nid_top_down_reserved_with_space_check(void)
404415 {
405416 struct memblock_region *rgn1 = &memblock.reserved.regions[1];
406417 struct memblock_region *rgn2 = &memblock.reserved.regions[0];
@@ -428,9 +439,9 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void) · 21 unmodified lines
428439 memblock_reserve(r1.base, r1.size);
429440 memblock_reserve(r2.base, r2.size);
430441
431− allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
432− min_addr, max_addr,
433− NUMA_NO_NODE);
442+ allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
443+ min_addr, max_addr,
444+ NUMA_NO_NODE);
434445
435446 ASSERT_NE(allocated_ptr, NULL);
436447 assert_mem_content(allocated_ptr, r3_size, alloc_nid_test_flags);
@@ -465,7 +476,7 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void) · 28 unmodified lines
465476 * Expect to merge all of the regions into one. The region counter and total
466477 * size fields get updated.
467478 */
468−static int alloc_try_nid_reserved_full_merge_generic_check(void)
479+static int alloc_nid_reserved_full_merge_generic_check(void)
469480 {
470481 struct memblock_region *rgn = &memblock.reserved.regions[0];
471482 void *allocated_ptr = NULL;
@@ -491,9 +502,9 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void) · 19 unmodified lines
491502 memblock_reserve(r1.base, r1.size);
492503 memblock_reserve(r2.base, r2.size);
493504
494− allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
495− min_addr, max_addr,
496− NUMA_NO_NODE);
505+ allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
506+ min_addr, max_addr,
507+ NUMA_NO_NODE);
497508
498509 ASSERT_NE(allocated_ptr, NULL);
499510 assert_mem_content(allocated_ptr, r3_size, alloc_nid_test_flags);
@@ -527,7 +538,7 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void) · 27 unmodified lines
527538 * Expect to merge the new region with r2. The second region does not get
528539 * updated. The total size counter gets updated.
529540 */
530−static int alloc_try_nid_top_down_reserved_no_space_check(void)
541+static int alloc_nid_top_down_reserved_no_space_check(void)
531542 {
532543 struct memblock_region *rgn1 = &memblock.reserved.regions[1];
533544 struct memblock_region *rgn2 = &memblock.reserved.regions[0];
@@ -555,9 +566,9 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void) · 21 unmodified lines
555566 memblock_reserve(r1.base, r1.size);
556567 memblock_reserve(r2.base, r2.size);
557568
558− allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
559− min_addr, max_addr,
560− NUMA_NO_NODE);
569+ allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
570+ min_addr, max_addr,
571+ NUMA_NO_NODE);
561572
562573 ASSERT_NE(allocated_ptr, NULL);
563574 assert_mem_content(allocated_ptr, r3_size, alloc_nid_test_flags);
@@ -596,7 +607,7 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void) · 32 unmodified lines
596607 * Expect no allocation to happen.
597608 */
598609
599−static int alloc_try_nid_reserved_all_generic_check(void)
610+static int alloc_nid_reserved_all_generic_check(void)
600611 {
601612 void *allocated_ptr = NULL;
602613 struct region r1, r2;
@@ -620,9 +631,9 @@ static int alloc_try_nid_reserved_all_generic_check(void) · 17 unmodified lines
620631 memblock_reserve(r1.base, r1.size);
621632 memblock_reserve(r2.base, r2.size);
622633
623− allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
624− min_addr, max_addr,
625− NUMA_NO_NODE);
634+ allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
635+ min_addr, max_addr,
636+ NUMA_NO_NODE);
626637
627638 ASSERT_EQ(allocated_ptr, NULL);
628639
@@ -636,7 +647,7 @@ static int alloc_try_nid_reserved_all_generic_check(void) · 7 unmodified lines
636647 * bigger than the end address of the available memory. Expect to allocate
637648 * a region that ends before the end of the memory.
638649 */
639−static int alloc_try_nid_top_down_cap_max_check(void)
650+static int alloc_nid_top_down_cap_max_check(void)
640651 {
641652 struct memblock_region *rgn = &memblock.reserved.regions[0];
642653 void *allocated_ptr = NULL;
@@ -650,9 +661,9 @@ static int alloc_try_nid_top_down_cap_max_check(void) · 7 unmodified lines
650661 min_addr = memblock_end_of_DRAM() - SZ_1K;
651662 max_addr = memblock_end_of_DRAM() + SZ_256;
652663
653− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
654− min_addr, max_addr,
655− NUMA_NO_NODE);
664+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
665+ min_addr, max_addr,
666+ NUMA_NO_NODE);
656667
657668 ASSERT_NE(allocated_ptr, NULL);
658669 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -673,7 +684,7 @@ static int alloc_try_nid_top_down_cap_max_check(void) · 14 unmodified lines
673684 * smaller than the start address of the available memory. Expect to allocate
674685 * a region that ends before the end of the memory.
675686 */
676−static int alloc_try_nid_top_down_cap_min_check(void)
687+static int alloc_nid_top_down_cap_min_check(void)
677688 {
678689 struct memblock_region *rgn = &memblock.reserved.regions[0];
679690 void *allocated_ptr = NULL;
@@ -687,9 +698,9 @@ static int alloc_try_nid_top_down_cap_min_check(void) · 7 unmodified lines
687698 min_addr = memblock_start_of_DRAM() - SZ_256;
688699 max_addr = memblock_end_of_DRAM();
689700
690− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
691− min_addr, max_addr,
692− NUMA_NO_NODE);
701+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
702+ min_addr, max_addr,
703+ NUMA_NO_NODE);
693704
694705 ASSERT_NE(allocated_ptr, NULL);
695706 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -719,7 +730,7 @@ static int alloc_try_nid_top_down_cap_min_check(void) · 23 unmodified lines
719730 *
720731 * Expect to allocate a region that ends before max_addr.
721732 */
722−static int alloc_try_nid_bottom_up_simple_check(void)
733+static int alloc_nid_bottom_up_simple_check(void)
723734 {
724735 struct memblock_region *rgn = &memblock.reserved.regions[0];
725736 void *allocated_ptr = NULL;
@@ -734,9 +745,9 @@ static int alloc_try_nid_bottom_up_simple_check(void) · 8 unmodified lines
734745 min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
735746 max_addr = min_addr + SZ_512;
736747
737− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
738− min_addr, max_addr,
739− NUMA_NO_NODE);
748+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
749+ min_addr, max_addr,
750+ NUMA_NO_NODE);
740751 rgn_end = rgn->base + rgn->size;
741752
742753 ASSERT_NE(allocated_ptr, NULL);
@@ -771,7 +782,7 @@ static int alloc_try_nid_bottom_up_simple_check(void) · 28 unmodified lines
771782 *
772783 * Expect to allocate an aligned region that ends before max_addr.
773784 */
774−static int alloc_try_nid_bottom_up_start_misaligned_check(void)
785+static int alloc_nid_bottom_up_start_misaligned_check(void)
775786 {
776787 struct memblock_region *rgn = &memblock.reserved.regions[0];
777788 void *allocated_ptr = NULL;
@@ -787,9 +798,9 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void) · 9 unmodified lines
787798 min_addr = memblock_start_of_DRAM() + misalign;
788799 max_addr = min_addr + SZ_512;
789800
790− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
791− min_addr, max_addr,
792− NUMA_NO_NODE);
801+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
802+ min_addr, max_addr,
803+ NUMA_NO_NODE);
793804 rgn_end = rgn->base + rgn->size;
794805
795806 ASSERT_NE(allocated_ptr, NULL);
@@ -824,7 +835,7 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void) · 28 unmodified lines
824835 * Expect to drop the lower limit and allocate a memory region which
825836 * starts at the beginning of the available memory.
826837 */
827−static int alloc_try_nid_bottom_up_narrow_range_check(void)
838+static int alloc_nid_bottom_up_narrow_range_check(void)
828839 {
829840 struct memblock_region *rgn = &memblock.reserved.regions[0];
830841 void *allocated_ptr = NULL;
@@ -838,9 +849,9 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void) · 7 unmodified lines
838849 min_addr = memblock_start_of_DRAM() + SZ_512;
839850 max_addr = min_addr + SMP_CACHE_BYTES;
840851
841− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
842− min_addr, max_addr,
843− NUMA_NO_NODE);
852+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
853+ min_addr, max_addr,
854+ NUMA_NO_NODE);
844855
845856 ASSERT_NE(allocated_ptr, NULL);
846857 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -873,7 +884,7 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void) · 26 unmodified lines
873884 * updated. The total size field gets updated.
874885 */
875886
876−static int alloc_try_nid_bottom_up_reserved_with_space_check(void)
887+static int alloc_nid_bottom_up_reserved_with_space_check(void)
877888 {
878889 struct memblock_region *rgn1 = &memblock.reserved.regions[1];
879890 struct memblock_region *rgn2 = &memblock.reserved.regions[0];
@@ -901,9 +912,9 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void) · 21 unmodified lines
901912 memblock_reserve(r1.base, r1.size);
902913 memblock_reserve(r2.base, r2.size);
903914
904− allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
905− min_addr, max_addr,
906− NUMA_NO_NODE);
915+ allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
916+ min_addr, max_addr,
917+ NUMA_NO_NODE);
907918
908919 ASSERT_NE(allocated_ptr, NULL);
909920 assert_mem_content(allocated_ptr, r3_size, alloc_nid_test_flags);
@@ -942,7 +953,7 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void) · 32 unmodified lines
942953 * Other regions are not modified.
943954 */
944955
945−static int alloc_try_nid_bottom_up_reserved_no_space_check(void)
956+static int alloc_nid_bottom_up_reserved_no_space_check(void)
946957 {
947958 struct memblock_region *rgn1 = &memblock.reserved.regions[2];
948959 struct memblock_region *rgn2 = &memblock.reserved.regions[1];
@@ -971,9 +982,9 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void) · 22 unmodified lines
971982 memblock_reserve(r1.base, r1.size);
972983 memblock_reserve(r2.base, r2.size);
973984
974− allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
975− min_addr, max_addr,
976− NUMA_NO_NODE);
985+ allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
986+ min_addr, max_addr,
987+ NUMA_NO_NODE);
977988
978989 ASSERT_NE(allocated_ptr, NULL);
979990 assert_mem_content(allocated_ptr, r3_size, alloc_nid_test_flags);
@@ -1000,7 +1011,7 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void) · 20 unmodified lines
10001011 * bigger than the end address of the available memory. Expect to allocate
10011012 * a region that starts at the min_addr.
10021013 */
1003−static int alloc_try_nid_bottom_up_cap_max_check(void)
1014+static int alloc_nid_bottom_up_cap_max_check(void)
10041015 {
10051016 struct memblock_region *rgn = &memblock.reserved.regions[0];
10061017 void *allocated_ptr = NULL;
@@ -1014,9 +1025,9 @@ static int alloc_try_nid_bottom_up_cap_max_check(void) · 7 unmodified lines
10141025 min_addr = memblock_start_of_DRAM() + SZ_1K;
10151026 max_addr = memblock_end_of_DRAM() + SZ_256;
10161027
1017− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1018− min_addr, max_addr,
1019− NUMA_NO_NODE);
1028+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1029+ min_addr, max_addr,
1030+ NUMA_NO_NODE);
10201031
10211032 ASSERT_NE(allocated_ptr, NULL);
10221033 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1037,7 +1048,7 @@ static int alloc_try_nid_bottom_up_cap_max_check(void) · 14 unmodified lines
10371048 * smaller than the start address of the available memory. Expect to allocate
10381049 * a region at the beginning of the available memory.
10391050 */
1040−static int alloc_try_nid_bottom_up_cap_min_check(void)
1051+static int alloc_nid_bottom_up_cap_min_check(void)
10411052 {
10421053 struct memblock_region *rgn = &memblock.reserved.regions[0];
10431054 void *allocated_ptr = NULL;
@@ -1051,9 +1062,9 @@ static int alloc_try_nid_bottom_up_cap_min_check(void) · 7 unmodified lines
10511062 min_addr = memblock_start_of_DRAM();
10521063 max_addr = memblock_end_of_DRAM() - SZ_256;
10531064
1054− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1055− min_addr, max_addr,
1056− NUMA_NO_NODE);
1065+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1066+ min_addr, max_addr,
1067+ NUMA_NO_NODE);
10571068
10581069 ASSERT_NE(allocated_ptr, NULL);
10591070 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1070,133 +1081,133 @@ static int alloc_try_nid_bottom_up_cap_min_check(void) · 10 unmodified lines
10701081 }
10711082
10721083 /* Test case wrappers for range tests */
1073−static int alloc_try_nid_simple_check(void)
1084+static int alloc_nid_simple_check(void)
10741085 {
10751086 test_print("\tRunning %s...\n", __func__);
10761087 memblock_set_bottom_up(false);
1077− alloc_try_nid_top_down_simple_check();
1088+ alloc_nid_top_down_simple_check();
10781089 memblock_set_bottom_up(true);
1079− alloc_try_nid_bottom_up_simple_check();
1090+ alloc_nid_bottom_up_simple_check();
10801091
10811092 return 0;
10821093 }
10831094
1084−static int alloc_try_nid_misaligned_check(void)
1095+static int alloc_nid_misaligned_check(void)
10851096 {
10861097 test_print("\tRunning %s...\n", __func__);
10871098 memblock_set_bottom_up(false);
1088− alloc_try_nid_top_down_end_misaligned_check();
1099+ alloc_nid_top_down_end_misaligned_check();
10891100 memblock_set_bottom_up(true);
1090− alloc_try_nid_bottom_up_start_misaligned_check();
1101+ alloc_nid_bottom_up_start_misaligned_check();
10911102
10921103 return 0;
10931104 }
10941105
1095−static int alloc_try_nid_narrow_range_check(void)
1106+static int alloc_nid_narrow_range_check(void)
10961107 {
10971108 test_print("\tRunning %s...\n", __func__);
10981109 memblock_set_bottom_up(false);
1099− alloc_try_nid_top_down_narrow_range_check();
1110+ alloc_nid_top_down_narrow_range_check();
11001111 memblock_set_bottom_up(true);
1101− alloc_try_nid_bottom_up_narrow_range_check();
1112+ alloc_nid_bottom_up_narrow_range_check();
11021113
11031114 return 0;
11041115 }
11051116
1106−static int alloc_try_nid_reserved_with_space_check(void)
1117+static int alloc_nid_reserved_with_space_check(void)
11071118 {
11081119 test_print("\tRunning %s...\n", __func__);
11091120 memblock_set_bottom_up(false);
1110− alloc_try_nid_top_down_reserved_with_space_check();
1121+ alloc_nid_top_down_reserved_with_space_check();
11111122 memblock_set_bottom_up(true);
1112− alloc_try_nid_bottom_up_reserved_with_space_check();
1123+ alloc_nid_bottom_up_reserved_with_space_check();
11131124
11141125 return 0;
11151126 }
11161127
1117−static int alloc_try_nid_reserved_no_space_check(void)
1128+static int alloc_nid_reserved_no_space_check(void)
11181129 {
11191130 test_print("\tRunning %s...\n", __func__);
11201131 memblock_set_bottom_up(false);
1121− alloc_try_nid_top_down_reserved_no_space_check();
1132+ alloc_nid_top_down_reserved_no_space_check();
11221133 memblock_set_bottom_up(true);
1123− alloc_try_nid_bottom_up_reserved_no_space_check();
1134+ alloc_nid_bottom_up_reserved_no_space_check();
11241135
11251136 return 0;
11261137 }
11271138
1128−static int alloc_try_nid_cap_max_check(void)
1139+static int alloc_nid_cap_max_check(void)
11291140 {
11301141 test_print("\tRunning %s...\n", __func__);
11311142 memblock_set_bottom_up(false);
1132− alloc_try_nid_top_down_cap_max_check();
1143+ alloc_nid_top_down_cap_max_check();
11331144 memblock_set_bottom_up(true);
1134− alloc_try_nid_bottom_up_cap_max_check();
1145+ alloc_nid_bottom_up_cap_max_check();
11351146
11361147 return 0;
11371148 }
11381149
1139−static int alloc_try_nid_cap_min_check(void)
1150+static int alloc_nid_cap_min_check(void)
11401151 {
11411152 test_print("\tRunning %s...\n", __func__);
11421153 memblock_set_bottom_up(false);
1143− alloc_try_nid_top_down_cap_min_check();
1154+ alloc_nid_top_down_cap_min_check();
11441155 memblock_set_bottom_up(true);
1145− alloc_try_nid_bottom_up_cap_min_check();
1156+ alloc_nid_bottom_up_cap_min_check();
11461157
11471158 return 0;
11481159 }
11491160
1150−static int alloc_try_nid_min_reserved_check(void)
1161+static int alloc_nid_min_reserved_check(void)
11511162 {
11521163 test_print("\tRunning %s...\n", __func__);
1153− run_top_down(alloc_try_nid_min_reserved_generic_check);
1154− run_bottom_up(alloc_try_nid_min_reserved_generic_check);
1164+ run_top_down(alloc_nid_min_reserved_generic_check);
1165+ run_bottom_up(alloc_nid_min_reserved_generic_check);
11551166
11561167 return 0;
11571168 }
11581169
1159−static int alloc_try_nid_max_reserved_check(void)
1170+static int alloc_nid_max_reserved_check(void)
11601171 {
11611172 test_print("\tRunning %s...\n", __func__);
1162− run_top_down(alloc_try_nid_max_reserved_generic_check);
1163− run_bottom_up(alloc_try_nid_max_reserved_generic_check);
1173+ run_top_down(alloc_nid_max_reserved_generic_check);
1174+ run_bottom_up(alloc_nid_max_reserved_generic_check);
11641175
11651176 return 0;
11661177 }
11671178
1168−static int alloc_try_nid_exact_address_check(void)
1179+static int alloc_nid_exact_address_check(void)
11691180 {
11701181 test_print("\tRunning %s...\n", __func__);
1171− run_top_down(alloc_try_nid_exact_address_generic_check);
1172− run_bottom_up(alloc_try_nid_exact_address_generic_check);
1182+ run_top_down(alloc_nid_exact_address_generic_check);
1183+ run_bottom_up(alloc_nid_exact_address_generic_check);
11731184
11741185 return 0;
11751186 }
11761187
1177−static int alloc_try_nid_reserved_full_merge_check(void)
1188+static int alloc_nid_reserved_full_merge_check(void)
11781189 {
11791190 test_print("\tRunning %s...\n", __func__);
1180− run_top_down(alloc_try_nid_reserved_full_merge_generic_check);
1181− run_bottom_up(alloc_try_nid_reserved_full_merge_generic_check);
1191+ run_top_down(alloc_nid_reserved_full_merge_generic_check);
1192+ run_bottom_up(alloc_nid_reserved_full_merge_generic_check);
11821193
11831194 return 0;
11841195 }
11851196
1186−static int alloc_try_nid_reserved_all_check(void)
1197+static int alloc_nid_reserved_all_check(void)
11871198 {
11881199 test_print("\tRunning %s...\n", __func__);
1189− run_top_down(alloc_try_nid_reserved_all_generic_check);
1190− run_bottom_up(alloc_try_nid_reserved_all_generic_check);
1200+ run_top_down(alloc_nid_reserved_all_generic_check);
1201+ run_bottom_up(alloc_nid_reserved_all_generic_check);
11911202
11921203 return 0;
11931204 }
11941205
1195−static int alloc_try_nid_low_max_check(void)
1206+static int alloc_nid_low_max_check(void)
11961207 {
11971208 test_print("\tRunning %s...\n", __func__);
1198− run_top_down(alloc_try_nid_low_max_generic_check);
1199− run_bottom_up(alloc_try_nid_low_max_generic_check);
1209+ run_top_down(alloc_nid_low_max_generic_check);
1210+ run_bottom_up(alloc_nid_low_max_generic_check);
12001211
12011212 return 0;
12021213 }
@@ -1204,22 +1215,22 @@ static int alloc_try_nid_low_max_check(void) · 1 unmodified line
12041215 static int memblock_alloc_nid_range_checks(void)
12051216 {
12061217 test_print("Running %s range tests...\n",
1207− get_memblock_alloc_try_nid_name(alloc_nid_test_flags));
1218+ get_memblock_alloc_nid_name(alloc_nid_test_flags));
12081219
1209− alloc_try_nid_simple_check();
1210− alloc_try_nid_misaligned_check();
1211− alloc_try_nid_narrow_range_check();
1212− alloc_try_nid_reserved_with_space_check();
1213− alloc_try_nid_reserved_no_space_check();
1214− alloc_try_nid_cap_max_check();
1215− alloc_try_nid_cap_min_check();
1220+ alloc_nid_simple_check();
1221+ alloc_nid_misaligned_check();
1222+ alloc_nid_narrow_range_check();
1223+ alloc_nid_reserved_with_space_check();
1224+ alloc_nid_reserved_no_space_check();
1225+ alloc_nid_cap_max_check();
1226+ alloc_nid_cap_min_check();
12161227
1217− alloc_try_nid_min_reserved_check();
1218− alloc_try_nid_max_reserved_check();
1219− alloc_try_nid_exact_address_check();
1220− alloc_try_nid_reserved_full_merge_check();
1221− alloc_try_nid_reserved_all_check();
1222− alloc_try_nid_low_max_check();
1228+ alloc_nid_min_reserved_check();
1229+ alloc_nid_max_reserved_check();
1230+ alloc_nid_exact_address_check();
1231+ alloc_nid_reserved_full_merge_check();
1232+ alloc_nid_reserved_all_check();
1233+ alloc_nid_low_max_check();
12231234
12241235 return 0;
12251236 }
@@ -1229,7 +1240,7 @@ static int memblock_alloc_nid_range_checks(void) · 3 unmodified lines
12291240 * has enough memory to allocate a region of the requested size.
12301241 * Expect to allocate an aligned region at the end of the requested node.
12311242 */
1232−static int alloc_try_nid_top_down_numa_simple_check(void)
1243+static int alloc_nid_top_down_numa_simple_check(void)
12331244 {
12341245 int nid_req = 3;
12351246 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1247,8 +1258,8 @@ static int alloc_try_nid_top_down_numa_simple_check(void) · 11 unmodified lines
12471258 min_addr = memblock_start_of_DRAM();
12481259 max_addr = memblock_end_of_DRAM();
12491260
1250− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1251− min_addr, max_addr, nid_req);
1261+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1262+ min_addr, max_addr, nid_req);
12521263
12531264 ASSERT_NE(allocated_ptr, NULL);
12541265 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1280,7 +1291,7 @@ static int alloc_try_nid_top_down_numa_simple_check(void) · 25 unmodified lines
12801291 * Expect to allocate an aligned region at the end of the last node that has
12811292 * enough memory (in this case, nid = 6) after falling back to NUMA_NO_NODE.
12821293 */
1283−static int alloc_try_nid_top_down_numa_small_node_check(void)
1294+static int alloc_nid_top_down_numa_small_node_check(void)
12841295 {
12851296 int nid_req = 1;
12861297 int nid_exp = 6;
@@ -1299,8 +1310,8 @@ static int alloc_try_nid_top_down_numa_small_node_check(void) · 12 unmodified lines
12991310 min_addr = memblock_start_of_DRAM();
13001311 max_addr = memblock_end_of_DRAM();
13011312
1302− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1303− min_addr, max_addr, nid_req);
1313+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1314+ min_addr, max_addr, nid_req);
13041315
13051316 ASSERT_NE(allocated_ptr, NULL);
13061317 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1333,7 +1344,7 @@ static int alloc_try_nid_top_down_numa_small_node_check(void) · 26 unmodified lines
13331344 * large enough and has enough unreserved memory (in this case, nid = 6) after
13341345 * falling back to NUMA_NO_NODE. The region count and total size get updated.
13351346 */
1336−static int alloc_try_nid_top_down_numa_node_reserved_check(void)
1347+static int alloc_nid_top_down_numa_node_reserved_check(void)
13371348 {
13381349 int nid_req = 2;
13391350 int nid_exp = 6;
@@ -1353,8 +1364,8 @@ static int alloc_try_nid_top_down_numa_node_reserved_check(void) · 13 unmodified lines
13531364 max_addr = memblock_end_of_DRAM();
13541365
13551366 memblock_reserve(req_node->base, req_node->size);
1356− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1357− min_addr, max_addr, nid_req);
1367+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1368+ min_addr, max_addr, nid_req);
13581369
13591370 ASSERT_NE(allocated_ptr, NULL);
13601371 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1386,7 +1397,7 @@ static int alloc_try_nid_top_down_numa_node_reserved_check(void) · 25 unmodified lines
13861397 * Expect to allocate an aligned region at the end of the requested node. The
13871398 * region count and total size get updated.
13881399 */
1389−static int alloc_try_nid_top_down_numa_part_reserved_check(void)
1400+static int alloc_nid_top_down_numa_part_reserved_check(void)
13901401 {
13911402 int nid_req = 4;
13921403 struct memblock_region *new_rgn = &memblock.reserved.regions[1];
@@ -1408,8 +1419,8 @@ static int alloc_try_nid_top_down_numa_part_reserved_check(void) · 15 unmodified lines
14081419 max_addr = memblock_end_of_DRAM();
14091420
14101421 memblock_reserve(r1.base, r1.size);
1411− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1412− min_addr, max_addr, nid_req);
1422+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1423+ min_addr, max_addr, nid_req);
14131424
14141425 ASSERT_NE(allocated_ptr, NULL);
14151426 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1444,7 +1455,7 @@ static int alloc_try_nid_top_down_numa_part_reserved_check(void) · 28 unmodified lines
14441455 * nid = NUMA_NODES - 1) after falling back to NUMA_NO_NODE. The region count
14451456 * and total size get updated.
14461457 */
1447−static int alloc_try_nid_top_down_numa_part_reserved_fallback_check(void)
1458+static int alloc_nid_top_down_numa_part_reserved_fallback_check(void)
14481459 {
14491460 int nid_req = 4;
14501461 int nid_exp = NUMA_NODES - 1;
@@ -1469,8 +1480,8 @@ static int alloc_try_nid_top_down_numa_part_reserved_fallback_check(void) · 18 unmodified lines
14691480 max_addr = memblock_end_of_DRAM();
14701481
14711482 memblock_reserve(r1.base, r1.size);
1472− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1473− min_addr, max_addr, nid_req);
1483+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1484+ min_addr, max_addr, nid_req);
14741485
14751486 ASSERT_NE(allocated_ptr, NULL);
14761487 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1507,7 +1518,7 @@ static int alloc_try_nid_top_down_numa_part_reserved_fallback_check(void) · 30 unmodified lines
15071518 * Expect to drop the lower limit and allocate a memory region that ends at
15081519 * the end of the requested node.
15091520 */
1510−static int alloc_try_nid_top_down_numa_split_range_low_check(void)
1521+static int alloc_nid_top_down_numa_split_range_low_check(void)
15111522 {
15121523 int nid_req = 2;
15131524 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1525,8 +1536,8 @@ static int alloc_try_nid_top_down_numa_split_range_low_check(void) · 11 unmodified lines
15251536 min_addr = req_node_end - SZ_256;
15261537 max_addr = min_addr + size;
15271538
1528− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1529− min_addr, max_addr, nid_req);
1539+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1540+ min_addr, max_addr, nid_req);
15301541
15311542 ASSERT_NE(allocated_ptr, NULL);
15321543 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1563,7 +1574,7 @@ static int alloc_try_nid_top_down_numa_split_range_low_check(void) · 30 unmodified lines
15631574 * Expect to drop the lower limit and allocate a memory region that
15641575 * ends at the end of the first node that overlaps with the range.
15651576 */
1566−static int alloc_try_nid_top_down_numa_split_range_high_check(void)
1577+static int alloc_nid_top_down_numa_split_range_high_check(void)
15671578 {
15681579 int nid_req = 3;
15691580 int nid_exp = nid_req - 1;
@@ -1582,8 +1593,8 @@ static int alloc_try_nid_top_down_numa_split_range_high_check(void) · 12 unmodified lines
15821593 min_addr = exp_node_end - SZ_256;
15831594 max_addr = min_addr + size;
15841595
1585− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1586− min_addr, max_addr, nid_req);
1596+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1597+ min_addr, max_addr, nid_req);
15871598
15881599 ASSERT_NE(allocated_ptr, NULL);
15891600 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1620,7 +1631,7 @@ static int alloc_try_nid_top_down_numa_split_range_high_check(void) · 30 unmodified lines
16201631 * Expect to drop the lower limit and allocate a memory region that ends at
16211632 * the end of the requested node.
16221633 */
1623−static int alloc_try_nid_top_down_numa_no_overlap_split_check(void)
1634+static int alloc_nid_top_down_numa_no_overlap_split_check(void)
16241635 {
16251636 int nid_req = 2;
16261637 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1638,8 +1649,8 @@ static int alloc_try_nid_top_down_numa_no_overlap_split_check(void) · 11 unmodified lines
16381649 min_addr = node2->base - SZ_256;
16391650 max_addr = min_addr + size;
16401651
1641− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1642− min_addr, max_addr, nid_req);
1652+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1653+ min_addr, max_addr, nid_req);
16431654
16441655 ASSERT_NE(allocated_ptr, NULL);
16451656 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1677,7 +1688,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_split_check(void) · 31 unmodified lines
16771688 * Expect to allocate a memory region at the end of the final node in
16781689 * the range after falling back to NUMA_NO_NODE.
16791690 */
1680−static int alloc_try_nid_top_down_numa_no_overlap_low_check(void)
1691+static int alloc_nid_top_down_numa_no_overlap_low_check(void)
16811692 {
16821693 int nid_req = 0;
16831694 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1694,8 +1705,8 @@ static int alloc_try_nid_top_down_numa_no_overlap_low_check(void) · 10 unmodified lines
16941705 min_addr = min_node->base;
16951706 max_addr = region_end(max_node);
16961707
1697− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1698− min_addr, max_addr, nid_req);
1708+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1709+ min_addr, max_addr, nid_req);
16991710
17001711 ASSERT_NE(allocated_ptr, NULL);
17011712 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1733,7 +1744,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_low_check(void) · 31 unmodified lines
17331744 * Expect to allocate a memory region at the end of the final node in
17341745 * the range after falling back to NUMA_NO_NODE.
17351746 */
1736−static int alloc_try_nid_top_down_numa_no_overlap_high_check(void)
1747+static int alloc_nid_top_down_numa_no_overlap_high_check(void)
17371748 {
17381749 int nid_req = 7;
17391750 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1750,8 +1761,8 @@ static int alloc_try_nid_top_down_numa_no_overlap_high_check(void) · 10 unmodified lines
17501761 min_addr = min_node->base;
17511762 max_addr = region_end(max_node);
17521763
1753− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1754− min_addr, max_addr, nid_req);
1764+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1765+ min_addr, max_addr, nid_req);
17551766
17561767 ASSERT_NE(allocated_ptr, NULL);
17571768 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1773,7 +1784,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_high_check(void) · 15 unmodified lines
17731784 * has enough memory to allocate a region of the requested size.
17741785 * Expect to allocate an aligned region at the beginning of the requested node.
17751786 */
1776−static int alloc_try_nid_bottom_up_numa_simple_check(void)
1787+static int alloc_nid_bottom_up_numa_simple_check(void)
17771788 {
17781789 int nid_req = 3;
17791790 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1791,8 +1802,8 @@ static int alloc_try_nid_bottom_up_numa_simple_check(void) · 11 unmodified lines
17911802 min_addr = memblock_start_of_DRAM();
17921803 max_addr = memblock_end_of_DRAM();
17931804
1794− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1795− min_addr, max_addr, nid_req);
1805+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1806+ min_addr, max_addr, nid_req);
17961807
17971808 ASSERT_NE(allocated_ptr, NULL);
17981809 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1824,7 +1835,7 @@ static int alloc_try_nid_bottom_up_numa_simple_check(void) · 25 unmodified lines
18241835 * Expect to allocate an aligned region at the beginning of the first node that
18251836 * has enough memory (in this case, nid = 0) after falling back to NUMA_NO_NODE.
18261837 */
1827−static int alloc_try_nid_bottom_up_numa_small_node_check(void)
1838+static int alloc_nid_bottom_up_numa_small_node_check(void)
18281839 {
18291840 int nid_req = 1;
18301841 int nid_exp = 0;
@@ -1843,8 +1854,8 @@ static int alloc_try_nid_bottom_up_numa_small_node_check(void) · 12 unmodified lines
18431854 min_addr = memblock_start_of_DRAM();
18441855 max_addr = memblock_end_of_DRAM();
18451856
1846− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1847− min_addr, max_addr, nid_req);
1857+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1858+ min_addr, max_addr, nid_req);
18481859
18491860 ASSERT_NE(allocated_ptr, NULL);
18501861 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1878,7 +1889,7 @@ static int alloc_try_nid_bottom_up_numa_small_node_check(void) · 27 unmodified lines
18781889 * after falling back to NUMA_NO_NODE. The region count and total size get
18791890 * updated.
18801891 */
1881−static int alloc_try_nid_bottom_up_numa_node_reserved_check(void)
1892+static int alloc_nid_bottom_up_numa_node_reserved_check(void)
18821893 {
18831894 int nid_req = 2;
18841895 int nid_exp = 0;
@@ -1898,8 +1909,8 @@ static int alloc_try_nid_bottom_up_numa_node_reserved_check(void) · 13 unmodified lines
18981909 max_addr = memblock_end_of_DRAM();
18991910
19001911 memblock_reserve(req_node->base, req_node->size);
1901− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1902− min_addr, max_addr, nid_req);
1912+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1913+ min_addr, max_addr, nid_req);
19031914
19041915 ASSERT_NE(allocated_ptr, NULL);
19051916 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1931,7 +1942,7 @@ static int alloc_try_nid_bottom_up_numa_node_reserved_check(void) · 25 unmodified lines
19311942 * Expect to allocate an aligned region in the requested node that merges with
19321943 * the existing reserved region. The total size gets updated.
19331944 */
1934−static int alloc_try_nid_bottom_up_numa_part_reserved_check(void)
1945+static int alloc_nid_bottom_up_numa_part_reserved_check(void)
19351946 {
19361947 int nid_req = 4;
19371948 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -1955,8 +1966,8 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_check(void) · 17 unmodified lines
19551966 total_size = size + r1.size;
19561967
19571968 memblock_reserve(r1.base, r1.size);
1958− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
1959− min_addr, max_addr, nid_req);
1969+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
1970+ min_addr, max_addr, nid_req);
19601971
19611972 ASSERT_NE(allocated_ptr, NULL);
19621973 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -1991,7 +2002,7 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_check(void) · 28 unmodified lines
19912002 * nid = 0) after falling back to NUMA_NO_NODE. The region count and total size
19922003 * get updated.
19932004 */
1994−static int alloc_try_nid_bottom_up_numa_part_reserved_fallback_check(void)
2005+static int alloc_nid_bottom_up_numa_part_reserved_fallback_check(void)
19952006 {
19962007 int nid_req = 4;
19972008 int nid_exp = 0;
@@ -2016,8 +2027,8 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_fallback_check(void) · 18 unmodified lines
20162027 max_addr = memblock_end_of_DRAM();
20172028
20182029 memblock_reserve(r1.base, r1.size);
2019− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2020− min_addr, max_addr, nid_req);
2030+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2031+ min_addr, max_addr, nid_req);
20212032
20222033 ASSERT_NE(allocated_ptr, NULL);
20232034 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2054,7 +2065,7 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_fallback_check(void) · 30 unmodified lines
20542065 * Expect to drop the lower limit and allocate a memory region at the beginning
20552066 * of the requested node.
20562067 */
2057−static int alloc_try_nid_bottom_up_numa_split_range_low_check(void)
2068+static int alloc_nid_bottom_up_numa_split_range_low_check(void)
20582069 {
20592070 int nid_req = 2;
20602071 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -2072,8 +2083,8 @@ static int alloc_try_nid_bottom_up_numa_split_range_low_check(void) · 11 unmodified lines
20722083 min_addr = req_node_end - SZ_256;
20732084 max_addr = min_addr + size;
20742085
2075− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2076− min_addr, max_addr, nid_req);
2086+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2087+ min_addr, max_addr, nid_req);
20772088
20782089 ASSERT_NE(allocated_ptr, NULL);
20792090 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2110,7 +2121,7 @@ static int alloc_try_nid_bottom_up_numa_split_range_low_check(void) · 30 unmodified lines
21102121 * Expect to drop the lower limit and allocate a memory region at the beginning
21112122 * of the first node that has enough memory.
21122123 */
2113−static int alloc_try_nid_bottom_up_numa_split_range_high_check(void)
2124+static int alloc_nid_bottom_up_numa_split_range_high_check(void)
21142125 {
21152126 int nid_req = 3;
21162127 int nid_exp = 0;
@@ -2130,8 +2141,8 @@ static int alloc_try_nid_bottom_up_numa_split_range_high_check(void) · 13 unmodified lines
21302141 min_addr = req_node->base - SZ_256;
21312142 max_addr = min_addr + size;
21322143
2133− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2134− min_addr, max_addr, nid_req);
2144+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2145+ min_addr, max_addr, nid_req);
21352146
21362147 ASSERT_NE(allocated_ptr, NULL);
21372148 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2168,7 +2179,7 @@ static int alloc_try_nid_bottom_up_numa_split_range_high_check(void) · 30 unmodified lines
21682179 * Expect to drop the lower limit and allocate a memory region that starts at
21692180 * the beginning of the requested node.
21702181 */
2171−static int alloc_try_nid_bottom_up_numa_no_overlap_split_check(void)
2182+static int alloc_nid_bottom_up_numa_no_overlap_split_check(void)
21722183 {
21732184 int nid_req = 2;
21742185 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -2186,8 +2197,8 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_split_check(void) · 11 unmodified lines
21862197 min_addr = node2->base - SZ_256;
21872198 max_addr = min_addr + size;
21882199
2189− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2190− min_addr, max_addr, nid_req);
2200+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2201+ min_addr, max_addr, nid_req);
21912202
21922203 ASSERT_NE(allocated_ptr, NULL);
21932204 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2225,7 +2236,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_split_check(void) · 31 unmodified lines
22252236 * Expect to allocate a memory region at the beginning of the first node
22262237 * in the range after falling back to NUMA_NO_NODE.
22272238 */
2228−static int alloc_try_nid_bottom_up_numa_no_overlap_low_check(void)
2239+static int alloc_nid_bottom_up_numa_no_overlap_low_check(void)
22292240 {
22302241 int nid_req = 0;
22312242 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -2242,8 +2253,8 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_low_check(void) · 10 unmodified lines
22422253 min_addr = min_node->base;
22432254 max_addr = region_end(max_node);
22442255
2245− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2246− min_addr, max_addr, nid_req);
2256+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2257+ min_addr, max_addr, nid_req);
22472258
22482259 ASSERT_NE(allocated_ptr, NULL);
22492260 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2281,7 +2292,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_low_check(void) · 31 unmodified lines
22812292 * Expect to allocate a memory region at the beginning of the first node
22822293 * in the range after falling back to NUMA_NO_NODE.
22832294 */
2284−static int alloc_try_nid_bottom_up_numa_no_overlap_high_check(void)
2295+static int alloc_nid_bottom_up_numa_no_overlap_high_check(void)
22852296 {
22862297 int nid_req = 7;
22872298 struct memblock_region *new_rgn = &memblock.reserved.regions[0];
@@ -2298,8 +2309,8 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_high_check(void) · 10 unmodified lines
22982309 min_addr = min_node->base;
22992310 max_addr = region_end(max_node);
23002311
2301− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2302− min_addr, max_addr, nid_req);
2312+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2313+ min_addr, max_addr, nid_req);
23032314
23042315 ASSERT_NE(allocated_ptr, NULL);
23052316 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2330,7 +2341,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_high_check(void) · 24 unmodified lines
23302341 *
23312342 * Expect no allocation to happen.
23322343 */
2333−static int alloc_try_nid_numa_large_region_generic_check(void)
2344+static int alloc_nid_numa_large_region_generic_check(void)
23342345 {
23352346 int nid_req = 3;
23362347 void *allocated_ptr = NULL;
@@ -2344,8 +2355,8 @@ static int alloc_try_nid_numa_large_region_generic_check(void) · 7 unmodified lines
23442355 min_addr = memblock_start_of_DRAM();
23452356 max_addr = memblock_end_of_DRAM();
23462357
2347− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2348− min_addr, max_addr, nid_req);
2358+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2359+ min_addr, max_addr, nid_req);
23492360 ASSERT_EQ(allocated_ptr, NULL);
23502361
23512362 test_pass_pop();
@@ -2374,7 +2385,7 @@ static int alloc_try_nid_numa_large_region_generic_check(void) · 22 unmodified lines
23742385 * Expect to merge all of the regions into one. The region counter and total
23752386 * size fields get updated.
23762387 */
2377−static int alloc_try_nid_numa_reserved_full_merge_generic_check(void)
2388+static int alloc_nid_numa_reserved_full_merge_generic_check(void)
23782389 {
23792390 int nid_req = 6;
23802391 int nid_next = nid_req + 1;
@@ -2404,8 +2415,8 @@ static int alloc_try_nid_numa_reserved_full_merge_generic_check(void) · 23 unmodified lines
24042415 memblock_reserve(r1.base, r1.size);
24052416 memblock_reserve(r2.base, r2.size);
24062417
2407− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2408− min_addr, max_addr, nid_req);
2418+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2419+ min_addr, max_addr, nid_req);
24092420
24102421 ASSERT_NE(allocated_ptr, NULL);
24112422 assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
@@ -2448,7 +2459,7 @@ static int alloc_try_nid_numa_reserved_full_merge_generic_check(void) · 36 unmodified lines
24482459 *
24492460 * Expect no allocation to happen.
24502461 */
2451−static int alloc_try_nid_numa_split_all_reserved_generic_check(void)
2462+static int alloc_nid_numa_split_all_reserved_generic_check(void)
24522463 {
24532464 void *allocated_ptr = NULL;
24542465 struct memblock_region *next_node = &memblock.memory.regions[7];
@@ -2472,9 +2483,9 @@ static int alloc_try_nid_numa_split_all_reserved_generic_check(void) · 17 unmodified lines
24722483 memblock_reserve(r1.base, r1.size);
24732484 memblock_reserve(r2.base, r2.size);
24742485
2475− allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
2476− min_addr, max_addr,
2477− NUMA_NO_NODE);
2486+ allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
2487+ min_addr, max_addr,
2488+ NUMA_NO_NODE);
24782489
24792490 ASSERT_EQ(allocated_ptr, NULL);
24802491
@@ -2484,139 +2495,139 @@ static int alloc_try_nid_numa_split_all_reserved_generic_check(void) · 3 unmodified lines
24842495 }
24852496
24862497 /* Test case wrappers for NUMA tests */
2487−static int alloc_try_nid_numa_simple_check(void)
2498+static int alloc_nid_numa_simple_check(void)
24882499 {
24892500 test_print("\tRunning %s...\n", __func__);
24902501 memblock_set_bottom_up(false);
2491− alloc_try_nid_top_down_numa_simple_check();
2502+ alloc_nid_top_down_numa_simple_check();
24922503 memblock_set_bottom_up(true);
2493− alloc_try_nid_bottom_up_numa_simple_check();
2504+ alloc_nid_bottom_up_numa_simple_check();
24942505
24952506 return 0;
24962507 }
24972508
2498−static int alloc_try_nid_numa_small_node_check(void)
2509+static int alloc_nid_numa_small_node_check(void)
24992510 {
25002511 test_print("\tRunning %s...\n", __func__);
25012512 memblock_set_bottom_up(false);
2502− alloc_try_nid_top_down_numa_small_node_check();
2513+ alloc_nid_top_down_numa_small_node_check();
25032514 memblock_set_bottom_up(true);
2504− alloc_try_nid_bottom_up_numa_small_node_check();
2515+ alloc_nid_bottom_up_numa_small_node_check();
25052516
25062517 return 0;
25072518 }
25082519
2509−static int alloc_try_nid_numa_node_reserved_check(void)
2520+static int alloc_nid_numa_node_reserved_check(void)
25102521 {
25112522 test_print("\tRunning %s...\n", __func__);
25122523 memblock_set_bottom_up(false);
2513− alloc_try_nid_top_down_numa_node_reserved_check();
2524+ alloc_nid_top_down_numa_node_reserved_check();
25142525 memblock_set_bottom_up(true);
2515− alloc_try_nid_bottom_up_numa_node_reserved_check();
2526+ alloc_nid_bottom_up_numa_node_reserved_check();
25162527
25172528 return 0;
25182529 }
25192530
2520−static int alloc_try_nid_numa_part_reserved_check(void)
2531+static int alloc_nid_numa_part_reserved_check(void)
25212532 {
25222533 test_print("\tRunning %s...\n", __func__);
25232534 memblock_set_bottom_up(false);
2524− alloc_try_nid_top_down_numa_part_reserved_check();
2535+ alloc_nid_top_down_numa_part_reserved_check();
25252536 memblock_set_bottom_up(true);
2526− alloc_try_nid_bottom_up_numa_part_reserved_check();
2537+ alloc_nid_bottom_up_numa_part_reserved_check();
25272538
25282539 return 0;
25292540 }
25302541
2531−static int alloc_try_nid_numa_part_reserved_fallback_check(void)
2542+static int alloc_nid_numa_part_reserved_fallback_check(void)
25322543 {
25332544 test_print("\tRunning %s...\n", __func__);
25342545 memblock_set_bottom_up(false);
2535− alloc_try_nid_top_down_numa_part_reserved_fallback_check();
2546+ alloc_nid_top_down_numa_part_reserved_fallback_check();
25362547 memblock_set_bottom_up(true);
2537− alloc_try_nid_bottom_up_numa_part_reserved_fallback_check();
2548+ alloc_nid_bottom_up_numa_part_reserved_fallback_check();
25382549
25392550 return 0;
25402551 }
25412552
2542−static int alloc_try_nid_numa_split_range_low_check(void)
2553+static int alloc_nid_numa_split_range_low_check(void)
25432554 {
25442555 test_print("\tRunning %s...\n", __func__);
25452556 memblock_set_bottom_up(false);
2546− alloc_try_nid_top_down_numa_split_range_low_check();
2557+ alloc_nid_top_down_numa_split_range_low_check();
25472558 memblock_set_bottom_up(true);
2548− alloc_try_nid_bottom_up_numa_split_range_low_check();
2559+ alloc_nid_bottom_up_numa_split_range_low_check();
25492560
25502561 return 0;
25512562 }
25522563
2553−static int alloc_try_nid_numa_split_range_high_check(void)
2564+static int alloc_nid_numa_split_range_high_check(void)
25542565 {
25552566 test_print("\tRunning %s...\n", __func__);
25562567 memblock_set_bottom_up(false);
2557− alloc_try_nid_top_down_numa_split_range_high_check();
2568+ alloc_nid_top_down_numa_split_range_high_check();
25582569 memblock_set_bottom_up(true);
2559− alloc_try_nid_bottom_up_numa_split_range_high_check();
2570+ alloc_nid_bottom_up_numa_split_range_high_check();
25602571
25612572 return 0;
25622573 }
25632574
2564−static int alloc_try_nid_numa_no_overlap_split_check(void)
2575+static int alloc_nid_numa_no_overlap_split_check(void)
25652576 {
25662577 test_print("\tRunning %s...\n", __func__);
25672578 memblock_set_bottom_up(false);
2568− alloc_try_nid_top_down_numa_no_overlap_split_check();
2579+ alloc_nid_top_down_numa_no_overlap_split_check();
25692580 memblock_set_bottom_up(true);
2570− alloc_try_nid_bottom_up_numa_no_overlap_split_check();
2581+ alloc_nid_bottom_up_numa_no_overlap_split_check();
25712582
25722583 return 0;
25732584 }
25742585
2575−static int alloc_try_nid_numa_no_overlap_low_check(void)
2586+static int alloc_nid_numa_no_overlap_low_check(void)
25762587 {
25772588 test_print("\tRunning %s...\n", __func__);
25782589 memblock_set_bottom_up(false);
2579− alloc_try_nid_top_down_numa_no_overlap_low_check();
2590+ alloc_nid_top_down_numa_no_overlap_low_check();
25802591 memblock_set_bottom_up(true);
2581− alloc_try_nid_bottom_up_numa_no_overlap_low_check();
2592+ alloc_nid_bottom_up_numa_no_overlap_low_check();
25822593
25832594 return 0;
25842595 }
25852596
2586−static int alloc_try_nid_numa_no_overlap_high_check(void)
2597+static int alloc_nid_numa_no_overlap_high_check(void)
25872598 {
25882599 test_print("\tRunning %s...\n", __func__);
25892600 memblock_set_bottom_up(false);
2590− alloc_try_nid_top_down_numa_no_overlap_high_check();
2601+ alloc_nid_top_down_numa_no_overlap_high_check();
25912602 memblock_set_bottom_up(true);
2592− alloc_try_nid_bottom_up_numa_no_overlap_high_check();
2603+ alloc_nid_bottom_up_numa_no_overlap_high_check();
25932604
25942605 return 0;
25952606 }
25962607
2597−static int alloc_try_nid_numa_large_region_check(void)
2608+static int alloc_nid_numa_large_region_check(void)
25982609 {
25992610 test_print("\tRunning %s...\n", __func__);
2600− run_top_down(alloc_try_nid_numa_large_region_generic_check);
2601− run_bottom_up(alloc_try_nid_numa_large_region_generic_check);
2611+ run_top_down(alloc_nid_numa_large_region_generic_check);
2612+ run_bottom_up(alloc_nid_numa_large_region_generic_check);
26022613
26032614 return 0;
26042615 }
26052616
2606−static int alloc_try_nid_numa_reserved_full_merge_check(void)
2617+static int alloc_nid_numa_reserved_full_merge_check(void)
26072618 {
26082619 test_print("\tRunning %s...\n", __func__);
2609− run_top_down(alloc_try_nid_numa_reserved_full_merge_generic_check);
2610− run_bottom_up(alloc_try_nid_numa_reserved_full_merge_generic_check);
2620+ run_top_down(alloc_nid_numa_reserved_full_merge_generic_check);
2621+ run_bottom_up(alloc_nid_numa_reserved_full_merge_generic_check);
26112622
26122623 return 0;
26132624 }
26142625
2615−static int alloc_try_nid_numa_split_all_reserved_check(void)
2626+static int alloc_nid_numa_split_all_reserved_check(void)
26162627 {
26172628 test_print("\tRunning %s...\n", __func__);
2618− run_top_down(alloc_try_nid_numa_split_all_reserved_generic_check);
2619− run_bottom_up(alloc_try_nid_numa_split_all_reserved_generic_check);
2629+ run_top_down(alloc_nid_numa_split_all_reserved_generic_check);
2630+ run_bottom_up(alloc_nid_numa_split_all_reserved_generic_check);
26202631
26212632 return 0;
26222633 }
@@ -2624,22 +2635,22 @@ static int alloc_try_nid_numa_split_all_reserved_check(void) · 1 unmodified line
26242635 int __memblock_alloc_nid_numa_checks(void)
26252636 {
26262637 test_print("Running %s NUMA tests...\n",
2627− get_memblock_alloc_try_nid_name(alloc_nid_test_flags));
2638+ get_memblock_alloc_nid_name(alloc_nid_test_flags));
26282639
2629− alloc_try_nid_numa_simple_check();
2630− alloc_try_nid_numa_small_node_check();
2631− alloc_try_nid_numa_node_reserved_check();
2632− alloc_try_nid_numa_part_reserved_check();
2633− alloc_try_nid_numa_part_reserved_fallback_check();
2634− alloc_try_nid_numa_split_range_low_check();
2635− alloc_try_nid_numa_split_range_high_check();
2640+ alloc_nid_numa_simple_check();
2641+ alloc_nid_numa_small_node_check();
2642+ alloc_nid_numa_node_reserved_check();
2643+ alloc_nid_numa_part_reserved_check();
2644+ alloc_nid_numa_part_reserved_fallback_check();
2645+ alloc_nid_numa_split_range_low_check();
2646+ alloc_nid_numa_split_range_high_check();
26362647
2637− alloc_try_nid_numa_no_overlap_split_check();
2638− alloc_try_nid_numa_no_overlap_low_check();
2639− alloc_try_nid_numa_no_overlap_high_check();
2640− alloc_try_nid_numa_large_region_check();
2641− alloc_try_nid_numa_reserved_full_merge_check();
2642− alloc_try_nid_numa_split_all_reserved_check();
2648+ alloc_nid_numa_no_overlap_split_check();
2649+ alloc_nid_numa_no_overlap_low_check();
2650+ alloc_nid_numa_no_overlap_high_check();
2651+ alloc_nid_numa_large_region_check();
2652+ alloc_nid_numa_reserved_full_merge_check();
2653+ alloc_nid_numa_split_all_reserved_check();
26432654
26442655 return 0;
26452656 }
@@ -2649,7 +2660,7 @@ static int memblock_alloc_nid_checks_internal(int flags) · 3 unmodified lines
26492660 alloc_nid_test_flags = flags;
26502661
26512662 prefix_reset();
2652− prefix_push(get_memblock_alloc_try_nid_name(flags));
2663+ prefix_push(get_memblock_alloc_nid_name(flags));
26532664
26542665 reset_memblock_attributes();
26552666 dummy_physical_memory_init();
@@ -2671,3 +2682,12 @@ int memblock_alloc_nid_checks(void) · 15 unmodified lines
26712682
26722683 return 0;
26732684 }
2685+
2686+int memblock_alloc_exact_nid_range_checks(void)
2687+{
2688+ alloc_nid_test_flags = (TEST_F_RAW | TEST_F_EXACT);
2689+
2690+ memblock_alloc_nid_range_checks();
2691+
2692+ return 0;
2693+}
tools/testing/memblock/tests/alloc_nid_api.h+1−0
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #include "common.h"
66
77 int memblock_alloc_nid_checks(void);
8+int memblock_alloc_exact_nid_range_checks(void);
89 int __memblock_alloc_nid_numa_checks(void);
910
1011 #ifdef CONFIG_NUMA
tools/testing/memblock/tests/basic_api.c+184−0
@@ -423,6 +423,98 @@ static int memblock_add_near_max_check(void) · 422 unmodified lines
423423 return 0;
424424 }
425425
426+/*
427+ * A test that trying to add the 129th memory block.
428+ * Expect to trigger memblock_double_array() to double the
429+ * memblock.memory.max, find a new valid memory as
430+ * memory.regions.
431+ */
432+static int memblock_add_many_check(void)
433+{
434+ int i;
435+ void *orig_region;
436+ struct region r = {
437+ .base = SZ_16K,
438+ .size = SZ_16K,
439+ };
440+ phys_addr_t new_memory_regions_size;
441+ phys_addr_t base, size = SZ_64;
442+ phys_addr_t gap_size = SZ_64;
443+
444+ PREFIX_PUSH();
445+
446+ reset_memblock_regions();
447+ memblock_allow_resize();
448+
449+ dummy_physical_memory_init();
450+ /*
451+ * We allocated enough memory by using dummy_physical_memory_init(), and
452+ * split it into small block. First we split a large enough memory block
453+ * as the memory region which will be choosed by memblock_double_array().
454+ */
455+ base = PAGE_ALIGN(dummy_physical_memory_base());
456+ new_memory_regions_size = PAGE_ALIGN(INIT_MEMBLOCK_REGIONS * 2 *
457+ sizeof(struct memblock_region));
458+ memblock_add(base, new_memory_regions_size);
459+
460+ /* This is the base of small memory block. */
461+ base += new_memory_regions_size + gap_size;
462+
463+ orig_region = memblock.memory.regions;
464+
465+ for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
466+ /*
467+ * Add these small block to fulfill the memblock. We keep a
468+ * gap between the nearby memory to avoid being merged.
469+ */
470+ memblock_add(base, size);
471+ base += size + gap_size;
472+
473+ ASSERT_EQ(memblock.memory.cnt, i + 2);
474+ ASSERT_EQ(memblock.memory.total_size, new_memory_regions_size +
475+ (i + 1) * size);
476+ }
477+
478+ /*
479+ * At there, memblock_double_array() has been succeed, check if it
480+ * update the memory.max.
481+ */
482+ ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
483+
484+ /* memblock_double_array() will reserve the memory it used. Check it. */
485+ ASSERT_EQ(memblock.reserved.cnt, 1);
486+ ASSERT_EQ(memblock.reserved.total_size, new_memory_regions_size);
487+
488+ /*
489+ * Now memblock_double_array() works fine. Let's check after the
490+ * double_array(), the memblock_add() still works as normal.
491+ */
492+ memblock_add(r.base, r.size);
493+ ASSERT_EQ(memblock.memory.regions[0].base, r.base);
494+ ASSERT_EQ(memblock.memory.regions[0].size, r.size);
495+
496+ ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2);
497+ ASSERT_EQ(memblock.memory.total_size, INIT_MEMBLOCK_REGIONS * size +
498+ new_memory_regions_size +
499+ r.size);
500+ ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
501+
502+ dummy_physical_memory_cleanup();
503+
504+ /*
505+ * The current memory.regions is occupying a range of memory that
506+ * allocated from dummy_physical_memory_init(). After free the memory,
507+ * we must not use it. So restore the origin memory region to make sure
508+ * the tests can run as normal and not affected by the double array.
509+ */
510+ memblock.memory.regions = orig_region;
511+ memblock.memory.cnt = INIT_MEMBLOCK_REGIONS;
512+
513+ test_pass_pop();
514+
515+ return 0;
516+}
517+
426518 static int memblock_add_checks(void)
427519 {
428520 prefix_reset();
@@ -438,6 +530,7 @@ static int memblock_add_checks(void) · 9 unmodified lines
438530 memblock_add_twice_check();
439531 memblock_add_between_check();
440532 memblock_add_near_max_check();
533+ memblock_add_many_check();
441534
442535 prefix_pop();
443536
@@ -799,6 +892,96 @@ static int memblock_reserve_near_max_check(void) · 355 unmodified lines
799892 return 0;
800893 }
801894
895+/*
896+ * A test that trying to reserve the 129th memory block.
897+ * Expect to trigger memblock_double_array() to double the
898+ * memblock.memory.max, find a new valid memory as
899+ * reserved.regions.
900+ */
901+static int memblock_reserve_many_check(void)
902+{
903+ int i;
904+ void *orig_region;
905+ struct region r = {
906+ .base = SZ_16K,
907+ .size = SZ_16K,
908+ };
909+ phys_addr_t memory_base = SZ_128K;
910+ phys_addr_t new_reserved_regions_size;
911+
912+ PREFIX_PUSH();
913+
914+ reset_memblock_regions();
915+ memblock_allow_resize();
916+
917+ /* Add a valid memory region used by double_array(). */
918+ dummy_physical_memory_init();
919+ memblock_add(dummy_physical_memory_base(), MEM_SIZE);
920+
921+ for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
922+ /* Reserve some fakes memory region to fulfill the memblock. */
923+ memblock_reserve(memory_base, MEM_SIZE);
924+
925+ ASSERT_EQ(memblock.reserved.cnt, i + 1);
926+ ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE);
927+
928+ /* Keep the gap so these memory region will not be merged. */
929+ memory_base += MEM_SIZE * 2;
930+ }
931+
932+ orig_region = memblock.reserved.regions;
933+
934+ /* This reserve the 129 memory_region, and makes it double array. */
935+ memblock_reserve(memory_base, MEM_SIZE);
936+
937+ /*
938+ * This is the memory region size used by the doubled reserved.regions,
939+ * and it has been reserved due to it has been used. The size is used to
940+ * calculate the total_size that the memblock.reserved have now.
941+ */
942+ new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) *
943+ sizeof(struct memblock_region));
944+ /*
945+ * The double_array() will find a free memory region as the new
946+ * reserved.regions, and the used memory region will be reserved, so
947+ * there will be one more region exist in the reserved memblock. And the
948+ * one more reserved region's size is new_reserved_regions_size.
949+ */
950+ ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2);
951+ ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
952+ new_reserved_regions_size);
953+ ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
954+
955+ /*
956+ * Now memblock_double_array() works fine. Let's check after the
957+ * double_array(), the memblock_reserve() still works as normal.
958+ */
959+ memblock_reserve(r.base, r.size);
960+ ASSERT_EQ(memblock.reserved.regions[0].base, r.base);
961+ ASSERT_EQ(memblock.reserved.regions[0].size, r.size);
962+
963+ ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3);
964+ ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
965+ new_reserved_regions_size +
966+ r.size);
967+ ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
968+
969+ dummy_physical_memory_cleanup();
970+
971+ /*
972+ * The current reserved.regions is occupying a range of memory that
973+ * allocated from dummy_physical_memory_init(). After free the memory,
974+ * we must not use it. So restore the origin memory region to make sure
975+ * the tests can run as normal and not affected by the double array.
976+ */
977+ memblock.reserved.regions = orig_region;
978+ memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS;
979+
980+ test_pass_pop();
981+
982+ return 0;
983+}
984+
802985 static int memblock_reserve_checks(void)
803986 {
804987 prefix_reset();
@@ -813,6 +996,7 @@ static int memblock_reserve_checks(void) · 8 unmodified lines
813996 memblock_reserve_twice_check();
814997 memblock_reserve_between_check();
815998 memblock_reserve_near_max_check();
999+ memblock_reserve_many_check();
8161000
8171001 prefix_pop();
8181002
tools/testing/memblock/tests/common.c+5−2
@@ -5,8 +5,6 @@ · 4 unmodified lines
55 #include <linux/memory_hotplug.h>
66 #include <linux/build_bug.h>
77
8−#define INIT_MEMBLOCK_REGIONS 128
9−#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
108 #define PREFIXES_MAX 15
119 #define DELIM ": "
1210 #define BASIS 10000
@@ -115,6 +113,11 @@ void dummy_physical_memory_cleanup(void) · 102 unmodified lines
115113 free(memory_block.base);
116114 }
117115
116+phys_addr_t dummy_physical_memory_base(void)
117+{
118+ return (phys_addr_t)memory_block.base;
119+}
120+
118121 static void usage(const char *prog)
119122 {
120123 BUILD_BUG_ON(ARRAY_SIZE(help_opts) != ARRAY_SIZE(long_opts) - 1);
tools/testing/memblock/tests/common.h+7−1
@@ -10,14 +10,19 @@ · 9 unmodified lines
1010 #include <linux/printk.h>
1111 #include <../selftests/kselftest.h>
1212
13−#define MEM_SIZE SZ_16K
13+#define MEM_SIZE SZ_32K
1414 #define NUMA_NODES 8
1515
16+#define INIT_MEMBLOCK_REGIONS 128
17+#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
18+
1619 enum test_flags {
1720 /* No special request. */
1821 TEST_F_NONE = 0x0,
1922 /* Perform raw allocations (no zeroing of memory). */
2023 TEST_F_RAW = 0x1,
24+ /* Perform allocations on the exact node specified. */
25+ TEST_F_EXACT = 0x2
2126 };
2227
2328 /**
@@ -124,6 +129,7 @@ void setup_memblock(void); · 100 unmodified lines
124129 void setup_numa_memblock(const unsigned int node_fracs[]);
125130 void dummy_physical_memory_init(void);
126131 void dummy_physical_memory_cleanup(void);
132+phys_addr_t dummy_physical_memory_base(void);
127133 void parse_args(int argc, char **argv);
128134
129135 void test_fail(void);