Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "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>
Cc: "Muchun Song" <muchun.song@linux.dev>,
	"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: Fri, 04 Dec 2026 07:23:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-249307@kernel.org> (raw)
In-Reply-To: <20261204065009.1392156-2-songmuchun@bytedance.com>

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


  reply	other threads:[~2026-12-04  7:23 UTC|newest]

Thread overview: 5+ 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 [this message]
2026-12-04  6:50 ` [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized Muchun Song
2026-12-04  7:23   ` sashiko-bot

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=sashiko-outbox-249307@kernel.org \
    --to=sashiko-bot@kernel.org \
    --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=muchun.song@linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox