Skip to content

Commit 6e245ad

Browse files
rppttorvalds
authored andcommitted
memblock: reduce number of parameters in for_each_mem_range()
Currently for_each_mem_range() and for_each_mem_range_rev() iterators are the most generic way to traverse memblock regions. As such, they have 8 parameters and they are hardly convenient to users. Most users choose to utilize one of their wrappers and the only user that actually needs most of the parameters is memblock itself. To avoid yet another naming for memblock iterators, rename the existing for_each_mem_range[_rev]() to __for_each_mem_range[_rev]() and add a new for_each_mem_range[_rev]() wrappers with only index, start and end parameters. The new wrapper nicely fits into init_unavailable_mem() and will be used in upcoming changes to simplify memblock traversals. Signed-off-by: Mike Rapoport <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Thomas Bogendoerfer <[email protected]> [MIPS] Cc: Andy Lutomirski <[email protected]> Cc: Baoquan He <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Daniel Axtens <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Emil Renner Berthing <[email protected]> Cc: Hari Bathini <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Marek Szyprowski <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Russell King <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yoshinori Sato <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 87c5587 commit 6e245ad

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ ForEachMacros:
207207
- 'for_each_memblock_type'
208208
- 'for_each_memcg_cache_index'
209209
- 'for_each_mem_pfn_range'
210+
- '__for_each_mem_range'
210211
- 'for_each_mem_range'
212+
- '__for_each_mem_range_rev'
211213
- 'for_each_mem_range_rev'
212214
- 'for_each_migratetype_order'
213215
- 'for_each_msi_entry'

arch/arm64/kernel/machine_kexec_file.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
215215
phys_addr_t start, end;
216216

217217
nr_ranges = 1; /* for exclusion of crashkernel region */
218-
for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
219-
MEMBLOCK_NONE, &start, &end, NULL)
218+
for_each_mem_range(i, &start, &end)
220219
nr_ranges++;
221220

222221
cmem = kmalloc(struct_size(cmem, ranges, nr_ranges), GFP_KERNEL);
@@ -225,8 +224,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
225224

226225
cmem->max_nr_ranges = nr_ranges;
227226
cmem->nr_ranges = 0;
228-
for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
229-
MEMBLOCK_NONE, &start, &end, NULL) {
227+
for_each_mem_range(i, &start, &end) {
230228
cmem->ranges[cmem->nr_ranges].start = start;
231229
cmem->ranges[cmem->nr_ranges].end = end - 1;
232230
cmem->nr_ranges++;

arch/powerpc/kexec/file_load_64.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ static int __locate_mem_hole_top_down(struct kexec_buf *kbuf,
250250
phys_addr_t start, end;
251251
u64 i;
252252

253-
for_each_mem_range_rev(i, &memblock.memory, NULL, NUMA_NO_NODE,
254-
MEMBLOCK_NONE, &start, &end, NULL) {
253+
for_each_mem_range_rev(i, &start, &end) {
255254
/*
256255
* memblock uses [start, end) convention while it is
257256
* [start, end] here. Fix the off-by-one to have the
@@ -350,8 +349,7 @@ static int __locate_mem_hole_bottom_up(struct kexec_buf *kbuf,
350349
phys_addr_t start, end;
351350
u64 i;
352351

353-
for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
354-
MEMBLOCK_NONE, &start, &end, NULL) {
352+
for_each_mem_range(i, &start, &end) {
355353
/*
356354
* memblock uses [start, end) convention while it is
357355
* [start, end] here. Fix the off-by-one to have the

include/linux/memblock.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
162162
#endif /* CONFIG_HAVE_MEMBLOCK_PHYS_MAP */
163163

164164
/**
165-
* for_each_mem_range - iterate through memblock areas from type_a and not
165+
* __for_each_mem_range - iterate through memblock areas from type_a and not
166166
* included in type_b. Or just type_a if type_b is NULL.
167167
* @i: u64 used as loop variable
168168
* @type_a: ptr to memblock_type to iterate
@@ -173,7 +173,7 @@ static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
173173
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
174174
* @p_nid: ptr to int for nid of the range, can be %NULL
175175
*/
176-
#define for_each_mem_range(i, type_a, type_b, nid, flags, \
176+
#define __for_each_mem_range(i, type_a, type_b, nid, flags, \
177177
p_start, p_end, p_nid) \
178178
for (i = 0, __next_mem_range(&i, nid, flags, type_a, type_b, \
179179
p_start, p_end, p_nid); \
@@ -182,7 +182,7 @@ static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
182182
p_start, p_end, p_nid))
183183

184184
/**
185-
* for_each_mem_range_rev - reverse iterate through memblock areas from
185+
* __for_each_mem_range_rev - reverse iterate through memblock areas from
186186
* type_a and not included in type_b. Or just type_a if type_b is NULL.
187187
* @i: u64 used as loop variable
188188
* @type_a: ptr to memblock_type to iterate
@@ -193,15 +193,36 @@ static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
193193
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
194194
* @p_nid: ptr to int for nid of the range, can be %NULL
195195
*/
196-
#define for_each_mem_range_rev(i, type_a, type_b, nid, flags, \
197-
p_start, p_end, p_nid) \
196+
#define __for_each_mem_range_rev(i, type_a, type_b, nid, flags, \
197+
p_start, p_end, p_nid) \
198198
for (i = (u64)ULLONG_MAX, \
199-
__next_mem_range_rev(&i, nid, flags, type_a, type_b,\
199+
__next_mem_range_rev(&i, nid, flags, type_a, type_b, \
200200
p_start, p_end, p_nid); \
201201
i != (u64)ULLONG_MAX; \
202202
__next_mem_range_rev(&i, nid, flags, type_a, type_b, \
203203
p_start, p_end, p_nid))
204204

205+
/**
206+
* for_each_mem_range - iterate through memory areas.
207+
* @i: u64 used as loop variable
208+
* @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
209+
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
210+
*/
211+
#define for_each_mem_range(i, p_start, p_end) \
212+
__for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, \
213+
MEMBLOCK_NONE, p_start, p_end, NULL)
214+
215+
/**
216+
* for_each_mem_range_rev - reverse iterate through memblock areas from
217+
* type_a and not included in type_b. Or just type_a if type_b is NULL.
218+
* @i: u64 used as loop variable
219+
* @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
220+
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
221+
*/
222+
#define for_each_mem_range_rev(i, p_start, p_end) \
223+
__for_each_mem_range_rev(i, &memblock.memory, NULL, NUMA_NO_NODE, \
224+
MEMBLOCK_NONE, p_start, p_end, NULL)
225+
205226
/**
206227
* for_each_reserved_mem_region - iterate over all reserved memblock areas
207228
* @i: u64 used as loop variable
@@ -307,8 +328,8 @@ int __init deferred_page_init_max_threads(const struct cpumask *node_cpumask);
307328
* soon as memblock is initialized.
308329
*/
309330
#define for_each_free_mem_range(i, nid, flags, p_start, p_end, p_nid) \
310-
for_each_mem_range(i, &memblock.memory, &memblock.reserved, \
311-
nid, flags, p_start, p_end, p_nid)
331+
__for_each_mem_range(i, &memblock.memory, &memblock.reserved, \
332+
nid, flags, p_start, p_end, p_nid)
312333

313334
/**
314335
* for_each_free_mem_range_reverse - rev-iterate through free memblock areas
@@ -324,8 +345,8 @@ int __init deferred_page_init_max_threads(const struct cpumask *node_cpumask);
324345
*/
325346
#define for_each_free_mem_range_reverse(i, nid, flags, p_start, p_end, \
326347
p_nid) \
327-
for_each_mem_range_rev(i, &memblock.memory, &memblock.reserved, \
328-
nid, flags, p_start, p_end, p_nid)
348+
__for_each_mem_range_rev(i, &memblock.memory, &memblock.reserved, \
349+
nid, flags, p_start, p_end, p_nid)
329350

330351
int memblock_set_node(phys_addr_t base, phys_addr_t size,
331352
struct memblock_type *type, int nid);

mm/page_alloc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6990,8 +6990,7 @@ static void __init init_unavailable_mem(void)
69906990
* Loop through unavailable ranges not covered by memblock.memory.
69916991
*/
69926992
pgcnt = 0;
6993-
for_each_mem_range(i, &memblock.memory, NULL,
6994-
NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end, NULL) {
6993+
for_each_mem_range(i, &start, &end) {
69956994
if (next < start)
69966995
pgcnt += init_unavailable_range(PFN_DOWN(next),
69976996
PFN_UP(start));

0 commit comments

Comments
 (0)