All of lore.kernel.org
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: Muchun Song <muchun.song@linux.dev>,
	Muchun Song <songmuchun@bytedance.com>,
	Oscar Salvador <osalvador@suse.de>,
	David Hildenbrand <david@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Michal Hocko <mhocko@suse.com>, Miaohe Lin <linmiaohe@huawei.com>,
	Naoya Horiguchi <nao.horiguchi@gmail.com>,
	Lance Yang <lance.yang@linux.dev>, Qi Zheng <qi.zheng@linux.dev>,
	linux-mm@kvack.org
Subject: Re: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages
Date: Sat, 5 Dec 2026 22:25:39 +0800	[thread overview]
Message-ID: <C6D65AF9-9054-4C5D-B75C-B6EE9EB9471D@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-249307@kernel.org>



> 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



  reply	other threads:[~2026-12-05 14:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=C6D65AF9-9054-4C5D-B75C-B6EE9EB9471D@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@suse.de \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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.