From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.185 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796174640; b=4OksooC+pW1X0GtzvnCm7up2kmUkLpFclgZfaABZclqgNSHl5pR+SSzdhcqR9sZieP5/ ae9Yvi56/EzxiFYdXBVyCNQKGeQ9XQ6GiR/Qx+eFNGKdA5kxS5NkjSaQQeW2OUZ9DuVFp x6J373FEdffs9lQQZBPwu0RBRzyId7D8bYUWXekkSYTCK+Hi/0oos8jfcaH1D/j1Bsl+N jWqTWJNJlCo8oBADCy3965Fn4KNL06d1zOrWu7lkD1gmAyZptemNrZlr/8tycpF/7mVVM wCt86tzTHafxRr1xeo8yTC6kvhwhTZS3aHfm1rZnn4Qc5RwmsjX+F0IoM79SLia7ciw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796174640; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=5UiQGF4mh+98ZWEQ3q9Y4tthfvazgmSueK2uGmXhHo4=; b=mVGC/fW4RJ7d9cIJfNZNwHqohrmo94QooHDmITmkcgd5tM3x4mQu0DFGroLe5TC9vQZm yH2/RzLiREsJ/CtKFrwDqXWRxJxRk+1uAScOHo9P708kaavu/OQSLpGJb3qZE+aEDi/eS IH4fs2md0dlIo/3ug08tr54u1BFIyf5XOYQEdz0mWV5DkYvxl0QSw4Fft7fphyebdsb/G TRaiNlJ8HkNOWQvUi3IYpbFMAtiDV6e+4hVdGb8WuHHc3rI+Ao+JMebSAK4Om+HwB1fl6 sK8rs3dg+JpX+0y4QI3oG6Hfm/rr5HHKHjIzyW9sRdYx0Cc9JKrcfB5NMnVwQa0Z5+w== 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=o8B8QcLB; arc=none smtp.remote-ip=91.218.175.185 Received: from mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 8E646606A325 for ; Wed, 2 Dec 2026 01:23:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E646606A325 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=o8B8QcLB X-Envelope-To: cgroups@vger.kernel.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: cgroups@vger.kernel.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-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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.