Commit cddb5ddf authored by Mike Rapoport's avatar Mike Rapoport Committed by Linus Torvalds

arm, xtensa: simplify initialization of high memory pages

free_highpages() in both arm and xtensa essentially open-code
for_each_free_mem_range() loop to detect high memory pages that were not
reserved and that should be initialized and passed to the buddy allocator.

Replace open-coded implementation of for_each_free_mem_range() with usage
of memblock API to simplify the code.
Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Tested-by: Max Filippov <jcmvbkbc@gmail.com>	[xtensa]
Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>	[xtensa]
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Emil Renner Berthing <kernel@esmil.dk>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Link: https://lkml.kernel.org/r/20200818151634.14343-4-rppt@kernel.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e9aa36cc
...@@ -347,61 +347,29 @@ static void __init free_unused_memmap(void) ...@@ -347,61 +347,29 @@ static void __init free_unused_memmap(void)
#endif #endif
} }
#ifdef CONFIG_HIGHMEM
static inline void free_area_high(unsigned long pfn, unsigned long end)
{
for (; pfn < end; pfn++)
free_highmem_page(pfn_to_page(pfn));
}
#endif
static void __init free_highpages(void) static void __init free_highpages(void)
{ {
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
unsigned long max_low = max_low_pfn; unsigned long max_low = max_low_pfn;
struct memblock_region *mem, *res; phys_addr_t range_start, range_end;
u64 i;
/* set highmem page free */ /* set highmem page free */
for_each_memblock(memory, mem) { for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
unsigned long start = memblock_region_memory_base_pfn(mem); &range_start, &range_end, NULL) {
unsigned long end = memblock_region_memory_end_pfn(mem); unsigned long start = PHYS_PFN(range_start);
unsigned long end = PHYS_PFN(range_end);
/* Ignore complete lowmem entries */ /* Ignore complete lowmem entries */
if (end <= max_low) if (end <= max_low)
continue; continue;
if (memblock_is_nomap(mem))
continue;
/* Truncate partial highmem entries */ /* Truncate partial highmem entries */
if (start < max_low) if (start < max_low)
start = max_low; start = max_low;
/* Find and exclude any reserved regions */ for (; start < end; start++)
for_each_memblock(reserved, res) { free_highmem_page(pfn_to_page(start));
unsigned long res_start, res_end;
res_start = memblock_region_reserved_base_pfn(res);
res_end = memblock_region_reserved_end_pfn(res);
if (res_end < start)
continue;
if (res_start < start)
res_start = start;
if (res_start > end)
res_start = end;
if (res_end > end)
res_end = end;
if (res_start != start)
free_area_high(start, res_start);
start = res_end;
if (start == end)
break;
}
/* And now free anything which remains */
if (start < end)
free_area_high(start, end);
} }
#endif #endif
} }
......
...@@ -79,67 +79,32 @@ void __init zones_init(void) ...@@ -79,67 +79,32 @@ void __init zones_init(void)
free_area_init(max_zone_pfn); free_area_init(max_zone_pfn);
} }
#ifdef CONFIG_HIGHMEM
static void __init free_area_high(unsigned long pfn, unsigned long end)
{
for (; pfn < end; pfn++)
free_highmem_page(pfn_to_page(pfn));
}
static void __init free_highpages(void) static void __init free_highpages(void)
{ {
#ifdef CONFIG_HIGHMEM
unsigned long max_low = max_low_pfn; unsigned long max_low = max_low_pfn;
struct memblock_region *mem, *res; phys_addr_t range_start, range_end;
u64 i;
reset_all_zones_managed_pages();
/* set highmem page free */ /* set highmem page free */
for_each_memblock(memory, mem) { for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
unsigned long start = memblock_region_memory_base_pfn(mem); &range_start, &range_end, NULL) {
unsigned long end = memblock_region_memory_end_pfn(mem); unsigned long start = PHYS_PFN(range_start);
unsigned long end = PHYS_PFN(range_end);
/* Ignore complete lowmem entries */ /* Ignore complete lowmem entries */
if (end <= max_low) if (end <= max_low)
continue; continue;
if (memblock_is_nomap(mem))
continue;
/* Truncate partial highmem entries */ /* Truncate partial highmem entries */
if (start < max_low) if (start < max_low)
start = max_low; start = max_low;
/* Find and exclude any reserved regions */ for (; start < end; start++)
for_each_memblock(reserved, res) { free_highmem_page(pfn_to_page(start));
unsigned long res_start, res_end;
res_start = memblock_region_reserved_base_pfn(res);
res_end = memblock_region_reserved_end_pfn(res);
if (res_end < start)
continue;
if (res_start < start)
res_start = start;
if (res_start > end)
res_start = end;
if (res_end > end)
res_end = end;
if (res_start != start)
free_area_high(start, res_start);
start = res_end;
if (start == end)
break;
}
/* And now free anything which remains */
if (start < end)
free_area_high(start, end);
} }
}
#else
static void __init free_highpages(void)
{
}
#endif #endif
}
/* /*
* Initialize memory pages. * Initialize memory pages.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment