Whether the optimized mapping can be used is now decided in the architecture-specific vmemmap_populate() path. When PowerPC has to fall back, such as on Hash MMU, it can disable optimization for the populated vmemmap range there.
Add section_vmemmap_optimization_disable() to centralize this fallback, use it in the Hash MMU path, and drop the radix-specific vmemmap_can_optimize() override. Signed-off-by: Muchun Song <[email protected]> --- v3: - Move section_vmemmap_optimization_disable() to mm/sparse-vmemmap.c to avoid the LoongArch header dependency (reported by Sashiko) v2: - Add section_vmemmap_optimization_disable() for architecture fallbacks - Use the helper for the PowerPC Hash MMU path - Include vmemmap-optimization.h directly (reported by Sashiko) --- arch/powerpc/include/asm/book3s/64/radix.h | 5 ----- arch/powerpc/mm/book3s64/radix_pgtable.c | 10 ---------- arch/powerpc/mm/init_64.c | 2 ++ include/linux/vmemmap-optimization.h | 6 ++++++ mm/sparse-vmemmap.c | 17 +++++++++++++++++ 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/include/asm/book3s/64/radix.h index 8452a2714cb1..df67209b0c5b 100644 --- a/arch/powerpc/include/asm/book3s/64/radix.h +++ b/arch/powerpc/include/asm/book3s/64/radix.h @@ -351,10 +351,5 @@ int radix__create_section_mapping(unsigned long start, unsigned long end, int nid, pgprot_t prot); int radix__remove_section_mapping(unsigned long start, unsigned long end); #endif /* CONFIG_MEMORY_HOTPLUG */ - -#ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP -#define vmemmap_can_optimize vmemmap_can_optimize -bool vmemmap_can_optimize(struct vmem_altmap *altmap, struct dev_pagemap *pgmap); -#endif #endif /* __ASSEMBLER__ */ #endif diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c index 2924604fbb38..63f369d296b4 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -978,16 +978,6 @@ int __meminit radix__vmemmap_create_mapping(unsigned long start, return 0; } -#ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP -bool vmemmap_can_optimize(struct vmem_altmap *altmap, struct dev_pagemap *pgmap) -{ - if (radix_enabled()) - return __vmemmap_can_optimize(altmap, pgmap); - - return false; -} -#endif - int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node, unsigned long addr, unsigned long next) { diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c index 0e777d7dc332..7329fcacdaf4 100644 --- a/arch/powerpc/mm/init_64.c +++ b/arch/powerpc/mm/init_64.c @@ -24,6 +24,7 @@ #include <linux/types.h> #include <linux/mman.h> #include <linux/mm.h> +#include <linux/vmemmap-optimization.h> #include <linux/swap.h> #include <linux/stddef.h> #include <linux/vmalloc.h> @@ -281,6 +282,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, if (radix_enabled()) return radix__vmemmap_populate(start, end, node, altmap); #endif + section_vmemmap_optimization_disable(start, end); return __vmemmap_populate(start, end, node, altmap); } diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h index 858311a71b0c..22e5a322be0b 100644 --- a/include/linux/vmemmap-optimization.h +++ b/include/linux/vmemmap-optimization.h @@ -63,6 +63,7 @@ static inline unsigned int pfn_to_section_compound_order(unsigned long pfn) } struct page *vmemmap_shared_tail_page(unsigned int order, struct zone *zone); +void section_vmemmap_optimization_disable(unsigned long start, unsigned long end); #else static inline unsigned int section_compound_order(const struct mem_section *section) { @@ -79,6 +80,11 @@ static inline void section_set_compound_order_range(unsigned long pfn, { } +static inline void section_vmemmap_optimization_disable(unsigned long start, + unsigned long end) +{ +} + static inline unsigned int pfn_to_section_compound_order(unsigned long pfn) { return 0; diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index b8b55e12f5ba..57aa5c2d8034 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -232,6 +232,23 @@ struct page __ref *vmemmap_shared_tail_page(unsigned int order, struct zone *zon return page; } + +void __meminit section_vmemmap_optimization_disable(unsigned long start, + unsigned long end) +{ + unsigned long pfn = page_to_pfn((struct page *)start); + unsigned long nr_pages = (end - start) / sizeof(struct page); + struct mem_section *section = __pfn_to_section(pfn); + + if (nr_pages < PAGES_PER_SECTION) { + VM_WARN_ON_ONCE(section_vmemmap_optimizable(section)); + return; + } + + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn, PAGES_PER_SECTION)); + VM_WARN_ON_ONCE(nr_pages != PAGES_PER_SECTION); + section_set_compound_order(section, 0); +} #endif static __meminit void *vmemmap_alloc_pte(unsigned long pfn, int node, -- 2.54.0
