[PATCH v2 2/5] powerpc/mm: drop powerpc vmemmap_can_optimize()
Muchun Song
songmuchun at bytedance.com
Wed Nov 4 22:12:14 PST 2026
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 <songmuchun at bytedance.com>
---
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 | 31 ++++++++++++++++++++++
mm/sparse.h | 5 ----
5 files changed, 33 insertions(+), 20 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..4d6928f717cf 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>
@@ -282,6 +283,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
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..5c09da4df4d8 100644
--- a/include/linux/vmemmap-optimization.h
+++ b/include/linux/vmemmap-optimization.h
@@ -57,6 +57,27 @@ static inline void section_set_compound_order_range(unsigned long pfn,
section_set_compound_order(__nr_to_section(section_nr + i), order);
}
+static inline bool section_vmemmap_optimizable(const struct mem_section *section)
+{
+ return vmemmap_optimizable_order(section_compound_order(section));
+}
+
+static inline void 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 | nr_pages, PAGES_PER_SECTION));
+ section_set_compound_order(section, 0);
+}
+
static inline unsigned int pfn_to_section_compound_order(unsigned long pfn)
{
return section_compound_order(__pfn_to_section(pfn));
@@ -79,6 +100,16 @@ static inline void section_set_compound_order_range(unsigned long pfn,
{
}
+static inline bool section_vmemmap_optimizable(const struct mem_section *section)
+{
+ return false;
+}
+
+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.h b/mm/sparse.h
index fdbc4cacf91d..9b81a549d928 100644
--- a/mm/sparse.h
+++ b/mm/sparse.h
@@ -46,11 +46,6 @@ static inline size_t mem_section_usage_size(void)
return struct_size_t(struct mem_section_usage, pageblock_flags,
BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS));
}
-
-static inline bool section_vmemmap_optimizable(const struct mem_section *ms)
-{
- return vmemmap_optimizable_order(section_compound_order(ms));
-}
#else
static inline void sparse_init(void) {}
static inline void sparse_sections_init(void) {}
--
2.54.0
More information about the linux-riscv
mailing list