From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386770; b=WFh1TqOG8M3pR6lveuKhUFxa5AtHYwDdKhJm2fRD6TSzAnplzsqGVJybl4//2/Z1b6uv jUvu7kerJFue9M7kvODZwgx/S4/PUF/Y0AZ0JcZe2PF3c/+L9z3sbk+PeW1mQrYzKDvFV gLhwcNTKKE9donGWBti8WZUzwIFDY8K4r+NKO6RWguBFqurb+ORtK6krDTVlbbjMV62fh nAOCWgMhMMWJcxS2hyaQ0qnZTmshzO2M5TSMY0e/qUZqZcgF+UA/Dxlza98S4Kp+f554s L7+xuBE29uXso5DTwddgrk7nNGmJLxZ1/jbSwUlQmQvxaaqwBzGYKtFx41/gFIqKy2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386770; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=Im4QfAsg2Hu8Oow5FozvUPgBYX9rcLOwFOBvYnm4ANg=; b=ZZae/ZJuEJ2rFeaH/H03tHueMUACcbQZ1Tfg82LTB+h8nA/u+dGiLQTHLeMN5cie+WDw wML7znXaDKwj4qOWzlmx8MrMVg5j4oKmFtn/jeXvvPEyemPNwX916BjhozUR+uryixCsb 4UaRui6E4iCoUmmibdofOg+zrkDPeegki5ZNGBmin+ccj2mAJsmdQN/jyzeC6zSa3YZK4 7sn0hFa1vQBPaM9RcMd57z3ZkxnyRMSDYVYvVgw9ou5z19/ATWisVCmOs6fk/OXNGYbzH qc9DR4oycbFjST/F5cSLWE9+KX+LAgdXOKXrZELlr5Rh9CE1inW97CkvULJOclRexlg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mSNiqLx6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1E86606A322; Fri, 4 Dec 2026 12:19:29 +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 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-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=us-ascii Content-Disposition: inline In-Reply-To: <20261204-mglru-fg-v8-14-64f81c876c15@tencent.com> 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