mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 21:24:08 +08:00
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: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Andrew 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.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e9aa36ccbb
commit
cddb5ddf2b
@ -347,61 +347,29 @@ static void __init free_unused_memmap(void)
|
||||
#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)
|
||||
{
|
||||
#ifdef CONFIG_HIGHMEM
|
||||
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 */
|
||||
for_each_memblock(memory, mem) {
|
||||
unsigned long start = memblock_region_memory_base_pfn(mem);
|
||||
unsigned long end = memblock_region_memory_end_pfn(mem);
|
||||
for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
|
||||
&range_start, &range_end, NULL) {
|
||||
unsigned long start = PHYS_PFN(range_start);
|
||||
unsigned long end = PHYS_PFN(range_end);
|
||||
|
||||
/* Ignore complete lowmem entries */
|
||||
if (end <= max_low)
|
||||
continue;
|
||||
|
||||
if (memblock_is_nomap(mem))
|
||||
continue;
|
||||
|
||||
/* Truncate partial highmem entries */
|
||||
if (start < max_low)
|
||||
start = max_low;
|
||||
|
||||
/* Find and exclude any reserved regions */
|
||||
for_each_memblock(reserved, res) {
|
||||
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);
|
||||
for (; start < end; start++)
|
||||
free_highmem_page(pfn_to_page(start));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -79,67 +79,32 @@ void __init zones_init(void)
|
||||
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)
|
||||
{
|
||||
#ifdef CONFIG_HIGHMEM
|
||||
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 */
|
||||
for_each_memblock(memory, mem) {
|
||||
unsigned long start = memblock_region_memory_base_pfn(mem);
|
||||
unsigned long end = memblock_region_memory_end_pfn(mem);
|
||||
for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
|
||||
&range_start, &range_end, NULL) {
|
||||
unsigned long start = PHYS_PFN(range_start);
|
||||
unsigned long end = PHYS_PFN(range_end);
|
||||
|
||||
/* Ignore complete lowmem entries */
|
||||
if (end <= max_low)
|
||||
continue;
|
||||
|
||||
if (memblock_is_nomap(mem))
|
||||
continue;
|
||||
|
||||
/* Truncate partial highmem entries */
|
||||
if (start < max_low)
|
||||
start = max_low;
|
||||
|
||||
/* Find and exclude any reserved regions */
|
||||
for_each_memblock(reserved, res) {
|
||||
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);
|
||||
for (; start < end; start++)
|
||||
free_highmem_page(pfn_to_page(start));
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void __init free_highpages(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize memory pages.
|
||||
|
Loading…
Reference in New Issue
Block a user