Skip to content

Commit

Permalink
memblock: use separate iterators for memory and reserved regions
Browse files Browse the repository at this point in the history
for_each_memblock() is used to iterate over memblock.memory in a few
places that use data from memblock_region rather than the memory ranges.

Introduce separate for_each_mem_region() and
for_each_reserved_mem_region() to improve encapsulation of memblock
internals from its users.

Signed-off-by: Mike Rapoport <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Baoquan He <[email protected]>
Acked-by: Ingo Molnar <[email protected]>			[x86]
Acked-by: Thomas Bogendoerfer <[email protected]>	[MIPS]
Acked-by: Miguel Ojeda <[email protected]>	[.clang-format]
Cc: Andy Lutomirski <[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: 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: 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]>
  • Loading branch information
rppt authored and torvalds committed Oct 14, 2020
1 parent 9f3d5ea commit cc6de16
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ ForEachMacros:
- 'for_each_matching_node'
- 'for_each_matching_node_and_match'
- 'for_each_member'
- 'for_each_memblock'
- 'for_each_mem_region'
- 'for_each_memblock_type'
- 'for_each_memcg_cache_index'
- 'for_each_mem_pfn_range'
Expand Down Expand Up @@ -274,6 +274,7 @@ ForEachMacros:
- 'for_each_requested_gpio'
- 'for_each_requested_gpio_in_range'
- 'for_each_reserved_mem_range'
- 'for_each_reserved_mem_region'
- 'for_each_rtd_codec_dais'
- 'for_each_rtd_codec_dais_rollback'
- 'for_each_rtd_components'
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void __init request_standard_resources(void)
if (!standard_resources)
panic("%s: Failed to allocate %zu bytes\n", __func__, res_size);

for_each_memblock(memory, region) {
for_each_mem_region(region) {
res = &standard_resources[i++];
if (memblock_is_nomap(region)) {
res->name = "reserved";
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/mm/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static int __init numa_register_nodes(void)
struct memblock_region *mblk;

/* Check that valid nid is set to memblks */
for_each_memblock(memory, mblk) {
for_each_mem_region(mblk) {
int mblk_nid = memblock_get_region_node(mblk);

if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/netlogic/xlp/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void nlm_fixup_mem(void)
const int pref_backup = 512;
struct memblock_region *mem;

for_each_memblock(memory, mem) {
for_each_mem_region(mem) {
memblock_remove(mem->base + mem->size - pref_backup,
pref_backup);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ static void __init resource_init(void)
{
struct memblock_region *region;

for_each_memblock(memory, region) {
for_each_mem_region(region) {
struct resource *res;

res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/mm/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
* memory ranges, because quirks such as trim_snb_memory()
* reserve specific pages for Sandy Bridge graphics. ]
*/
for_each_memblock(reserved, mb_region) {
for_each_reserved_mem_region(mb_region) {
int nid = memblock_get_region_node(mb_region);

if (nid != MAX_NUMNODES)
Expand Down
19 changes: 16 additions & 3 deletions include/linux/memblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,22 @@ static inline unsigned long memblock_region_reserved_end_pfn(const struct memblo
return PFN_UP(reg->base + reg->size);
}

#define for_each_memblock(memblock_type, region) \
for (region = memblock.memblock_type.regions; \
region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
/**
* for_each_mem_region - itereate over memory regions
* @region: loop variable
*/
#define for_each_mem_region(region) \
for (region = memblock.memory.regions; \
region < (memblock.memory.regions + memblock.memory.cnt); \
region++)

/**
* for_each_reserved_mem_region - itereate over reserved memory regions
* @region: loop variable
*/
#define for_each_reserved_mem_region(region) \
for (region = memblock.reserved.regions; \
region < (memblock.reserved.regions + memblock.reserved.cnt); \
region++)

extern void *alloc_large_system_hash(const char *tablename,
Expand Down
4 changes: 2 additions & 2 deletions mm/memblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ static phys_addr_t __init_memblock __find_max_addr(phys_addr_t limit)
* the memory memblock regions, if the @limit exceeds the total size
* of those regions, max_addr will keep original value PHYS_ADDR_MAX
*/
for_each_memblock(memory, r) {
for_each_mem_region(r) {
if (limit <= r->size) {
max_addr = r->base + limit;
break;
Expand Down Expand Up @@ -1837,7 +1837,7 @@ void __init_memblock memblock_trim_memory(phys_addr_t align)
phys_addr_t start, end, orig_start, orig_end;
struct memblock_region *r;

for_each_memblock(memory, r) {
for_each_mem_region(r) {
orig_start = r->base;
orig_end = r->base + r->size;
start = round_up(orig_start, align);
Expand Down
8 changes: 4 additions & 4 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5961,7 +5961,7 @@ overlap_memmap_init(unsigned long zone, unsigned long *pfn)

if (mirrored_kernelcore && zone == ZONE_MOVABLE) {
if (!r || *pfn >= memblock_region_memory_end_pfn(r)) {
for_each_memblock(memory, r) {
for_each_mem_region(r) {
if (*pfn < memblock_region_memory_end_pfn(r))
break;
}
Expand Down Expand Up @@ -6546,7 +6546,7 @@ static unsigned long __init zone_absent_pages_in_node(int nid,
unsigned long start_pfn, end_pfn;
struct memblock_region *r;

for_each_memblock(memory, r) {
for_each_mem_region(r) {
start_pfn = clamp(memblock_region_memory_base_pfn(r),
zone_start_pfn, zone_end_pfn);
end_pfn = clamp(memblock_region_memory_end_pfn(r),
Expand Down Expand Up @@ -7140,7 +7140,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
* options.
*/
if (movable_node_is_enabled()) {
for_each_memblock(memory, r) {
for_each_mem_region(r) {
if (!memblock_is_hotpluggable(r))
continue;

Expand All @@ -7161,7 +7161,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
if (mirrored_kernelcore) {
bool mem_below_4gb_not_mirrored = false;

for_each_memblock(memory, r) {
for_each_mem_region(r) {
if (memblock_is_mirror(r))
continue;

Expand Down

0 comments on commit cc6de16

Please sign in to comment.