From: Muchun Song <muchun.song@linux.dev>
To: Muchun Song <songmuchun@bytedance.com>
Cc: Mike Rapoport <rppt@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>, Michal Hocko <mhocko@suse.com>,
David Laight <david.laight.linux@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>
Subject: Re: [PATCH v3 05/17] mm/sparse-vmemmap: support section-based vmemmap accounting
Date: Tue, 11 Aug 2026 11:45:41 +0800 [thread overview]
Message-ID: <6069cc82-d215-476c-a02f-52e0ae181ea9@linux.dev> (raw)
In-Reply-To: <20260804035535.2846016-6-songmuchun@bytedance.com>
On 2026/8/4 11:55, Muchun Song wrote:
> section_nr_vmemmap_pages() can account ordinary sections and DAX sections,
> but section-based vmemmap optimization keeps its compound order in struct
> mem_section and retains a different number of vmemmap pages.
>
> Teach section_nr_vmemmap_pages() to recognize section-based optimized
> sections and calculate their vmemmap page count from the section order
> and the HVO retained page count.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
> v3:
> - Add vmemmap_optimizable_order() for order-based optimization checks
>
> v2:
> - Remove an unnecessary vmemmap_can_optimize() call to simplify the code
> (suggested by Mike Rapoport).
> - Rewrite the commit message for better understanding.
> ---
> include/linux/mmzone.h | 6 ++++--
> mm/sparse-vmemmap.c | 10 ++++++----
> mm/sparse.h | 16 ++++++++++++++++
> 3 files changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 81e16d71e1f0..663726dd6463 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -107,8 +107,10 @@
> is_power_of_2(sizeof(struct page)) ? \
> MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0)
>
> -/* The number of struct pages covered by the retained vmemmap pages with HVO enabled. */
> -#define VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES (PAGE_SIZE / sizeof(struct page))
> +/* The number of retained vmemmap pages with HVO enabled. */
> +#define VMEMMAP_OPTIMIZATION_PAGES 1
> +#define VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES \
> + (VMEMMAP_OPTIMIZATION_PAGES * PAGE_SIZE / sizeof(struct page))
> #define VMEMMAP_OPTIMIZATION_MIN_ORDER (ilog2(VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES) + 1)
>
> #define __VMEMMAP_OPTIMIZATION_NR_ORDERS \
> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
> index 107215cf8488..b7abc5494bb9 100644
> --- a/mm/sparse-vmemmap.c
> +++ b/mm/sparse-vmemmap.c
> @@ -649,24 +649,26 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
> static int __meminit section_nr_vmemmap_pages(unsigned long pfn, unsigned long nr_pages,
> struct vmem_altmap *altmap, struct dev_pagemap *pgmap)
> {
> - const unsigned int order = pgmap ? pgmap->vmemmap_shift : 0;
> + const struct mem_section *ms = __pfn_to_section(pfn);
> + const int order = pgmap ? pgmap->vmemmap_shift : section_order(ms);
> + const int vmemmap_pages = pgmap ? VMEMMAP_RESERVE_NR : VMEMMAP_OPTIMIZATION_PAGES;
> const unsigned long pages_per_compound = 1UL << order;
>
> VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SUBSECTION));
> VM_WARN_ON_ONCE(nr_pages > PAGES_PER_SECTION);
>
> - if (!vmemmap_can_optimize(altmap, pgmap))
> + if (!vmemmap_can_optimize(altmap, pgmap) && !section_vmemmap_optimizable(ms))
> return DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE);
Sashiko said this conditional logic mix DAX and HVO optimization checks in
a way that severely corrupts vmemmap accounting for nr_memmap_pages.
This is a false positive because its premise is based on memory hotplug
support for HVO. However, HVO cannot be enabled through memory hotplug at
this time.
Muchun,
Thanks.
>
> if (order < PFN_SECTION_SHIFT) {
> VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, pages_per_compound));
> - return VMEMMAP_RESERVE_NR * nr_pages / pages_per_compound;
> + return vmemmap_pages * nr_pages / pages_per_compound;
> }
>
> VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION));
>
> if (IS_ALIGNED(pfn, pages_per_compound))
> - return VMEMMAP_RESERVE_NR;
> + return vmemmap_pages;
>
> return 0;
> }
> diff --git a/mm/sparse.h b/mm/sparse.h
> index b9b6b47e85ce..6ad190ec48cf 100644
> --- a/mm/sparse.h
> +++ b/mm/sparse.h
> @@ -43,6 +43,17 @@ static inline bool pfn_vmemmap_optimizable(unsigned long pfn)
> return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES;
> }
>
> +static inline bool vmemmap_optimizable_order(unsigned int order)
> +{
> + if (!IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP))
> + return false;
> +
> + if (!is_power_of_2(sizeof(struct page)))
> + return false;
> +
> + return order >= VMEMMAP_OPTIMIZATION_MIN_ORDER;
> +}
> +
> /*
> * mm/sparse.c
> */
> @@ -80,6 +91,11 @@ static inline void __section_mark_present(struct mem_section *ms,
>
> ms->section_mem_map |= SECTION_MARKED_PRESENT;
> }
> +
> +static inline bool section_vmemmap_optimizable(const struct mem_section *section)
> +{
> + return vmemmap_optimizable_order(section_order(section));
> +}
> #else
> static inline void sparse_init(void) {}
> #endif /* CONFIG_SPARSEMEM */
next prev parent reply other threads:[~2026-08-11 3:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 3:55 [PATCH v3 00/17] mm: Introduce section-based vmemmap optimization for HugeTLB Muchun Song
2026-08-04 3:55 ` [PATCH v3 01/17] mm/sparse: relax struct mem_section size constraints Muchun Song
2026-08-04 3:55 ` [PATCH v3 02/17] mm/sparse-vmemmap: rename HVO order macros Muchun Song
2026-08-04 3:55 ` [PATCH v3 03/17] mm/mm_init: skip initializing shared vmemmap tail pages Muchun Song
2026-08-11 3:40 ` Muchun Song
2026-08-04 3:55 ` [PATCH v3 04/17] mm/sparse-vmemmap: initialize shared tail vmemmap pages on allocation Muchun Song
2026-08-04 3:55 ` [PATCH v3 05/17] mm/sparse-vmemmap: support section-based vmemmap accounting Muchun Song
2026-08-11 3:45 ` Muchun Song [this message]
2026-08-04 3:55 ` [PATCH v3 06/17] mm/mm_init: factor out pfn_to_zone() Muchun Song
2026-08-04 3:55 ` [PATCH v3 07/17] mm/sparse-vmemmap: move vmemmap_get_tail() before PTE population Muchun Song
2026-08-04 3:55 ` [PATCH v3 08/17] mm/sparse-vmemmap: support section-based vmemmap optimization Muchun Song
2026-08-06 3:04 ` Muchun Song
2026-08-11 3:54 ` Muchun Song
2026-08-04 3:55 ` [PATCH v3 09/17] mm/sparse: initialize memory sections earlier Muchun Song
2026-08-04 3:55 ` [PATCH v3 10/17] mm/hugetlb: switch HugeTLB to section-based vmemmap optimization Muchun Song
2026-08-11 3:58 ` Muchun Song
2026-08-04 3:55 ` [PATCH v3 11/17] mm/sparse-vmemmap: remove SPARSEMEM_VMEMMAP_PREINIT support Muchun Song
2026-08-04 3:55 ` [PATCH v3 12/17] mm/sparse: inline usemap allocation into sparse_init_nid() Muchun Song
2026-08-04 3:55 ` [PATCH v3 13/17] mm/sparse: remove section_map_size() Muchun Song
2026-08-04 3:55 ` [PATCH v3 14/17] mm/hugetlb: remove HUGE_BOOTMEM_HVO Muchun Song
2026-08-04 3:55 ` [PATCH v3 15/17] mm/hugetlb: remove HUGE_BOOTMEM_CMA Muchun Song
2026-08-04 3:55 ` [PATCH v3 16/17] mm/hugetlb: localize struct huge_bootmem_page Muchun Song
2026-08-04 3:55 ` [PATCH v3 17/17] mm/hugetlb: localize HUGE_BOOTMEM_ZONES_VALID Muchun Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6069cc82-d215-476c-a02f-52e0ae181ea9@linux.dev \
--to=muchun.song@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=david.laight.linux@gmail.com \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=rppt@kernel.org \
--cc=songmuchun@bytedance.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.