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 6E57A606A322 for ; Fri, 4 Dec 2026 12:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mSNiqLx6 Received: by kanga.kvack.org (Postfix) id 97D866B05BA; Fri, 4 Dec 2026 07:19:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 92D416B05BB; Fri, 4 Dec 2026 07:19:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81CD86B05BC; Fri, 4 Dec 2026 07:19:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3E8D46B05BA for ; Fri, 4 Dec 2026 07:19:33 -0500 (EST) Received: from smtpin22.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D47A7A7E17 for ; Fri, 4 Dec 2026 12:19:32 +0000 (UTC) X-FDA: 85506206184.22.8672E40 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf07.hostedemail.com (Postfix) with ESMTP id 3EA4E4000E for ; Fri, 4 Dec 2026 12:19:31 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=mSNiqLx6; spf=pass (imf07.hostedemail.com: domain of ljs@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ljs@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796386771; b=7zqFk81RBSLaQjyodCQjPWVrwZWZYXcR/wXlMRfAb7lKuiYBJLd1lf4rP4P2JCMiUci8lu Ea+DxGG5VWpMq1y7dZUWmmq/TLQEAu6NI0bYJc7g8BuZT9x5ipDd6xbg/q2/jMIzcayc1R 0cBol4c8xSww/EjdB3UPToNHb4ygXNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796386771; 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=Im4QfAsg2Hu8Oow5FozvUPgBYX9rcLOwFOBvYnm4ANg=; b=hLRIfbKkXbb6veqClZU849qhUvkNNIxuBGoJoAEmuJr8ZPMSGB82T1XAi+dN1dX7HJn4xy aXmhvtTVmfMLrowzfcIo3eGr1lyLCde0LNXXNIERBYfjnq1N+GggyMP2PQ24uf1enRQMEA 4N/bqTrDxoiQW50wlpV/tDgcWiE//GM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=mSNiqLx6; spf=pass (imf07.hostedemail.com: domain of ljs@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ljs@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F3149631F9; Fri, 4 Dec 2026 12:19:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C21FD1F000CE; Fri, 4 Dec 2026 12:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796386769; bh=Im4QfAsg2Hu8Oow5FozvUPgBYX9rcLOwFOBvYnm4ANg=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=mSNiqLx61YAoX21jIWO9Rr/A8NCQMs/5gkGx41CYBBKSR/Iy4ocGG//SEf0SbJEuZ RQLZ9kwKtO56JNEZzEe374yGIF4JZM3HqIIZHvyzShjoAsHLZTVZYWZU5ag+ZKW6n9 Zp2qm+eGVVwP6oo5EMbAXTvV61rEfPaod4zPeiNVyl2czkdvnOHWyTLzGWP1ua+Kls deKksmRqf0U1Obso+B9rQzOPRQ1dgPOca2UJ2x0eHKmDkyYA20f1CqruqZkUJTHxlM k6pyYvmtfO+Vten/jeF0FTygI0dsPFRFGzQujV+sSJPKl8ByzMI+OkIY//X2LvzE8i g2nnByDJwHF4g== Date: Fri, 4 Dec 2026 12:19:14 +0000 From: "Lorenzo Stoakes (ARM)" To: kasong@tencent.com Cc: linux-mm@kvack.org, Andrew Morton , Johannes Weiner , Muchun Song , Qi Zheng , Ying Huang , Chris Li , Baoquan He , Nico Pache , Usama Arif , Michal Hocko , Roman Gushchin , Shakeel Butt , David Hildenbrand , "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 , Kairui Song , Xiang Liu , Ehab Ababneh , Zhao Zhengzhuo , Lian Wang , Joanne Koong , Kunwu Chan , Hui Zhu , Maxim Muzafarov , Tianyi Chen , Aveline Noir , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, linux-doc@vger.kernel.org, Ridong Chen Subject: Re: [PATCH v8 14/19] mm/madvise: adapt for LRU refs based operations for MGLRU Message-ID: References: <20261204-mglru-fg-v8-0-64f81c876c15@tencent.com> <20261204-mglru-fg-v8-14-64f81c876c15@tencent.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204-mglru-fg-v8-14-64f81c876c15@tencent.com> X-Stat-Signature: 5yud31sfbyb9aax5c5dui8j5i5p76yt5 X-Rspam-User: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-Rspamd-Queue-Id: 3EA4E4000E X-Rspamd-Server: rspam01 X-HE-Tag: 1796386771-125856 X-HE-Meta: U2FsdGVkX1/4Ii+imhrasOCcunj1QaC2gbsQnnCTSgc6qLomTpGkpK9TZS3XKuNp68d8ntQxjURASkF0Z1akqyWgGhMYhstvKccWR3CgDDbUdxGcVNA8CZRiH3en3GxnsqGhcoUwo1a1Db2sRgCKyr5CShzYUyXOTp69u4KIktV7HAfNDYr3+AcfJ22enM8MqluAnxkDhd2E/DQWevCggrZyQMT8Mmg+DvvYPa4oNrF1clMYBTmGQ9ZG8VYodF2qU/4B9KhWlRxx1ExNKyVcrQ3nd3h3Hjg5RiRWF907Z4JRYVwC1GwHTuliSZ6PC8H3a/yndAKWhAlESfnrhC3WTtIUFnOCCy+ZrbgDqmZVgtycQlHBI6d8k6CDsHGT7q3kw1murb3Rrp/M1YPiiWVTwiXdLhzxF1HU72J+EHXe5PHJPsO6UU1/Nuc5nzdTjdmsW8U2P9a9BNH71NQGqy2GZNq2L4z3/hgckr+aK63q2W0/GE0aP9xEmRo46xokoegoAufG+x+dPGFZMDHzoxJLN0IcZqd1P8Z1O4SrWsPg3M4hcN1mA97if+8yJPpDvoDQ9UMGnrTz6H0EOPi88N8WNw2KRxZPPSphvizWihSB5Nj0Ey88Qs4U9zJKlYNxHnmf12WmdIu+jBwXoo8l0rsHj2DI0M1rgkWT2uQ6gFAw1jVmw7q3F1g6PUldsxk3/I4vhtNuxIzsqn30QzN0qxjkn9I+lnUU48c2HC0JLR2cp9PKdeQ9IhUj3VlYw2V7aypGSIJ3xj0gFim8FsZ9KYD0Oo8oRmbI2mcminCfZDi1UmHsFtEE5xIMa79TLeyri3GX7z9IFEqwkn1UNKXTJafDz2BfsAPNrYGSF2lxYpLxafw1JNl+yRnvEBO4JpWPxtbsguKWfywIiTii7BTs5CFYpoZowGvuZ2WvfDwILhMSeVQAmOSB+ceRHLwWaqUuuCj3u/f7sMcEENzo6/PpMLD 6U78OZIw 9WmUgdksyqVZKH1lN9ZIp1vtDw9ifY1RGs3wBVJpjcGKT8Ey35K+lQfYqOimu3aNyC7tHMdIthNthweK7JNXOWZYkwTwT1lKrZFV2HTX061oMf76UWJ5np1fYYiedX1YeAtEyu+tmO/ArkKpiL4wwATz17zSWluKIVYYlwiabfOTqMy87pXzfC76zSvh87sq/k8uiFLnzszYYqq92lbhQSa8GD7f4E3FUiVDZnWBE03y36doWp++j5e/8uyITFVFLfMqWXpp45GTT5O6J4Mzx2+ViMDWkReA3SzKKXdfWyaqzvg8HFdhNYGGA/7hDu8HmZUPVTmbAOxY0yJiNaK8S6mljwDQmjOG1ljmFN2TUuLlnb9dLBYvzVxY00EVhBjhYKuF45y/Yn94XWPQvNRQbiUGghcIhyYGcqxlkN0+27kxE1O10JNvKrPzMp0AdTYBhVyg9v58VwqMRxQQim9bKh1n0qk+Hpka20R064vrDtKhoQkTJO4x/izqhWutadDSAER3RBAEcgtpUiEUUjQCoNv/F+jyPjmeyV5Y7xlMPz0NfGHCDlokuj/AHoYBUqEVqfcG3WrnuTKIfMTkr9UETSI3jY7pkan0PBwsskkUANJ8uNk3RFvWetO2+cK5qId1oHL/FbvYaPXSR/ZjoZGj09utusA== 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 Fri, Dec 04, 2026 at 01:02:45AM +0800, 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 It'd be nice for us to figure out a way eventually to make this modular re: reclaim backends. The implementation looks sensible and you're breaking things out sensibly also so not objecting to it though :) Also hopefully Gregory's rework of the cold/pageout bits can make this even nicer (I realise I owe review on that, swamped etc. :) > --- > mm/madvise.c | 50 ++++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 36 insertions(+), 14 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index 227f1c759668..28ffaf921e9f 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -368,6 +368,38 @@ 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) > +{ > + /* > + * 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); > + } else { > + folio_test_clear_young(folio); > + } > +} > + > +static void madvise_pageout_prep_folio(struct folio *folio) > +{ > + unsigned int refs = folio_lru_refs(folio); > + > + /* > + * For MGLRU, clear refs below LRU_REFS_WORKINGSET and cap > + * the rest at it: MADV suggests the folio is cold, so the eviction shadow > + * should not record its hotness in the high tier counters, but > + * the workingset classification is preserved for PSI. > + */ > + if (lru_gen_enabled()) > + folio_set_lru_refs(folio, refs >= LRU_REFS_WORKINGSET ? LRU_REFS_WORKINGSET : 0); > +} > + > static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, > unsigned long addr, unsigned long end, > struct mm_walk *walk) > @@ -442,12 +474,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, > tlb_remove_pmd_tlb_entry(tlb, pmd, addr); > } > > - folio_clear_referenced(folio); > - folio_test_clear_young(folio); > - if (folio_test_active(folio)) > - folio_set_workingset(folio); > + madvise_cold_prep_folio(folio); > if (pageout) { > if (folio_isolate_lru(folio)) { > + madvise_pageout_prep_folio(folio); > if (folio_test_unevictable(folio)) > folio_putback_lru(folio); > else > @@ -552,18 +582,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, > tlb_remove_tlb_entries(tlb, pte, nr, addr); > } > > - /* > - * We are deactivating a folio for accelerating reclaiming. > - * VM couldn't reclaim the folio unless we clear PG_young. > - * As a side effect, it makes confuse idle-page tracking > - * because they will miss recent referenced history. > - */ > - folio_clear_referenced(folio); > - folio_test_clear_young(folio); > - if (folio_test_active(folio)) > - folio_set_workingset(folio); > + madvise_cold_prep_folio(folio); > if (pageout) { > if (folio_isolate_lru(folio)) { > + madvise_pageout_prep_folio(folio); > if (folio_test_unevictable(folio)) > folio_putback_lru(folio); > else > > -- > 2.56.1 > > -- Cheers, Lorenzo