Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796480760; b=x3N1L3lqFxtfp6/QzatGT6MGYnBPUx/RsjdldI6JcLmAXRecUBDG8iGyRi2fKOyYXj+C xXtkbNNPEIdRZIeiv6I5baAnbxZhBeRzSPky/HMuYwY1uDUBBLcQD9WXOW57Gi4NViSa0 LfUDoZaneO1upQoNMbnKxODuAfyVI6aD/JU1Bag49kms/oLgUZJhkZwlwuwdZT4IDcdMw xAQEB6Wy/0tc8rA3t6uI8z6OSqoO3tljOkotLvNOFAWjEevBKr6hS+Is+J4YxpyGP1wyX +P1SsOmLgexjRKEPqdXGmUu+4Qs3kBqKDobaIbNJL5Bc3rdL6cJIwRlEip81oO91sBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796480760; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=CJVdst3xTAv0l6Conj6qgO7P4I3dSuGVTnuLeaV/ejE=; b=DHZC8I5mhQkbrBmfNGkrl2IhOFe6X4drkOoXCZkUIIz/hE8c3J6BmPLFny5h3dY8R989 wbIB7Su5O3h/JGXdUp/jt13k9j485O4OL3rUcuh4shEdvE6AFGP5W5IoSDQho5R9RJbpO UtlsdKaUs10IepkYzIzdiDtqsJg55eJHQJrY+kTKzgQtlaSQkJJz1s9ooZad9irDrcf6F 4PTCGckg/kVkZIygjTGLA4geDD39HlS8oQwTC4PokyoTeD/tsjvgoFRJQMVl/6Hd9Xtzs ErQtQvoUphxnI9b4BS/2/Ogo8ThOReD6z8xeoKnzvaGc6MKyFi84ieUCIMUxgS+n1ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=BFApQ6ON; arc=none smtp.remote-ip=91.218.175.20 Received: from mta0.migadu.com (out-20.mta0.migadu.com [91.218.175.20]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97647606A32F for ; Sat, 5 Dec 2026 14:25:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 97647606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=BFApQ6ON X-Envelope-To: sashiko-reviews@lists.linux.dev DKIM-Signature: a=rsa-sha256; bh=EMVE+1Vad0CfLHM/T7xxRInbsWjO3DWIFnzUUUJMkv4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796480757; v=1; x=1797085557; b=BFApQ6ONiqrnnbR048+WHQsqm7UFSJx3HYfj00lMUl1QkFqaq7IleY2d8tiT+6FpIC5UPgt3 7sskj+u+zm5EkeW+yfSGqKjRS/md2ixC5zL8XuDVOQVVB39a2+5giqh/VcroMtPbsUq5NDG80UA dGOnZEMdKzJnBzpLFVVm5tAA= X-Envelope-To: sashiko-reviews@lists.linux.dev Received: by smtp.migadu.com with ESMTPS id 87fb5146045bd8d1; Sat, 05 Dec 2026 14:25:57 +0000 X-Mizu-Trace-ID: 87fb5146045bd8d1 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=utf-8 X-Mailing-List: sashiko-reviews@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages From: Muchun Song In-Reply-To: Date: Sat, 5 Dec 2026 22:25:39 +0800 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@kvack.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20261204065009.1392156-1-songmuchun@bytedance.com> <20261204065009.1392156-2-songmuchun@bytedance.com> To: sashiko-reviews@lists.linux.dev X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Dec 4, 2026, at 15:23, sashiko-bot@kernel.org wrote: >=20 > 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 > -- >=20 > commit 57d69b737693aaf19d5ab0727dc8fe02907fcd34 > Author: Muchun Song >=20 > mm/vmemmap-optimization: track optimization state in shared vmemmap = pages >=20 > 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. >=20 >> 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 =3D PG_owner_2, >>=20 >> + /* Set on the first struct page in a shared vmemmap backing = page. */ >> + PG_vmemmap_optimized =3D PG_owner_2, >> + >=20 > [Severity: Medium] > Can aliasing PG_vmemmap_optimized to PG_owner_2 cause > folio_vmemmap_optimized() to return false positives on anonymous THPs? >=20 > 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. >=20 > Since MAP_PRIVATE HugeTLB folios are also anonymous, picking a flag = never > set on tail pages beyond the first would avoid the collision. >=20 > [ ... ] >=20 >> 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 @@ >>=20 >> #include >> #include >> +#include >> #include >> -#include >=20 > [ ... ] >=20 >> @@ -115,4 +115,14 @@ static inline bool = vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order >>=20 >> return (pfn & (nr_pages - 1)) >=3D = VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; >> } >> + >> +static inline bool folio_vmemmap_optimized(const struct folio = *folio) >> +{ >> + const struct page *page =3D 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 */ >=20 > [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?). >=20 > On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally > includes linux/vmemmap-optimization.h, creating the cycle: >=20 > linux/mm.h -> linux/pgtable.h -> asm/pgtable.h > -> linux/vmemmap-optimization.h -> linux/mm.h >=20 > 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. >=20 >> 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 >=20 > [ ... ] >=20 >> @@ -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) >=20 > [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. >=20 > 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. >=20 > --=20 > Sashiko AI review =C2=B7 = https://sashiko.dev/#/patchset/20261204065009.1392156-1-songmuchun@bytedan= ce.com?part=3D1