* [PATCH 0/2] mm: Track vmemmap optimization state in shared backing pages
@ 2026-12-04 6:50 Muchun Song
2026-12-04 6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song
2026-12-04 6:50 ` [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized Muchun Song
0 siblings, 2 replies; 9+ messages in thread
From: Muchun Song @ 2026-12-04 6:50 UTC (permalink / raw)
To: Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton
Cc: Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko,
Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm,
Muchun Song
Folio-based vmemmap optimization currently requires HugeTLB to maintain
HPG_vmemmap_optimized separately from the vmemmap mapping. The runtime
update is counterintuitive: when TLB flushing is deferred, the flag must
be set before remapping so that it is copied to the replacement head
page, then cleared if optimization fails. Boot-time HugeTLB setup also
needs an explicit transfer from section metadata into the flag.
The same representation is useful to future shared-vmemmap users [1].
The FS-DAX prototype currently determines whether a metadata page still
uses shared backing by looking up its vmemmap PTE and comparing the mapped
backing page with the shared template. A future revision can instead
test the common flag directly through the vmemmap address, avoiding
page-table identity as the state representation for shared metadata.
Reuse PG_owner_2 in the first struct page slot of each shared backing
page, and provide folio_vmemmap_optimized() as the common query. Patch 1
introduces the generic state representation and query. Patch 2 switches
HugeTLB to it and removes the private flag and its explicit state updates.
[1] https://lore.kernel.org/20260903122128.12264-4-songmuchun@bytedance.com
Muchun Song (2):
mm/vmemmap-optimization: track optimization state in shared vmemmap
pages
mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized
include/linux/hugetlb.h | 3 --
include/linux/page-flags.h | 6 ++++
include/linux/vmemmap-optimization.h | 12 ++++++-
mm/hugetlb.c | 15 ++++-----
mm/hugetlb_vmemmap.c | 47 ++++++----------------------
mm/memory-failure.c | 4 +--
mm/sparse-vmemmap.c | 1 +
7 files changed, 36 insertions(+), 52 deletions(-)
base-commit: 1a7610248a3802e38124ce66b07eef12277be9a0
--
2.54.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages 2026-12-04 6:50 [PATCH 0/2] mm: Track vmemmap optimization state in shared backing pages Muchun Song @ 2026-12-04 6:50 ` Muchun Song 2026-12-04 7:23 ` sashiko-bot ` (2 more replies) 2026-12-04 6:50 ` [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized Muchun Song 1 sibling, 3 replies; 9+ messages in thread From: Muchun Song @ 2026-12-04 6:50 UTC (permalink / raw) To: Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton Cc: Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm, Muchun Song Updating HPG_vmemmap_optimized in __hugetlb_vmemmap_optimize_folio() is subtle and counterintuitive. The flag cannot simply be set after optimization succeeds. When TLB flushing is deferred, accesses can continue using the old head page after remapping. The flag must therefore be set before remapping so that it is copied to the replacement head page, then cleared if optimization fails. This couples the flag update to vmemmap remapping and TLB behavior. A separate state transfer is required in gather_bootmem_prealloc_node(), which derives the optimization state from section metadata and copies it into HPG_vmemmap_optimized before the section state is cleared. This extra action is needed only to keep the two representations synchronized. Reuse PG_owner_2 in the first struct page slot of each shared backing page to record the optimization state, and provide folio_vmemmap_optimized() as the common query. This lets consumers determine the state from the folio's vmemmap instead of maintaining and transferring a separate copy. Signed-off-by: Muchun Song <songmuchun@bytedance.com> --- include/linux/page-flags.h | 6 ++++++ include/linux/vmemmap-optimization.h | 12 +++++++++++- mm/hugetlb_vmemmap.c | 4 +++- mm/sparse-vmemmap.c | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 2b8582838a4e..f284364bc845 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -147,6 +147,9 @@ enum pageflags { */ PG_mappedtodisk = PG_owner_2, + /* Set on the first struct page in a shared vmemmap backing page. */ + PG_vmemmap_optimized = PG_owner_2, + /* Two page bits are conscripted by FS-Cache to maintain local caching * state. These bits are set on pages belonging to the netfs's inodes * when those inodes are being locally cached. @@ -692,6 +695,9 @@ PAGEFLAG(VmemmapSelfHosted, vmemmap_self_hosted, PF_ANY) PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted) #endif +/* Only test this flag through folio_vmemmap_optimized(). */ +PAGEFLAG(VmemmapOptimized, vmemmap_optimized, PF_ANY) + /* * On an anonymous folio mapped into a user virtual memory area, * folio->mapping points to its anon_vma, not to a struct address_space; diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h index 0ae8a96a0874..8277edbb0315 100644 --- a/include/linux/vmemmap-optimization.h +++ b/include/linux/vmemmap-optimization.h @@ -11,8 +11,8 @@ #include <linux/align.h> #include <linux/log2.h> +#include <linux/mm.h> #include <linux/mmdebug.h> -#include <linux/mmzone.h> /* * HugeTLB Vmemmap Optimization (HVO) requires struct pages of the head page to @@ -115,4 +115,14 @@ static inline bool vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; } + +static inline bool folio_vmemmap_optimized(const struct folio *folio) +{ + const struct page *page = folio_page(folio, VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES); + + if (!vmemmap_optimizable_order(folio_order(folio))) + return false; + + return PageVmemmapOptimized(page); +} #endif /* _LINUX_VMEMMAP_OPTIMIZATION_H */ diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 336b1405cd6a..34d44ad1228a 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -216,6 +216,7 @@ static struct page *vmemmap_dup_page_from_list(const struct page *src, list_del(&dst->lru); copy_page(page_address(dst), page_address(src)); + ClearPageVmemmapOptimized(page_address(dst)); /* Ensure updates to @dst page are visible before set_pte_at(). */ smp_wmb(); @@ -331,7 +332,8 @@ static int vmemmap_pteify_folio(const struct folio *folio, unsigned long flags) * Note: The caller must hold vmemmap_remap_rwsem. If TLB flushing is deferred, * the lock must remain held until the final TLB flush. * - * Return: %0 on success, negative error code otherwise. + * Return: %0 on success, with folio_vmemmap_optimized(@folio) returning true, + * or a negative error code otherwise. */ static int vmemmap_optimize_folio(const struct folio *folio, struct list_head *vmemmap_pages, unsigned long flags) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 51fa77982ca5..d8246c6e7388 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -215,6 +215,7 @@ struct page __ref *vmemmap_shared_tail_page(unsigned int order, struct zone *zon memmap_init_page(page, zone_idx(zone), zone_to_nid(zone)); prep_compound_tail(page, NULL, order); } + SetPageVmemmapOptimized((struct page *)addr); page = virt_to_page(addr); if (cmpxchg(&pages[idx], NULL, page) != NULL) { -- 2.54.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages 2026-12-04 6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song @ 2026-12-04 7:23 ` sashiko-bot 2026-12-05 14:25 ` Muchun Song 2026-12-05 9:55 ` kernel test robot 2026-12-05 9:55 ` kernel test robot 2 siblings, 1 reply; 9+ messages in thread From: sashiko-bot @ 2026-12-04 7:23 UTC (permalink / raw) To: Muchun Song, Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton Cc: Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] mm: circular linux/mm.h include in vmemmap-optimization.h breaks LoongArch - [Medium] mm: PG_vmemmap_optimized aliases PG_owner_2 causing THP false positives - [Low] mm: vmemmap_optimize_folio() Return doc ignores VMEMMAP_DEFER_TLB_FLUSH -- commit 57d69b737693aaf19d5ab0727dc8fe02907fcd34 Author: Muchun Song <muchun.song@linux.dev> mm/vmemmap-optimization: track optimization state in shared vmemmap pages This commit records the vmemmap optimization state in PG_owner_2 on the first struct page of each shared vmemmap backing page and adds folio_vmemmap_optimized() to query it. > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index 2b8582838a4e2..f284364bc845c 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -147,6 +147,9 @@ enum pageflags { > */ > PG_mappedtodisk = PG_owner_2, > > + /* Set on the first struct page in a shared vmemmap backing page. */ > + PG_vmemmap_optimized = PG_owner_2, > + [Severity: Medium] Can aliasing PG_vmemmap_optimized to PG_owner_2 cause folio_vmemmap_optimized() to return false positives on anonymous THPs? PG_anon_exclusive also aliases PG_owner_2 and is set per tail page on PTE-mapped exclusive anonymous THPs (after __split_huge_pmd_locked() -> __folio_add_anon_rmap()). Because those folios satisfy vmemmap_optimizable_order(), folio_vmemmap_optimized() returns true. Since MAP_PRIVATE HugeTLB folios are also anonymous, picking a flag never set on tail pages beyond the first would avoid the collision. [ ... ] > diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h > index 0ae8a96a08740..8277edbb03157 100644 > --- a/include/linux/vmemmap-optimization.h > +++ b/include/linux/vmemmap-optimization.h > @@ -11,8 +11,8 @@ > > #include <linux/align.h> > #include <linux/log2.h> > +#include <linux/mm.h> > #include <linux/mmdebug.h> > -#include <linux/mmzone.h> [ ... ] > @@ -115,4 +115,14 @@ static inline bool vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order > > return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; > } > + > +static inline bool folio_vmemmap_optimized(const struct folio *folio) > +{ > + const struct page *page = folio_page(folio, VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES); > + > + if (!vmemmap_optimizable_order(folio_order(folio))) > + return false; > + > + return PageVmemmapOptimized(page); > +} > #endif /* _LINUX_VMEMMAP_OPTIMIZATION_H */ [Severity: High] Does including linux/mm.h here create a circular include that breaks LoongArch builds? On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally includes linux/vmemmap-optimization.h, creating the cycle: linux/mm.h -> linux/pgtable.h -> asm/pgtable.h -> linux/vmemmap-optimization.h -> linux/mm.h When a LoongArch C file includes linux/mm.h first, the nested include is skipped before folio_order() is defined, so folio_vmemmap_optimized() fails to compile. Including linux/pgtable.h first similarly parses linux/mm.h before the rest of pgtable.h is defined. > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c > index 336b1405cd6a3..34d44ad1228aa 100644 > --- a/mm/hugetlb_vmemmap.c > +++ b/mm/hugetlb_vmemmap.c [ ... ] > @@ -331,7 +332,8 @@ static int vmemmap_pteify_folio(const struct folio *folio, unsigned long flags) > * Note: The caller must hold vmemmap_remap_rwsem. If TLB flushing is deferred, > * the lock must remain held until the final TLB flush. > * > - * Return: %0 on success, negative error code otherwise. > + * Return: %0 on success, with folio_vmemmap_optimized(@folio) returning true, > + * or a negative error code otherwise. > */ > static int vmemmap_optimize_folio(const struct folio *folio, > struct list_head *vmemmap_pages, unsigned long flags) [Severity: Low] Is this return guarantee accurate when VMEMMAP_DEFER_TLB_FLUSH is set? vmemmap_optimize_pte() accesses the old vmemmap mapping before set_pte_at(), warming the local TLB with the unoptimized page. Since vmemmap_remap_range() skips the TLB flush under VMEMMAP_DEFER_TLB_FLUSH, folio_vmemmap_optimized() can return false until the caller flushes. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261204065009.1392156-1-songmuchun@bytedance.com?part=1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages 2026-12-04 7:23 ` sashiko-bot @ 2026-12-05 14:25 ` Muchun Song 0 siblings, 0 replies; 9+ messages in thread From: Muchun Song @ 2026-12-05 14:25 UTC (permalink / raw) To: sashiko-reviews Cc: Muchun Song, Muchun Song, Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm > On Dec 4, 2026, at 15:23, sashiko-bot@kernel.org wrote: > > Thank you for your contribution! Sashiko AI review found 3 potential > issues to consider: > - [High] mm: circular linux/mm.h include in vmemmap-optimization.h > breaks LoongArch > - [Medium] mm: PG_vmemmap_optimized aliases PG_owner_2 causing THP false > positives > - [Low] mm: vmemmap_optimize_folio() Return doc ignores > VMEMMAP_DEFER_TLB_FLUSH > -- > > commit 57d69b737693aaf19d5ab0727dc8fe02907fcd34 > Author: Muchun Song <muchun.song@linux.dev> > > mm/vmemmap-optimization: track optimization state in shared vmemmap pages > > This commit records the vmemmap optimization state in PG_owner_2 on the > first struct page of each shared vmemmap backing page and adds > folio_vmemmap_optimized() to query it. > >> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h >> index 2b8582838a4e2..f284364bc845c 100644 >> --- a/include/linux/page-flags.h >> +++ b/include/linux/page-flags.h >> @@ -147,6 +147,9 @@ enum pageflags { >> */ >> PG_mappedtodisk = PG_owner_2, >> >> + /* Set on the first struct page in a shared vmemmap backing page. */ >> + PG_vmemmap_optimized = PG_owner_2, >> + > > [Severity: Medium] > Can aliasing PG_vmemmap_optimized to PG_owner_2 cause > folio_vmemmap_optimized() to return false positives on anonymous THPs? > > PG_anon_exclusive also aliases PG_owner_2 and is set per tail page on > PTE-mapped exclusive anonymous THPs (after __split_huge_pmd_locked() -> > __folio_add_anon_rmap()). Because those folios satisfy > vmemmap_optimizable_order(), folio_vmemmap_optimized() returns true. It is not reachable today: every caller passes a hugetlb folio (mm/hugetlb.c, mm/hugetlb_vmemmap.c and the hugetlb hwpoison helpers in mm/memory-failure.c), and on hugetlb SetPageAnonExclusive() rejects tail pages while PageAnonExclusive() redirects to the head. But the helper is a generic inline gated only by order, so relying on its callers is fragile. I'll move PG_vmemmap_optimized to PG_owner_priv_1. Every alias there is either PF_NO_COMPOUND (PG_checked and the Xen bits) or head-only (PG_swapcache), and PG_vmemmap_self_hosted is only set on memmap_on_memory vmemmap pages, so no compound tail page can carry it. > > Since MAP_PRIVATE HugeTLB folios are also anonymous, picking a flag never > set on tail pages beyond the first would avoid the collision. > > [ ... ] > >> diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h >> index 0ae8a96a08740..8277edbb03157 100644 >> --- a/include/linux/vmemmap-optimization.h >> +++ b/include/linux/vmemmap-optimization.h >> @@ -11,8 +11,8 @@ >> >> #include <linux/align.h> >> #include <linux/log2.h> >> +#include <linux/mm.h> >> #include <linux/mmdebug.h> >> -#include <linux/mmzone.h> > > [ ... ] > >> @@ -115,4 +115,14 @@ static inline bool vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order >> >> return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; >> } >> + >> +static inline bool folio_vmemmap_optimized(const struct folio *folio) >> +{ >> + const struct page *page = folio_page(folio, VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES); >> + >> + if (!vmemmap_optimizable_order(folio_order(folio))) >> + return false; >> + >> + return PageVmemmapOptimized(page); >> +} >> #endif /* _LINUX_VMEMMAP_OPTIMIZATION_H */ > > [Severity: High] > Does including linux/mm.h here create a circular include that breaks > LoongArch builds? Yeah. I will move MAX_FOLIO_VMEMMAP_ALIGN to the location where MAX_FOLIO_NR_PAGES is defined to fix this issue (Maybe a separate prerequisite patch?). > > On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally > includes linux/vmemmap-optimization.h, creating the cycle: > > linux/mm.h -> linux/pgtable.h -> asm/pgtable.h > -> linux/vmemmap-optimization.h -> linux/mm.h > > When a LoongArch C file includes linux/mm.h first, the nested include is > skipped before folio_order() is defined, so folio_vmemmap_optimized() > fails to compile. Including linux/pgtable.h first similarly parses > linux/mm.h before the rest of pgtable.h is defined. > >> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c >> index 336b1405cd6a3..34d44ad1228aa 100644 >> --- a/mm/hugetlb_vmemmap.c >> +++ b/mm/hugetlb_vmemmap.c > > [ ... ] > >> @@ -331,7 +332,8 @@ static int vmemmap_pteify_folio(const struct folio *folio, unsigned long flags) >> * Note: The caller must hold vmemmap_remap_rwsem. If TLB flushing is deferred, >> * the lock must remain held until the final TLB flush. >> * >> - * Return: %0 on success, negative error code otherwise. >> + * Return: %0 on success, with folio_vmemmap_optimized(@folio) returning true, >> + * or a negative error code otherwise. >> */ >> static int vmemmap_optimize_folio(const struct folio *folio, >> struct list_head *vmemmap_pages, unsigned long flags) > > [Severity: Low] > Is this return guarantee accurate when VMEMMAP_DEFER_TLB_FLUSH is set? I'll use the following wording. * Return: %0 on success, with folio_vmemmap_optimized(@folio) returning true * once any deferred TLB flush has completed, or a negative error code otherwise. Thanks. > > vmemmap_optimize_pte() accesses the old vmemmap mapping before > set_pte_at(), warming the local TLB with the unoptimized page. Since > vmemmap_remap_range() skips the TLB flush under VMEMMAP_DEFER_TLB_FLUSH, > folio_vmemmap_optimized() can return false until the caller flushes. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261204065009.1392156-1-songmuchun@bytedance.com?part=1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages 2026-12-04 6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song 2026-12-04 7:23 ` sashiko-bot @ 2026-12-05 9:55 ` kernel test robot 2026-12-05 9:55 ` kernel test robot 2 siblings, 0 replies; 9+ messages in thread From: kernel test robot @ 2026-12-05 9:55 UTC (permalink / raw) To: Muchun Song, Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton Cc: llvm, oe-kbuild-all, Linux Memory Management List, Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng Hi Muchun, kernel test robot noticed the following build errors: [auto build test ERROR on 1a7610248a3802e38124ce66b07eef12277be9a0] url: https://github.com/intel-lab-lkp/linux/commits/Muchun-Song/mm-vmemmap-optimization-track-optimization-state-in-shared-vmemmap-pages/20261204-145008 base: 1a7610248a3802e38124ce66b07eef12277be9a0 patch link: https://lore.kernel.org/r/20261204065009.1392156-2-songmuchun%40bytedance.com patch subject: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20261204/20261204215615.prolt4W2-lkp@intel.com/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261204/20261204215615.prolt4W2-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/20261204215615.prolt4W2-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:31: In file included from include/linux/pgtable.h:6: In file included from arch/loongarch/include/asm/pgtable.h:75: >> include/linux/vmemmap-optimization.h:123:33: error: call to undeclared function 'folio_order'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 123 | if (!vmemmap_optimizable_order(folio_order(folio))) | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:98:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 98 | return (set->sig[3] | set->sig[2] | | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:98:25: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 98 | return (set->sig[3] | set->sig[2] | | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:99:4: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 99 | set->sig[1] | set->sig[0]) == 0; | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:101:11: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 101 | return (set->sig[1] | set->sig[0]) == 0; | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:114:11: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 114 | return (set1->sig[3] == set2->sig[3]) && | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:114:27: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 114 | return (set1->sig[3] == set2->sig[3]) && | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:115:5: warning: array index 2 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 115 | (set1->sig[2] == set2->sig[2]) && | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:115:21: warning: array index 2 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 115 | (set1->sig[2] == set2->sig[2]) && | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:116:5: warning: array index 1 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 116 | (set1->sig[1] == set2->sig[1]) && | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:116:21: warning: array index 1 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 116 | (set1->sig[1] == set2->sig[1]) && | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here -- | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:187:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:175:20: note: expanded from macro '_SIG_SET_OP' 175 | set->sig[2] = op(set->sig[2]); \ | ^ ~ include/linux/signal.h:186:24: note: expanded from macro '_sig_not' 186 | #define _sig_not(x) (~(x)) | ^ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:187:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:175:3: note: expanded from macro '_SIG_SET_OP' 175 | set->sig[2] = op(set->sig[2]); \ | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:187:1: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:177:27: note: expanded from macro '_SIG_SET_OP' 177 | case 2: set->sig[1] = op(set->sig[1]); \ | ^ ~ include/linux/signal.h:186:24: note: expanded from macro '_sig_not' 186 | #define _sig_not(x) (~(x)) | ^ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:187:1: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:177:10: note: expanded from macro '_SIG_SET_OP' 177 | case 2: set->sig[1] = op(set->sig[1]); \ | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:198:10: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 198 | case 2: set->sig[1] = 0; | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:211:10: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 211 | case 2: set->sig[1] = -1; | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:242:10: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 242 | case 2: set->sig[1] = 0; | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:7: include/linux/signal.h:255:10: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 255 | case 2: set->sig[1] = -1; | ^ ~ include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here 62 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/loongarch/kernel/asm-offsets.c:11: >> include/linux/mm.h:1950:28: error: conflicting types for 'folio_order' 1950 | static inline unsigned int folio_order(const struct folio *folio) | ^ include/linux/vmemmap-optimization.h:123:33: note: previous implicit declaration is here 123 | if (!vmemmap_optimizable_order(folio_order(folio))) | ^ 49 warnings and 2 errors generated. make[3]: *** [scripts/Makefile.build:185: arch/loongarch/kernel/asm-offsets.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1417: prepare0] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. vim +/folio_order +123 include/linux/vmemmap-optimization.h 118 119 static inline bool folio_vmemmap_optimized(const struct folio *folio) 120 { 121 const struct page *page = folio_page(folio, VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES); 122 > 123 if (!vmemmap_optimizable_order(folio_order(folio))) -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages 2026-12-04 6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song 2026-12-04 7:23 ` sashiko-bot 2026-12-05 9:55 ` kernel test robot @ 2026-12-05 9:55 ` kernel test robot 2 siblings, 0 replies; 9+ messages in thread From: kernel test robot @ 2026-12-05 9:55 UTC (permalink / raw) To: Muchun Song, Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton Cc: oe-kbuild-all, Linux Memory Management List, Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng Hi Muchun, kernel test robot noticed the following build errors: [auto build test ERROR on 1a7610248a3802e38124ce66b07eef12277be9a0] url: https://github.com/intel-lab-lkp/linux/commits/Muchun-Song/mm-vmemmap-optimization-track-optimization-state-in-shared-vmemmap-pages/20261204-145008 base: 1a7610248a3802e38124ce66b07eef12277be9a0 patch link: https://lore.kernel.org/r/20261204065009.1392156-2-songmuchun%40bytedance.com patch subject: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages config: loongarch-randconfig-1001-20261204 (https://download.01.org/0day-ci/archive/20261204/20261204225656.P5q9BSDl-lkp@intel.com/config) compiler: loongarch64-linux-gcc (GCC) 13.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261204/20261204225656.P5q9BSDl-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/20261204225656.P5q9BSDl-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from arch/loongarch/include/asm/pgtable.h:75, from include/linux/pgtable.h:6, from include/linux/mm.h:31, from arch/loongarch/kernel/asm-offsets.c:11: include/linux/vmemmap-optimization.h: In function 'folio_vmemmap_optimized': >> include/linux/vmemmap-optimization.h:123:40: error: implicit declaration of function 'folio_order'; did you mean 'folio_try_get'? [-Werror=implicit-function-declaration] 123 | if (!vmemmap_optimizable_order(folio_order(folio))) | ^~~~~~~~~~~ | folio_try_get include/linux/mm.h: At top level: >> include/linux/mm.h:1950:28: error: conflicting types for 'folio_order'; have 'unsigned int(const struct folio *)' 1950 | static inline unsigned int folio_order(const struct folio *folio) | ^~~~~~~~~~~ include/linux/vmemmap-optimization.h:123:40: note: previous implicit declaration of 'folio_order' with type 'int()' 123 | if (!vmemmap_optimizable_order(folio_order(folio))) | ^~~~~~~~~~~ cc1: some warnings being treated as errors make[3]: *** [scripts/Makefile.build:185: arch/loongarch/kernel/asm-offsets.s] Error 1 shuffle=15396140 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1417: prepare0] Error 2 shuffle=15396140 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=15396140 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 shuffle=15396140 make: Target 'prepare' not remade because of errors. vim +123 include/linux/vmemmap-optimization.h 118 119 static inline bool folio_vmemmap_optimized(const struct folio *folio) 120 { 121 const struct page *page = folio_page(folio, VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES); 122 > 123 if (!vmemmap_optimizable_order(folio_order(folio))) -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized 2026-12-04 6:50 [PATCH 0/2] mm: Track vmemmap optimization state in shared backing pages Muchun Song 2026-12-04 6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song @ 2026-12-04 6:50 ` Muchun Song 2026-12-04 7:23 ` sashiko-bot 1 sibling, 1 reply; 9+ messages in thread From: Muchun Song @ 2026-12-04 6:50 UTC (permalink / raw) To: Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton Cc: Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm, Muchun Song HPG_vmemmap_optimized duplicates the state recorded in the shared vmemmap backing page and must be updated on every mapping transition. Derive the state with folio_vmemmap_optimized() instead and remove the flag and its explicit updates to simplify the code. Signed-off-by: Muchun Song <songmuchun@bytedance.com> --- include/linux/hugetlb.h | 3 --- mm/hugetlb.c | 15 ++++++-------- mm/hugetlb_vmemmap.c | 43 +++++++---------------------------------- mm/memory-failure.c | 4 ++-- 4 files changed, 15 insertions(+), 50 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 14af4396de7e..98338392789f 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -612,7 +612,6 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr, * modifications require hugetlb_lock. * HPG_freed - Set when page is on the free lists. * Synchronization: hugetlb_lock held for examination and modification. - * HPG_vmemmap_optimized - Set when the vmemmap pages of the page are freed. * HPG_raw_hwp_unreliable - Set when the hugetlb page has a hwpoison sub-page * that is not tracked by raw_hwp_page list. */ @@ -621,7 +620,6 @@ enum hugetlb_page_flags { HPG_migratable, HPG_temporary, HPG_freed, - HPG_vmemmap_optimized, HPG_raw_hwp_unreliable, HPG_cma, __NR_HPAGEFLAGS, @@ -681,7 +679,6 @@ HPAGEFLAG(RestoreReserve, restore_reserve) HPAGEFLAG(Migratable, migratable) HPAGEFLAG(Temporary, temporary) HPAGEFLAG(Freed, freed) -HPAGEFLAG(VmemmapOptimized, vmemmap_optimized) HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) HPAGEFLAG(Cma, cma) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 11ab74970738..781e5a8a99d0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1503,7 +1503,7 @@ void remove_hugetlb_folio(struct hstate *h, struct folio *folio, * pages. Otherwise, someone (memory error handling) may try to write * to tail struct pages. */ - if (!folio_test_hugetlb_vmemmap_optimized(folio)) + if (!folio_vmemmap_optimized(folio)) __folio_clear_hugetlb(folio); h->nr_huge_pages--; @@ -1515,14 +1515,13 @@ void add_hugetlb_folio(struct hstate *h, struct folio *folio, { int nid = folio_nid(folio); - VM_BUG_ON_FOLIO(!folio_test_hugetlb_vmemmap_optimized(folio), folio); + VM_BUG_ON_FOLIO(!folio_vmemmap_optimized(folio), folio); lockdep_assert_held(&hugetlb_lock); /* Callers must clear transient flags before returning to the pool. */ VM_WARN_ON_ONCE_FOLIO((unsigned long)folio->private & - ~(BIT(HPG_vmemmap_optimized) | - BIT(HPG_raw_hwp_unreliable) | + ~(BIT(HPG_raw_hwp_unreliable) | BIT(HPG_cma)), folio); INIT_LIST_HEAD(&folio->lru); @@ -1543,7 +1542,7 @@ void add_hugetlb_folio(struct hstate *h, struct folio *folio, static void __update_and_free_hugetlb_folio(struct hstate *h, struct folio *folio) { - bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio); + bool clear_flag = folio_vmemmap_optimized(folio); if (hstate_is_gigantic_no_runtime(h)) { /* Callers must filter gigantic_no_runtime upstream. */ @@ -1651,7 +1650,7 @@ static inline void flush_free_hpage_work(struct hstate *h) static void update_and_free_hugetlb_folio(struct hstate *h, struct folio *folio, bool atomic) { - if (!folio_test_hugetlb_vmemmap_optimized(folio) || !atomic) { + if (!folio_vmemmap_optimized(folio) || !atomic) { __update_and_free_hugetlb_folio(h, folio); return; } @@ -3459,8 +3458,6 @@ static void __init gather_bootmem_prealloc_node(unsigned long nid) memmap_init_compound_page(page, pfn, zone, huge_page_order(h)); init_new_hugetlb_folio(folio); - if (vmemmap_optimizable_order(pfn_to_section_compound_order(pfn))) - folio_set_hugetlb_vmemmap_optimized(folio); section_set_compound_order_range(pfn, nr_pages, 0); list_add(&folio->lru, &folio_list); @@ -4093,7 +4090,7 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst, int i; bool cma; - if (folio_test_hugetlb_vmemmap_optimized(folio)) + if (folio_vmemmap_optimized(folio)) continue; cma = folio_test_hugetlb_cma(folio); diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 34d44ad1228a..bba1c0adb622 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -393,6 +393,9 @@ static int vmemmap_restore_folio(const struct folio *folio, unsigned long flags) int ret, nid = folio_nid(folio); LIST_HEAD(vmemmap_pages); + if (!folio_vmemmap_optimized(folio)) + return 0; + start += VMEMMAP_OPTIMIZATION_SIZE; ret = alloc_vmemmap_page_list(&vmemmap_pages, (end - start) / PAGE_SIZE, nid, GFP_KERNEL); @@ -412,18 +415,8 @@ early_param("hugetlb_free_vmemmap", hugetlb_vmemmap_optimize_param); static int __hugetlb_vmemmap_restore_folio(struct folio *folio, unsigned long flags) { - int ret; - VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio), folio); - - if (!folio_test_hugetlb_vmemmap_optimized(folio)) - return 0; - - ret = vmemmap_restore_folio(folio, flags); - if (!ret) - folio_clear_hugetlb_vmemmap_optimized(folio); - - return ret; + return vmemmap_restore_folio(folio, flags); } /** @@ -461,7 +454,7 @@ long hugetlb_vmemmap_restore_folios(struct list_head *folio_list, unsigned long flags = VMEMMAP_DEFER_TLB_FLUSH; list_for_each_entry_safe(folio, t_folio, folio_list, lru) { - if (folio_test_hugetlb_vmemmap_optimized(folio)) { + if (folio_vmemmap_optimized(folio)) { ret = __hugetlb_vmemmap_restore_folio(folio, flags); if (ret) break; @@ -483,37 +476,15 @@ static int __hugetlb_vmemmap_optimize_folio(struct folio *folio, struct list_head *vmemmap_pages, unsigned long flags) { - int ret; - VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio), folio); - - /* - * Very Subtle - * If VMEMMAP_DEFER_TLB_FLUSH is set, TLB flushing is not performed - * immediately after remapping. As a result, subsequent accesses - * and modifications to struct pages associated with the hugetlb - * page could be to the OLD struct pages. Set the vmemmap optimized - * flag here so that it is copied to the new head page. This keeps - * the old and new struct pages in sync. - * If there is an error during optimization, we will immediately FLUSH - * the TLB and clear the flag below. - */ - folio_set_hugetlb_vmemmap_optimized(folio); - ret = vmemmap_optimize_folio(folio, vmemmap_pages, flags); - if (ret) - folio_clear_hugetlb_vmemmap_optimized(folio); - - return ret; + return vmemmap_optimize_folio(folio, vmemmap_pages, flags); } /** * hugetlb_vmemmap_optimize_folio - optimize @folio's vmemmap pages. * @folio: the folio whose vmemmap pages will be optimized. * - * This function only tries to optimize @folio's vmemmap pages and does not - * guarantee that the optimization will succeed after it returns. The caller - * can use folio_test_hugetlb_vmemmap_optimized(@folio) to detect if @folio's - * vmemmap pages have been optimized. + * On success, folio_vmemmap_optimized(@folio) returns true. */ void hugetlb_vmemmap_optimize_folio(struct folio *folio) { diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 227148d116dd..2e39a6d453e4 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2008,7 +2008,7 @@ static unsigned long folio_free_raw_hwp(struct folio *folio, bool move_flag) * hugetlb_vmemmap_optimized hugepages can't be freed because struct * pages for tail pages are required but they don't exist. */ - if (move_flag && folio_test_hugetlb_vmemmap_optimized(folio)) + if (move_flag && folio_vmemmap_optimized(folio)) return 0; /* @@ -2025,7 +2025,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio) { if (folio_test_hugetlb_raw_hwp_unreliable(folio)) return; - if (folio_test_hugetlb_vmemmap_optimized(folio)) + if (folio_vmemmap_optimized(folio)) return; folio_clear_hwpoison(folio); folio_free_raw_hwp(folio, true); -- 2.54.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized 2026-12-04 6:50 ` [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized Muchun Song @ 2026-12-04 7:23 ` sashiko-bot 2026-12-05 14:00 ` Muchun Song 0 siblings, 1 reply; 9+ messages in thread From: sashiko-bot @ 2026-12-04 7:23 UTC (permalink / raw) To: Muchun Song, Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton Cc: Muchun Song, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] mm: circular header include breaks LoongArch build in vmemmap-optimization.h - [Medium] mm: folio_vmemmap_optimized() flips too early during vmemmap_restore_folio() -- commit 46c817b207bb4d732145a6484d9eb4524b9922cf Author: Muchun Song <muchun.song@linux.dev> mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized This commit replaces folio_test_hugetlb_vmemmap_optimized() with folio_vmemmap_optimized() across hugetlb and memory-failure paths and removes the HPG_vmemmap_optimized flag and its explicit updates. > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 11ab74970738f..781e5a8a99d00 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1503,7 +1503,7 @@ void remove_hugetlb_folio(struct hstate *h, struct folio *folio, > * pages. Otherwise, someone (memory error handling) may try to write > * to tail struct pages. > */ > - if (!folio_test_hugetlb_vmemmap_optimized(folio)) > + if (!folio_vmemmap_optimized(folio)) > __folio_clear_hugetlb(folio); [Severity: High] Does folio_vmemmap_optimized() break the LoongArch build via a circular header include? In commit "mm/vmemmap-optimization: track optimization state in shared vmemmap pages", include/linux/vmemmap-optimization.h switched to including linux/mm.h and added the inline helper folio_vmemmap_optimized(), which calls folio_order(). On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally includes linux/vmemmap-optimization.h. When a translation unit includes linux/mm.h first, linux/mm.h -> linux/pgtable.h -> asm/pgtable.h -> linux/vmemmap-optimization.h skips the nested linux/mm.h include because _LINUX_MM_H is already defined, so folio_order() is undeclared when folio_vmemmap_optimized() is parsed. Conversely, including linux/pgtable.h or asm/pgtable.h before linux/mm.h pulls in linux/mm.h while both pgtable headers are still incomplete. [ ... ] > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 227148d116dd9..2e39a6d453e4b 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c [ ... ] > @@ -2025,7 +2025,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio) > { > if (folio_test_hugetlb_raw_hwp_unreliable(folio)) > return; > - if (folio_test_hugetlb_vmemmap_optimized(folio)) > + if (folio_vmemmap_optimized(folio)) > return; > folio_clear_hwpoison(folio); > folio_free_raw_hwp(folio, true); [Severity: Medium] Can folio_vmemmap_optimized() return false before vmemmap_restore_folio() finishes restoring all tail PTEs, causing SetPageHWPoison() to write to the shared tail page? folio_vmemmap_optimized() checks PageVmemmapOptimized() on the first tail struct page at start + VMEMMAP_OPTIMIZATION_SIZE. vmemmap_restore_folio() walks tail PTEs in ascending order and overwrites that first PTE while the remaining tail PTEs still map the shared tail page and before the TLB is flushed. Previously, __hugetlb_vmemmap_restore_folio() cleared HPG_vmemmap_optimized only after vmemmap_restore_folio() returned. With the flag removed, a racing hwpoison_filter() rejection on a free HVO folio can observe folio_vmemmap_optimized() == false mid-restore: CPU0 CPU1 try_memory_failure_hugetlb() get_huge_page_for_hwpoison() /* free HVO folio, no ref; drops hugetlb_lock and vmemmap_remap_rwsem */ dissolve_free_hugetlb_folio() remove_hugetlb_folio() hugetlb_vmemmap_restore_folio() vmemmap_restore_range() /* overwrites first tail PTE; remaining tail PTEs still map shared tail page */ if (hwpoison_filter(p)) folio_clear_hugetlb_hwpoison() folio_vmemmap_optimized() /* returns false */ folio_free_raw_hwp(..., true) SetPageHWPoison(p->page) <-- writes to shared tail page For bootmem-preallocated HVO gigantic folios whose shared tail PTEs are mapped read-only, this write causes a kernel page fault. For runtime HVO folios with writable shared tail PTEs, it sets PG_hwpoison on the global shared tail page, corrupting struct page state across all HVO folios in that zone and order. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261204065009.1392156-1-songmuchun@bytedance.com?part=2 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized 2026-12-04 7:23 ` sashiko-bot @ 2026-12-05 14:00 ` Muchun Song 0 siblings, 0 replies; 9+ messages in thread From: Muchun Song @ 2026-12-05 14:00 UTC (permalink / raw) To: sashiko-reviews Cc: Muchun Song, Muchun Song, Oscar Salvador, David Hildenbrand, Mike Rapoport, Andrew Morton, Liam R . Howlett, Vlastimil Babka, Michal Hocko, Miaohe Lin, Naoya Horiguchi, Lance Yang, Qi Zheng, linux-mm > On Dec 4, 2026, at 15:23, sashiko-bot@kernel.org wrote: > > Thank you for your contribution! Sashiko AI review found 2 potential > issues to consider: > - [High] mm: circular header include breaks LoongArch build in > vmemmap-optimization.h > - [Medium] mm: folio_vmemmap_optimized() flips too early during > vmemmap_restore_folio() > -- > > commit 46c817b207bb4d732145a6484d9eb4524b9922cf > Author: Muchun Song <muchun.song@linux.dev> > > mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized > > This commit replaces folio_test_hugetlb_vmemmap_optimized() with > folio_vmemmap_optimized() across hugetlb and memory-failure paths and > removes the HPG_vmemmap_optimized flag and its explicit updates. > >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index 11ab74970738f..781e5a8a99d00 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -1503,7 +1503,7 @@ void remove_hugetlb_folio(struct hstate *h, struct folio *folio, >> * pages. Otherwise, someone (memory error handling) may try to write >> * to tail struct pages. >> */ >> - if (!folio_test_hugetlb_vmemmap_optimized(folio)) >> + if (!folio_vmemmap_optimized(folio)) >> __folio_clear_hugetlb(folio); > > [Severity: High] > Does folio_vmemmap_optimized() break the LoongArch build via a circular > header include? Right. > > In commit "mm/vmemmap-optimization: track optimization state in shared > vmemmap pages", include/linux/vmemmap-optimization.h switched to including > linux/mm.h and added the inline helper folio_vmemmap_optimized(), which > calls folio_order(). > > On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally includes > linux/vmemmap-optimization.h. When a translation unit includes linux/mm.h > first, linux/mm.h -> linux/pgtable.h -> asm/pgtable.h -> > linux/vmemmap-optimization.h skips the nested linux/mm.h include because > _LINUX_MM_H is already defined, so folio_order() is undeclared when > folio_vmemmap_optimized() is parsed. > > Conversely, including linux/pgtable.h or asm/pgtable.h before linux/mm.h > pulls in linux/mm.h while both pgtable headers are still incomplete. > > [ ... ] > >> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >> index 227148d116dd9..2e39a6d453e4b 100644 >> --- a/mm/memory-failure.c >> +++ b/mm/memory-failure.c > > [ ... ] > >> @@ -2025,7 +2025,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio) >> { >> if (folio_test_hugetlb_raw_hwp_unreliable(folio)) >> return; >> - if (folio_test_hugetlb_vmemmap_optimized(folio)) >> + if (folio_vmemmap_optimized(folio)) >> return; >> folio_clear_hwpoison(folio); >> folio_free_raw_hwp(folio, true); > > [Severity: Medium] > Can folio_vmemmap_optimized() return false before vmemmap_restore_folio() > finishes restoring all tail PTEs, causing SetPageHWPoison() to write to the > shared tail page? Right. However, the actual race is much worse than what is shown here. The lower half of try_memory_failure_hugetlb() does not hold any refcount to a HugeTLB folio, so the folio can be freed at any time, and there are many more other pre-existing issues here. I've fixed it in a separate patch here [1]. After this fix, the race mentioned here will no longer exist. [1] https://lore.kernel.org/all/20261205121205.83068-1-songmuchun@bytedance.com/ > > folio_vmemmap_optimized() checks PageVmemmapOptimized() on the first tail > struct page at start + VMEMMAP_OPTIMIZATION_SIZE. vmemmap_restore_folio() > walks tail PTEs in ascending order and overwrites that first PTE while the > remaining tail PTEs still map the shared tail page and before the TLB is > flushed. > > Previously, __hugetlb_vmemmap_restore_folio() cleared HPG_vmemmap_optimized > only after vmemmap_restore_folio() returned. With the flag removed, a > racing hwpoison_filter() rejection on a free HVO folio can observe > folio_vmemmap_optimized() == false mid-restore: > > CPU0 CPU1 > try_memory_failure_hugetlb() > get_huge_page_for_hwpoison() > /* free HVO folio, no ref; > drops hugetlb_lock and > vmemmap_remap_rwsem */ > dissolve_free_hugetlb_folio() > remove_hugetlb_folio() > hugetlb_vmemmap_restore_folio() > vmemmap_restore_range() > /* overwrites first tail PTE; > remaining tail PTEs still > map shared tail page */ > if (hwpoison_filter(p)) > folio_clear_hugetlb_hwpoison() > folio_vmemmap_optimized() > /* returns false */ > folio_free_raw_hwp(..., true) > SetPageHWPoison(p->page) <-- writes to shared tail page > > For bootmem-preallocated HVO gigantic folios whose shared tail PTEs are > mapped read-only, this write causes a kernel page fault. For runtime HVO > folios with writable shared tail PTEs, it sets PG_hwpoison on the global > shared tail page, corrupting struct page state across all HVO folios in > that zone and order. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261204065009.1392156-1-songmuchun@bytedance.com?part=2 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-05 14:26 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-04 6:50 [PATCH 0/2] mm: Track vmemmap optimization state in shared backing pages Muchun Song 2026-12-04 6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song 2026-12-04 7:23 ` sashiko-bot 2026-12-05 14:25 ` Muchun Song 2026-12-05 9:55 ` kernel test robot 2026-12-05 9:55 ` kernel test robot 2026-12-04 6:50 ` [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized Muchun Song 2026-12-04 7:23 ` sashiko-bot 2026-12-05 14:00 ` Muchun Song
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.