From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87DC5606A32F for ; Sat, 5 Dec 2026 14:26:03 +0000 (UTC) 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=YUdSSmrq Received: by kanga.kvack.org (Postfix) id 962A96B05B2; Sat, 5 Dec 2026 09:26:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 913186B05B3; Sat, 5 Dec 2026 09:26:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 801916B05B4; Sat, 5 Dec 2026 09:26:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 572AD6B05B2 for ; Sat, 5 Dec 2026 09:26:02 -0500 (EST) Received: from smtpin28.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E42F81A064B for ; Sat, 5 Dec 2026 14:26:01 +0000 (UTC) X-FDA: 85510153722.28.9B7017C Received: from mta1.migadu.com (out-47.mta1.migadu.com [95.215.58.47]) by imf17.hostedemail.com (Postfix) with ESMTP id A6BD040007 for ; Sat, 5 Dec 2026 14:25:59 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=YUdSSmrq; spf=pass (imf17.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.47 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796480760; b=VKXnfcFLlytEpObLCmFO3+A2K0cuu86mdLHCwAxjNqtYUaFoVIszR/u5ZbQ843klOJ3cIU o1xrzKCt4uXalugbVlEZoihiytls0s+Fb3r+SWQiJPIE2RjtgCDYKl38XZC6kPtZkTnj5Y 37OPijkzF785d/LMEFJsjHSHveLfl4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796480760; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CJVdst3xTAv0l6Conj6qgO7P4I3dSuGVTnuLeaV/ejE=; b=6Zyp37rfTGkgOSQCn13+uvv7nbafkMo/d6zd+cOclj2OSNAb+6REJgIPjisOTkzZ71BG7v a3lXcruLK9E2oKalrsWRzQGgiXzSJVywhRGdMOeirWG/FcltjiaIXOQdCCoAQhdiY5jkX7 +EWf73jbhMVSCxv571+IXJJP8G5zRL8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=YUdSSmrq; spf=pass (imf17.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.47 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: linux-mm@kvack.org 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=1796480758; v=1; x=1797085558; b=YUdSSmrqchAbkwMZ/BJYYGzhX9sqO7cye8N8B7h7dSd1+VyQXD29ILpqtigAEp9MS6CzEyut duz/OJehXovtW3o9xW9vP4StNmR7qQ8Y4CvNabGsaL2TdSqkGHuBxCSK8NiHWtQgaBYXZenyCuz dAZu36ZfJhZG4z5Hyj38cRNY= X-Envelope-To: linux-mm@kvack.org 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-Archived-By: 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) X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A6BD040007 X-Stat-Signature: j3gdf985gbnx1wn9o519xupbtiebcwqp X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796480759-955487 X-HE-Meta: U2FsdGVkX18b51Y8ieD6ad7wr/Hzw9mYta4NvzZ6ewrfCK8D+pwt0JsBEVc2fmUVBExjV/9Vz1smkgwp69R1vzkjfWFlAQj10ziVsGGBVWz6NlPqfdHbfQZAwQRZ5cWYqTDZS+sBMPdaNgZr0CzQ7Dy0kPF7Wg+QU3IO79ErsmlRV0BugqrupAY4SazPzUZHHOUN70qZBGX3A9lietRfOxytWIrlZPVpN+CZ2PbyBM6D5WpfRNl+ERfbKRmuQ3PSEfww/sOQtg28I4LrxB3nrEgDMhle8rCot/cwc9nHT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mnxXhrIou2NiIECvabLO1VHSJwPOW1haIiZW1D9wurC1m9UTc8xAAx2IASdDqVDOBY6xbMdR7DiqZtJ1G9GbmPl6ZHgT1NHmljzS8i8SNvDaAvf9zsK2Kyb64g0vCEYluyiw98ZUBlnnFUsqVGkA6fTLP5PYQl6HjujioF5oHNl2nzMk8YYyVxZTsWsWxKJUv+p0YZf4/oRODYNzaW1Ex73I2AgIZ4h3eTzTXygKdWJHOrLls1ck7cJsJYZtJ3ZV35QnuWnjEGe6Wzyd62kn5w== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 > 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