section_vmemmap_optimizable() can already decide whether a section uses vmemmap optimization based on the section compound order. The DAX-specific vmemmap_can_optimize() helper duplicates that policy, so remove it to simplify the code.
Signed-off-by: Muchun Song <[email protected]> --- include/linux/mm.h | 37 ------------------------------------- mm/sparse-vmemmap.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index e875f73b0c6f..4fb48fbe712d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -38,7 +38,6 @@ #include <linux/bitops.h> #include <linux/iommu-debug-pagealloc.h> #include <linux/kcsan-checks.h> -#include <linux/vmemmap-optimization.h> struct mempolicy; struct anon_vma; @@ -5395,42 +5394,6 @@ static inline void vmem_altmap_free(struct vmem_altmap *altmap, } #endif -#ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP -static inline bool __vmemmap_can_optimize(struct vmem_altmap *altmap, - struct dev_pagemap *pgmap) -{ - unsigned long nr_pages; - unsigned long nr_vmemmap_pages; - - if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) - return false; - - if (!pgmap || !is_power_of_2(sizeof(struct page))) - return false; - - nr_pages = pgmap_vmemmap_nr(pgmap); - nr_vmemmap_pages = ((nr_pages * sizeof(struct page)) >> PAGE_SHIFT); - /* - * For vmemmap optimization with DAX we need minimum 2 vmemmap - * pages. See layout diagram in Documentation/mm/vmemmap_dedup.rst - */ - return !altmap && (nr_vmemmap_pages > VMEMMAP_OPTIMIZATION_PAGES); -} -/* - * If we don't have an architecture override, use the generic rule - */ -#ifndef vmemmap_can_optimize -#define vmemmap_can_optimize __vmemmap_can_optimize -#endif - -#else -static inline bool vmemmap_can_optimize(struct vmem_altmap *altmap, - struct dev_pagemap *pgmap) -{ - return false; -} -#endif - enum mf_flags { MF_COUNT_INCREASED = 1 << 0, MF_ACTION_REQUIRED = 1 << 1, diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 3e9d6617c4bb..43559593107c 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -466,12 +466,20 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, { unsigned long start = (unsigned long) pfn_to_page(pfn); unsigned long end = start + nr_pages * sizeof(struct page); + struct mem_section *ms = __pfn_to_section(pfn); int r; if (WARN_ON_ONCE(!IS_ALIGNED(pfn, PAGES_PER_SUBSECTION) || !IS_ALIGNED(nr_pages, PAGES_PER_SUBSECTION))) return NULL; + /* + * Vmemmap optimization is not supported when vmemmap pages are backed + * by an altmap. + */ + if (altmap && section_vmemmap_optimizable(ms)) + section_set_compound_order(ms, 0); + r = vmemmap_populate(start, end, nid, altmap); if (r < 0) return NULL; @@ -699,10 +707,9 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, struct mem_section *ms = __pfn_to_section(pfn); struct mem_section_usage *usage = NULL; struct page *memmap; - unsigned int order; + unsigned int order = pgmap ? pgmap->vmemmap_shift : 0; int rc; - order = vmemmap_can_optimize(altmap, pgmap) ? pgmap->vmemmap_shift : 0; if (nr_pages < PAGES_PER_SECTION && section_compound_order(ms)) return ERR_PTR(-EOPNOTSUPP); -- 2.54.0
