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 1AD59606A322 for ; Wed, 2 Dec 2026 01:24:04 +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=o8B8QcLB Received: by kanga.kvack.org (Postfix) id 3E23A6B05EA; Tue, 1 Dec 2026 20:24:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 392DA6B0601; Tue, 1 Dec 2026 20:24:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2823D6B0606; Tue, 1 Dec 2026 20:24:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0567C6B05EA for ; Tue, 1 Dec 2026 20:24:02 -0500 (EST) Received: from smtpin28.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8751D16015F for ; Wed, 2 Dec 2026 01:24:02 +0000 (UTC) X-FDA: 85497296724.28.CEC6F5A Received: from mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by imf22.hostedemail.com (Postfix) with ESMTP id AA9A9C0003 for ; Wed, 2 Dec 2026 01:23:58 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=o8B8QcLB; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796174640; b=lWJ9DWzgt43T/FXaL1CCWKGRsboCvPlgp9gwG4VDYZNQbWx7rYfNty3D6i/QrT2i75TE1s k8y+kYSb6kUMNLjJIpMoRsl8JY10SnZx3ueux/WWUIW1OWGfnVlfUSgFZQsXX3YDFCvfhH SawKWYpD8USNtbOE+OeqZEjYBRjQKx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796174640; 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=5UiQGF4mh+98ZWEQ3q9Y4tthfvazgmSueK2uGmXhHo4=; b=cac4Ft0/A9v9AjOiityu1f1Fvn5GHL+R4JaM4RDkoq956DCNmo78HGmroWUk7MoCcqkJEL Hv7fi4r8RswTDLXvoJ1a9ECYzFeUCQNFN79iDNnJgd4ndLeCwxxKRlBpPLUM66F4rZt2eS pGkBN6Horn53Ho6tl0Ii10G+lz5F/Y4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=o8B8QcLB; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=EK74zyyFlHLuj9qEInX1LctlYjbamp0SQyQAbfLviJU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796174637; v=1; x=1796779437; b=o8B8QcLBdLvU+EQPU1wIjGak9PTSGlywXiLweBlJCudKde5alsOcjtEjTZ/SQ3eMEITjcLBa 6B8hnJwXFVZZWpg00uJM6jv1OU68TwzSqz32w8b0uGpw7YzoOAkUyy+ciZEB6IU98wXKMz8gAER p0Rp+YvEAcCfGsvHpbjCBYr8= X-Envelope-To: linux-mm@kvack.org Received: by mta11.migadu.com with ESMTPS id 1157fc1b6bf081bf; Wed, 02 Dec 2026 01:23:57 +0000 X-Mizu-Trace-ID: 1157fc1b6bf081bf X-Migadu-Flow: FLOW_OUT Date: Wed, 2 Dec 2026 09:23:48 +0800 From: Baoquan He To: Kairui Song Cc: "David Hildenbrand (Arm)" , linux-mm@kvack.org, Andrew Morton , Johannes Weiner , Muchun Song , Qi Zheng , Ying Huang , Chris Li , Nico Pache , Usama Arif , Michal Hocko , Roman Gushchin , Shakeel Butt , 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 , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, linux-doc@vger.kernel.org, Tianyi Chen , Ridong Chen Subject: Re: [PATCH v6 14/18] mm/madvise: adapt for LRU refs based operations for MGLRU Message-ID: References: <20261124-mglru-fg-v6-0-8ffea39934a6@tencent.com> <20261124-mglru-fg-v6-14-8ffea39934a6@tencent.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AA9A9C0003 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: mwr7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9AOmcrXJHItc29+7uDzf0R6AMpum0TSXXxHtsjeJgDKqI0BiNjJL/OfU81gniAKv5t7W/j+C5tYtHfQEg2fe8KHtvN6TX5SpDqvWqJcJ2cEmKdeteDWFIB9MtkVTesaB4DJ/sz9m62HdLRjRyAZRVmZuul4IaMYgfS+3WgJFZ9Il5DrO59ANnNfrD5XtLUS6mYbkr1/qeNpfVEX2SuYkiUl+2d+JIYU7G9PSgy7EFCaFiU24Gk+fbPDXzIk4+cQat1GEULZd60NNQW756lVuopZtUNm0VQm3buSIu6T6G0iZo5Gr6vcCRqn2fWGjKBFDYJ8m8xxyUXOLoJSN2d1b0TUOPJ15CYc8cihUSHUQlt3fWSVkVQMVRZTWsfuGRdGnOiEF/UsZDrHQCEjF1UmULT3jjuHtfUPgj2p7mGUNpzRn1S5sYzTodi5n2HyIS39oujRH4s29b9LOiMj/nLEsSm4rUGFDL8wSEWd0pPFzU76D1GIlgCIIsst4di1Chwl+672jH7HhWwchW8tv9F4O1mfvYDSW+INBAYMiWhpNN8Pog3HmLMBWt78gDm7/BrUQmAkCwJXB3/HEGnR+DIKfGaL2wU30kwANqhAQcAqa0Jb9NHoAT5lBXbCISrdTqXTSjo7u2G7RViW7h+tS9Grs2b9/c8/WW6DE7/lg4ypBXOc= 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 12/02/26 at 02:28am, Kairui Song wrote: > On Wed, Nov 25, 2026 at 6:10 PM David Hildenbrand (Arm) > wrote: > > > > On 11/23/26 19:53, Kairui Song via B4 Relay wrote: > > > From: Kairui Song > > > > > > For the active/inactive LRU, madvise clears PG_referenced so that one more > > > access is not enough to reactivate a folio, and keeps PG_workingset on a > > > folio demoted out of the active list so its refault is still accounted as > > > a workingset refault (PSI). > > > > > > MGLRU keeps that history in the folio's refs count instead, which now > > > lives in PG_referenced, PG_workingset and LRU_REFS_MASK, so writing to > > > those bits directly corrupts the count. The two hints want different > > > things: > > > > > > - MADV_COLD resets the count in folio_deactivate(), which also requests > > > deactivation. > > > - MADV_PAGEOUT clears non-workingset refs and caps the rest at > > > LRU_REFS_WORKINGSET after isolation, before handing the folio to > > > reclaim_pages(). The hint marks the folio as cold, so the > > > eviction shadow records the capped count and does not inflate the > > > eviction/refault counters of the hot tiers that drive aging, while > > > folios at or above the workingset threshold keep their PSI > > > classification. > > > > > > PG_young is cleared for both LRUs as before, so the referenced walk does > > > not count stale history as a recent access. > > > > > > Reviewed-by: Kunwu Chan > > > Tested-by: Andrew Morton > > > Signed-off-by: Kairui Song > > > --- > > > mm/madvise.c | 54 ++++++++++++++++++++++++++++++++++++++++-------------- > > > 1 file changed, 40 insertions(+), 14 deletions(-) > > > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > > index a36cfe98dd81..7e562e78d52a 100644 > > > --- a/mm/madvise.c > > > +++ b/mm/madvise.c > > > @@ -360,6 +360,42 @@ static inline int madvise_folio_pte_batch(unsigned long addr, unsigned long end, > > > FPB_MERGE_YOUNG_DIRTY); > > > } > > > > > > +static void madvise_cold_prep_folio(struct folio *folio) > > > +{ > > > + /* > > > + * VM couldn't reclaim the folio unless we clear PG_young. > > > + * As a side effect, idle-page tracking loses recent referenced history. > > > + */ > > > + folio_test_clear_young(folio); > > > + > > > + /* > > > + * For the active/inactive LRU, a folio demoted out of the active > > > + * list should have PG_workingset so its refault is still accounted > > > + * as a workingset refault, and the referenced bit always needs to > > > + * be cleared even for inactive folios. For MGLRU, MADV_COLD clears > > > + * refs in folio_deactivate(); MADV_PAGEOUT handles refs after isolation. > > > + */ > > > + if (!lru_gen_enabled()) { > > > + folio_clear_lru_refs(folio); > > > + if (folio_test_active(folio)) > > > + folio_set_workingset(folio); > > > + } > > > +} > > > > These are all not things that madvise.c should have to worry about. Can we have > > some call into folio/reclaim code that will take care of this? > > I tried many times on this and found it's increadibly hard to do so > without changing the behavior of CLRU globally, as the whole if > (folio_test_active(folio)) then folio_set_workingset(folio) here is > actually a "workaround" for CLRU, and we have two LRU... > > I managed to reduce the code left in madvise here a little bit, > though. I think we can clean this part further, later. It will be part > of the work to better seperate CLRU with MGLRU, or making MGLRU the > default one. I agree with both, seperate CLRU with MGLRU, and making MGLRU the default one. The latter is being done on mobile phone by default afak, and the latter is also also enabled on some distrols and servers.