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 0F6C6606A31A for ; Wed, 2 Dec 2026 17:25:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=I3ER+WtN Received: by kanga.kvack.org (Postfix) id 2418E6B0642; Wed, 2 Dec 2026 12:25:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2192E6B0643; Wed, 2 Dec 2026 12:25:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 107F06B0645; Wed, 2 Dec 2026 12:25:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DF6096B0642 for ; Wed, 2 Dec 2026 12:25:33 -0500 (EST) Received: from smtpin14.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 815831203F8 for ; Wed, 2 Dec 2026 17:25:33 +0000 (UTC) X-FDA: 85499719746.14.84A4109 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf02.hostedemail.com (Postfix) with ESMTP id 9EFE58000E for ; Wed, 2 Dec 2026 17:25:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=I3ER+WtN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796232331; b=AkHeWoZzKwQiv+vA937RYVKZF+uq5xAnlxL+Gmk+EGCG5ogrmCSR6Zf7jvayKbjPIVvmu4 aZqgw8AkqfOXHjCip+XXuNRJEeVwH87djlWiD5WY4gs0E6w8kkD2gEd1pR3vTOBe8spRmj VOIucMwiOYPQA6hQyp3MBy0NtTIiyTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796232331; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=I5/0w05NlO9FHI3n9PTeUdY6i5YlWAfQX3K1q7008Mk=; b=Kj2v3ST+VgCNxrOlX9BkWX0PdK/if2LQt21M5gd7rUcn38vkZrE/zDsqKoJJICzSaSq1Od TWtT++R+tNJGhlkeKtP2XvsGVuFl5nzl/woQapLvQqKRw+VGhI363DF6WUPSoj/faKmZve bY4mJ0cEPSG2ve+RxSEQo52wXzegclY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=I3ER+WtN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=ryncsn@gmail.com Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b09a83d12aso9258209a91.2 for ; Wed, 02 Dec 2026 09:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796232330; x=1796837130; darn=kvack.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=I5/0w05NlO9FHI3n9PTeUdY6i5YlWAfQX3K1q7008Mk=; b=I3ER+WtN2RDQPQrXIH6o5dSr1A0ctTA7y+fuYf6hRwMdkIQHK3cU376RRayC6F0pT3 wgJQG6A93FnzBxeMbQjG5vBYpezJ1R2S8G1Ijw/IZXXjwen2nm9oH3O+n8el3FhA4apO GDfolu/ESMsWyYj+gl38jp53aUMsfa7LHbOya0hXNYPADOeYK98HY+++vvW5xZxep+d+ 8CuFx4VZvrroTZ1vUxzNE9Gqfos0VrHF3BsFmlsHHJD6X8YPO8ORnbdIIHTNIWOJKsvQ tIu3cqriL+bL/RhxNXJio3o5zXDFwa50tqUH4nYmLyqUaOLUKpYOsbRNLai/zyXD/uN6 JQLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796232330; x=1796837130; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=I5/0w05NlO9FHI3n9PTeUdY6i5YlWAfQX3K1q7008Mk=; b=G8Dy1stjz3fzwW2voFg4SOdKE1BlLECsEVpLHnz0F8F3i9RloEinHjxVwSeU04HPz5 06MCL4qCDSoHR+NobuZkIW+2Pkv9KM/ycAk2qk/FJ2svykwX6D9S/JU86oa0wwR2GMVN hrR0oALach/82SKs/5S5W3RYSDcFUU4wZzCrFe5fOK0wEfwsrPrSz0H2cEG3CHMSZHaN onzx/0LPd9G+uqur5ghymCWAql06cjOUeQf1eOqF4cu3XOYLmxEGPJC0yCOjOqZYZC/b SbvZqJTf6T38pjbJXp4/p8DDXPPeI9uw+hO5+uFi+fvf9Cim9KFJpeIHLNpjwVF+fODe TJhg== X-Forwarded-Encrypted: i=1; AL+hErGgVPQ1h88Jz2bFe/ZY7tWvHJeETMAHmYkv6DZMZ+2xoYbPrgSlpQIjrABuoFB2r49pRnYqrutffw==@kvack.org X-Gm-Message-State: APuU4Z8JdYp4vd2n7NTKBB4E99pqm2+tNAYPgrseiCaFHrHCM5rmvwv7 zvhiCbz3i9BL6GsLP/n067cg2tvnZ0X3h63ROJhZ5YPdz0YpVhjWnfv/ X-Gm-Gg: AZFdTZfP7MLdw+teA5YAN/KzGWo/PdibctetHGm3JtKHOYSDqF/DOs8tRhAoX627cYY 65gPshEH+MpqsVgjVbfgxVu7pp7gyyfjYv/X+NZ67EH0rMJlN1WGTyrFwAzjdQPLvNCWLPCN9Lq lt9OXY7Leom42TXcIw9IsH6NY1UbD7v4f1QtXZsnLA2bIaHYCkdJe+6Ux96PLaWc52ikJ4r9sfy n/Qm7oFsD3BEK2V6yLpWmf1j1aPBGVptTMK0B1FabBo7lHDhC7jB3LomFZWVh0y+L2TADY9j6Q9 xzo1C4nFHYbCWEvH3z4A2+MAjbsbjlpFCsiyy6QzvqGOh1w9ANxDamstB2PZDXrk3GU97N2hcy5 C0R//0rKJQnrKLfQbwCVrWAI5k/+qx/p4bkKx72CuofMExR4KFCUl8+NhTkxxVcyAaj1cMHR0Dg tA0ZHG/S9bx3s2K5C1e4kN6tUjoDMgE2W2lt2Ciowc0Lh3SNKqE1AlVJp3RDU+VA0uqvuv7D0rj k8DnA1sxk6FSH2TFifyh5t+TqfT0ZqmChKo4mF4+Wvg8Xa3h70ibdrZJy9A3wIoNcFbaVlWApna aZY6u4b2m1l6JY+LoIEVVZ+u41N9EYNebjAdR17JFuM2mtqUpf3UvZXEMyo4hzULI+iU2WY= X-Received: by 2002:a17:90b:52:b0:3b4:f457:9e5d with SMTP id 98e67ed59e1d1-3b4f457a24amr28931049a91.9.1796232330321; Wed, 02 Dec 2026 09:25:30 -0800 (PST) Received: from KASONG-MC4 ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d5e934sm62534a91.10.2026.12.02.09.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:25:29 -0800 (PST) Date: Thu, 3 Dec 2026 01:25:14 +0800 From: Kairui Song To: Andrew Morton Cc: Kairui Song , linux-mm@kvack.org, Johannes Weiner , Muchun Song , Qi Zheng , Ying Huang , Chris Li , Baoquan He , Nico Pache , Usama Arif , Michal Hocko , Roman Gushchin , Shakeel Butt , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SJ Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Tal Zussman , Xiang Liu , Ehab Ababneh , Zhao Zhenzhuo , Lian Wang , Joanne Koong , Kunwu Chan , Hui Zhu , Maxim Muzafarov , Tianyi Chen , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, linux-doc@vger.kernel.org, Ridong Chen Subject: Re: [PATCH v7 00/19] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup Message-ID: References: <20261202-mglru-fg-v7-0-5965a96d86d0@tencent.com> <20261201192218.3cbb143406a2744a33e555ec@linux-foundation.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261201192218.3cbb143406a2744a33e555ec@linux-foundation.org> X-Stat-Signature: phowm85pnotmeg5hojibifma4ypsnznq X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9EFE58000E X-Rspam-User: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-HE-Tag: 1796232331-178840 X-HE-Meta: U2FsdGVkX1+YTIoGhXvk+Ai/vyy16l0toniK+fN5XAyXeT3K7w5FUGju3bwGD0N5umVqx+C1GsdQdkev7m39HEVwNHlWlXkS8edth0sjRRDS/PSdxpTAp2GUCGUIctuWU+oT5OAa6l/H4i+WtbX39EgmDbJkfPwXVAGJa51krdpL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2TDgfDRfS9FBlr47dA0kJMcRkVrYuaq0iLiW3c/LPBeceeeqxo0shyhrtZXAgeX1LCV7FSApKg4Dn/APFb/+p4j7w4qeohcepzFiEviiJ+3J0FD7TKok/yLXc2CAEYeBa3Yj58dNVQs81gKYVoDNUV+5EZn/+QtbBW1pB5yiRa9/em/mi/XcBEezQbfEX+ygkqNIgi+fRV1inzfp3JN66/xzBHA/nHWFJbPIbNGoUIqRWRfZisgnHbaR/0tvTMVx9mBWP7+bGxgC16GOKr1xpIrWjtL87YUVE6oL8ZMxTm47d7OCvatuJXDUKydPFDG2FZ9jnxCnxV0DhciSunOMRySx5wkKCwR/+fS9nBDHknH1i3YurtFdoi6U+FHZdiJpyWrV3vR3P62Bb1EV3eqL8vMWP5SkcWEWu38IUexZgaU5ZJsqOdhC+SB/DlTrEDD8mL7SJeVhIYXBNk7Yw2Ng2GMX/jpe/8xWjVlBRbirk9hzDeJdcX8V9511dyXlKLdLIjbz6BYfBV3vscvv8532lt7qviRtFeZ8FJ8sjNpOp6JE7HHRHn4g6carvoCx6e18JJp2eFRbc2bFnaop9cbnS3CZsg0HKuGhHi8c1FOcUBMrhLdiR3KUwv7kxnQlKM0fuVDsIcdlC8VJiNeYsqnVgn7VyV+fbp+xp/l5tlmnAN09Wo9G6+fyoFPBTaVUPpADNFECXOsNH6PnG kEZC9pR0 FScrXwYc6WlI6AsgY7uEcQ== 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 Tue, Dec 01, 2026 at 07:22:18PM +0800, Andrew Morton wrote: > On Wed, 02 Dec 2026 04:18:40 +0800 Kairui Song wrote: > > > This series implements MGLRU-FG following the idea proposed at LSF/MM/BPF > > this year [1], based on current mm-new. Depending on the workload, it > > improves the performance or reduces IO by roughly 10% to over 50%, > > fixes multiple long-standing issues with MGLRU metrics, and drops one > > page flag. > > > > I gave this a 2-hour workout on 64 vCPU QEMU. Everything checks out. > It might have found one thing: > > : The test gives a 128 MiB cgroup a 4 MiB file that it reads repeatedly > : and a 512 MiB file whose reads force reclaim. The 4 MiB file is the > : hotset: 1,024 pages we expect to survive the cold-file scans. > : > : With three hot-file reads per scan, the kernel before the series (A) > : kept all 1,024 pages after warmup. The 19-patch kernel (B) sometimes > : evicted every one: in 6 of 10 cycles in one run and 3 of 10 in another. > : Reading the hot file then took about 2.4-3.2 ms on B versus about 1.3 > : ms on A. B also scanned more pages. > : > : The result depends on access rate: with one hot-file read per scan, B > : kept the pages and A mostly lost them. So the series helped one > : workload but regressed this more frequently read one. The trace points > : to hot pages being selected for eviction, but the run did not establish > : a safe correction or isolate which of the 19 patches causes it. Ah I see, this is the typical hot cache pollution vs code cache pollution issue. Here it's trying to fit 512MB + 4MB in a 128MB cgroup, so clearly it won't fit and if the 512MB is the cold part, it will turns the memcg LRU over about 4 times. Still TLDR (as LRU related things are always complex to explain): It's a trade off and I consider it a good one, and the problem will be fully covered by refault distance with no regression. I'm not sure how the agent actually conducted it, and maybe in the test env LRU_REFS_WIDTH is shrunk? But right now, FG does tend to be more proactive to avoid stall cache pollution, while mainline MGLRU does have the trend of (over)protect stall cache in some cases. Note the case here has a "warm up" which generates shadow, so the 512MB is not actually cold but more like "warm". A "warm" scan will trigger aging, and by trigging the aging 4 times, it will replace previous hotter workingset, as that workingset is now considered stalled. Without that, in mainline, stall cache pollution is a sometimes even worse problem. Many people reported that issues in previous discussions. See this table which I collected from my VM (30 rounds): setup | 512M warm + 4M hot (3 reads) | 64M hot (3 reads) -> 72M hot (loop) baseline | keeps the 4M (27/30) | keeps 64M, FAILS to cache 72M (fd) FG | LOSES 4M (14/30) try cache the 512M | keeps 64M, fully caches 72M FG+RD | keeps the 4M (30/30) | keeps 64M, fully caches 72M The 64+72 column is to demostrate the stall-LRU problem: 64M is scanned 3 times, then it loops on the 72M set. Mainline over protects the old 64M set, so the new 72M only gets 64M cached and thrashes every scan (cost ~473ms per scan). FG demotes the old set and caches 72M fully (only 5-7ms per scan now). The stall LRU issue is harder to handler as it could get stuck there forever. Clearly for the 512M / 4M case we should not try cache the 512M part at all since it won't fit anyway. To solve that properly we can use refault distance, which is described in the cover letter (refault distance can help the workingset shift go faster too in some case, in this case is can help to prevent invalid shift). This RD code is also what I posted previously: https://lore.kernel.org/linux-mm/avd5bI-b9y1nKWw5@KASONG-MC4/ Also results on Maxim case here: https://lore.kernel.org/linux-mm/CAMgjq7DDUHrHEXiGDnPn6+keL6VxWWMabAr-BRrNM_bwsKPZnQ@mail.gmail.com/ With the above refault distance adaption, FG + RD behaves better in all rounds. The idea of FD is when the cold part is way larger than memcg (random or scan), folios faulting back with a too long distance should not be protected at all (the 512M part). And meanwhile if the refault distance is short, consider protect it more proactively. I have to say we are still trying to tweak the refault distance part better, but I think we are good and in the right direction. > And it proposed a little GUP speedup: > > From: Andrew Morton > Subject: mm/mglru: skip refs decoding for already referenced GUP folios > Date: Tue, 01 Dec 2026 17:59:24 -0800 > > GUP-fast calls folio_inc_lru_refs_fast() for every folio it pins. After > its first reference, a folio with PG_referenced set still incurs the > generation decode, refs decode and static-key test on every pin. The > v7 GUP helper is measurably slower than the preceding queue endpoint > in this repeated-pin workload. > > Test PG_referenced first. If set, both the MGLRU refs count and the > classical LRU referenced state are already nonzero, so the helper has > nothing to change. Otherwise, check the remaining MGLRU refs bits and > atomically set PG_referenced only when needed. Reevaluate all tests > after a failed cmpxchg. This retains the original behavior for MGLRU > on, off and during switching, including a folio still on a generation > list after the static key turns off. > > In fresh 7.4.0-rc4 guests with the 19 v7 patches, GUP_FAST_BENCHMARK > pinned 16 MiB of 4 KiB pages in 64-page batches for 8192 calls per > thread. Across two interleaved baseline/fix pairs, the single-thread > median kernel get time fell from 52.9/53.8 to 49.3/50.1 us per call. > The 64-CPU medians fell from 88.3/85.7 to 79.8/85.8 us, with wider > run-to-run variation. GUP selftests passed 60/60 with MGLRU enabled > and 60/60 with it disabled; MADV selftests passed 24/24 with MGLRU > disabled. No kernel warnings were observed. > > Link: https://patch.msgid.link/20261202-mglru-fg-v7-10-5965a96d86d0@tencent.com > Cc: Kairui Song > Cc: linux-mm@kvack.org > > include/linux/mm_inline.h | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) This one looks good to me, thanks!