[PATCH 05/13] MIPS: make setup_zero_pages() use memblock

Mike Rapoport
2025-03-06T18:52:50Z

Allocating the zero pages from memblock is simpler because the memory is
already reserved.

This will also help with pulling out memblock_free_all() to the generic
code and reducing code duplication in arch::mem_init().

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
arch/mips/include/asm/mmzone.h | 2 --
arch/mips/mm/init.c | 16 +++++-----------
2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/arch/mips/include/asm/mmzone.h b/arch/mips/include/asm/mmzone.h
index 14226ea42036..602a21aee9d4 100644
--- a/arch/mips/include/asm/mmzone.h
+++ b/arch/mips/include/asm/mmzone.h
@@ -20,6 +20,4 @@
#define nid_to_addrbase(nid) 0
#endif

-extern void setup_zero_pages(void);
-
#endif /* _ASM_MMZONE_H_ */
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 3db6082c611e..f51cd97376df 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -59,25 +59,19 @@ EXPORT_SYMBOL(zero_page_mask);
/*
* Not static inline because used by IP27 special magic initialization code
*/
-void setup_zero_pages(void)
+static void __init setup_zero_pages(void)
{
- unsigned int order, i;
- struct page *page;
+ unsigned int order;

if (cpu_has_vce)
order = 3;
else
order = 0;

- empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
+ empty_zero_page = (unsigned long)memblock_alloc(PAGE_SIZE << order, PAGE_SIZE);
if (!empty_zero_page)
panic("Oh boy, that early out of memory?");

- page = virt_to_page((void *)empty_zero_page);
- split_page(page, order);
- for (i = 0; i < (1 << order); i++, page++)
- mark_page_reserved(page);
-
zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
}

@@ -470,9 +464,9 @@ void __init mem_init(void)
BUILD_BUG_ON(IS_ENABLED(CONFIG_32BIT) && (PFN_PTE_SHIFT > PAGE_SHIFT));

maar_init();
- memblock_free_all();
setup_zero_pages(); /* Setup zeroed pages. */
mem_init_free_highmem();
+ memblock_free_all();

#ifdef CONFIG_64BIT
if ((unsigned long) &_text > (unsigned long) CKSEG0)
@@ -486,8 +480,8 @@ void __init mem_init(void)
void __init mem_init(void)
{
high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT);
- memblock_free_all();
setup_zero_pages(); /* This comes from node 0 */
+ memblock_free_all();
}
#endif /* !CONFIG_NUMA */

--
2.47.2