From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,kasong@tencent.com,akpm@linux-foundation.org
Subject: + mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch added to mm-unstable branch
Date: Thu, 03 Dec 2026 10:19:42 -0800 [thread overview]
Message-ID: <20261203181942.E58A01F00896@smtp.kernel.org> (raw)
In-Reply-To: <20261204-mglru-fg-v8-14-64f81c876c15@tencent.com>
The patch titled
Subject: mm/madvise: adapt for LRU refs based operations for MGLRU
has been added to the -mm mm-unstable branch. Its filename is
mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Kairui Song <kasong@tencent.com>
Subject: mm/madvise: adapt for LRU refs based operations for MGLRU
Date: Fri, 04 Dec 2026 01:02:45 +0800
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.
Link: https://patch.msgid.link/20261204-mglru-fg-v8-14-64f81c876c15@tencent.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Kunwu Chan <kunwu.chan@gmail.com>
Tested-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Christopher Li <chrisl@kernel.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Barry Song <baohua@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Youngjun Park <youngjun.park@lge.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Hugh Dickins <hughd@google.com>
Cc: SJ Park <sj@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Vernon Yang <vernon2gm@gmail.com>
Cc: wangzicheng <wangzicheng@honor.com>
Cc: Tal Zussman <tz2294@columbia.edu>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Xiang Liu <liuxiang.277@bytedance.com>
Cc: Ehab Ababneh <ehab.ababneh@intel.com>
Cc: zhaozhengzhuo <zhaozhengzhuo@uniontech.com>
Cc: wang lian <lianux.mm@gmail.com>
Cc: Joanne Koong <joannelkoong@gmail.com>
Cc: Hui Zhu <hui.zhu@linux.dev>
Cc: Maxim Muzafarov <maxmuzaf@gmail.com>
Cc: Tianyi Chen <hi@tychen.cc>
Cc: Aveline Noir <jm5905938@gmail.com>
Cc: Ridong Chen <ridong.chen@linux.dev>
mm/madvise.c | 50 +++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
--- a/mm/madvise.c~mm-madvise-adapt-for-lru-refs-based-operations-for-mglru
+++ a/mm/madvise.c
@@ -368,6 +368,38 @@ static inline int madvise_folio_pte_batc
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_r
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 @@ restart:
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
_
Patches currently in -mm which might be from kasong@tencent.com are
mm-mglru-report-evictable-sizes-per-type.patch
mm-mglru-extract-lruvec_populated_min_seq-helper.patch
mm-mglru-reclaim-from-the-oldest-populated-gen.patch
mm-mglru-lift-the-forced-protection-of-reclaimer.patch
mm-mglru-skip-zones-above-reclaim_idx-instead-of-rotating-them.patch
mm-mglru-return-for-unavailable-anon-reclaim-earlier.patch
mm-mglru-balance-anon-and-file-scan-budget-by-refault-rate.patch
mm-mglru-lift-youngest-gen-protection-for-higher-priority.patch
mm-memcontrol-allow-update-of-lru-statistic-without-holding-lru-lock.patch
mm-memcontrol-avoid-potential-counter-leak-when-reparenting-local-stats.patch
mm-memcg-add-folio-based-lruvec-live-helper.patch
mm-mglru-make-generation-page-counters-atomic.patch
mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch
mm-mglru-make-folio-lru-referenced-times-count-a-generic-api.patch
mm-mglru-move-add-del-lru-size-accounting-out-of-lru_gen_update_size.patch
mm-mglru-gup-mark-folios-referenced-via-a-fast-helper.patch
mm-mglru-smaps-convert-to-lru-refs-based-operations-for-mglru.patch
mm-damon-convert-to-lru-refs-based-operations-for-mglru.patch
mm-khugepaged-convert-to-lru-refs-based-operations-for-mglru.patch
mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch
mm-factor-out-folio_mark_accessed_vma.patch
mm-huge_memory-mark-folio-as-accessed-more-accurately-on-split.patch
mm-mglru-make-pg_workingset-helpers-work-based-on-folio-lru-refs.patch
mm-mglru-folio-lru-refs-based-active-inactive-number-accounting.patch
mm-mglru-make-folio_inc_lru_refs-lruvec-lockless.patch
next prev parent reply other threads:[~2026-12-03 18:19 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 17:02 [PATCH v8 00/19] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 17:02 ` [PATCH v8 01/19] mm/memcontrol: allow update of LRU statistic without holding LRU lock Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:16 ` sashiko-bot
2026-12-04 6:27 ` Kairui Song
2026-12-04 22:53 ` Barry Song
2026-12-03 18:19 ` + mm-memcontrol-allow-update-of-lru-statistic-without-holding-lru-lock.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 02/19] mm/memcontrol: avoid potential counter leak when reparenting local stats Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-memcontrol-avoid-potential-counter-leak-when-reparenting-local-stats.patch added to mm-unstable branch Andrew Morton
2026-12-05 4:03 ` [PATCH v8 02/19] mm/memcontrol: avoid potential counter leak when reparenting local stats Barry Song
2026-12-03 17:02 ` [PATCH v8 03/19] mm/memcg: add folio-based lruvec live helper Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-memcg-add-folio-based-lruvec-live-helper.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 04/19] mm/mglru: rename the generation offset in lru_gen_folio_seq() Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-rename-the-generation-offset-in-lru_gen_folio_seq.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 05/19] mm/mglru: make generation page counters atomic Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-make-generation-page-counters-atomic.patch added to mm-unstable branch Andrew Morton
2026-12-03 19:11 ` [PATCH v8 05/19] mm/mglru: make generation page counters atomic sashiko-bot
2026-12-04 7:49 ` Kairui Song
2026-12-04 10:15 ` Ridong Chen
2026-12-03 17:02 ` [PATCH v8 06/19] mm/mglru: skip the flags cmpxchg when nothing changes Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-skip-the-flags-cmpxchg-when-nothing-changes.patch added to mm-unstable branch Andrew Morton
2026-12-03 19:21 ` [PATCH v8 06/19] mm/mglru: skip the flags cmpxchg when nothing changes sashiko-bot
2026-12-04 9:58 ` Kairui Song
2026-12-03 17:02 ` [PATCH v8 07/19] mm/mglru: frequency guided workingset promotion (MGLRU-FG) Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch added to mm-unstable branch Andrew Morton
2026-12-03 19:59 ` [PATCH v8 07/19] mm/mglru: frequency guided workingset promotion (MGLRU-FG) sashiko-bot
2026-12-04 15:45 ` Kairui Song
2026-12-05 10:56 ` Barry Song
2026-12-03 17:02 ` [PATCH v8 08/19] mm/mglru: make folio lru referenced times count a generic API Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-make-folio-lru-referenced-times-count-a-generic-api.patch added to mm-unstable branch Andrew Morton
2026-12-03 20:17 ` [PATCH v8 08/19] mm/mglru: make folio lru referenced times count a generic API sashiko-bot
2026-12-04 16:13 ` Kairui Song
2026-12-03 17:02 ` [PATCH v8 09/19] mm/mglru: move add/del LRU size accounting out of lru_gen_update_size() Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-move-add-del-lru-size-accounting-out-of-lru_gen_update_size.patch added to mm-unstable branch Andrew Morton
2026-12-03 20:26 ` [PATCH v8 09/19] mm/mglru: move add/del LRU size accounting out of lru_gen_update_size() sashiko-bot
2026-12-04 16:15 ` Kairui Song
2026-12-03 17:02 ` [PATCH v8 10/19] mm/mglru, gup: mark folios referenced via a fast helper Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-gup-mark-folios-referenced-via-a-fast-helper.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 11/19] mm/mglru, smaps: convert to LRU refs based operations for MGLRU Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-smaps-convert-to-lru-refs-based-operations-for-mglru.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 12/19] mm/damon: convert to LRU refs based operations for MGLRU Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-damon-convert-to-lru-refs-based-operations-for-mglru.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 13/19] mm/khugepaged: convert to LRU refs based operations for MGLRU Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-khugepaged-convert-to-lru-refs-based-operations-for-mglru.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 14/19] mm/madvise: adapt for LRU refs based operations for MGLRU Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` Andrew Morton [this message]
2026-12-03 21:20 ` sashiko-bot
2026-12-04 16:46 ` Kairui Song
2026-12-04 12:19 ` Lorenzo Stoakes (ARM)
2026-12-04 13:11 ` Kairui Song
2026-12-04 13:25 ` Lorenzo Stoakes (ARM)
2026-12-03 17:02 ` [PATCH v8 15/19] mm: factor out folio_mark_accessed_vma() Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-factor-out-folio_mark_accessed_vma.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 16/19] mm/huge_memory: mark folio as accessed more accurately on split Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-huge_memory-mark-folio-as-accessed-more-accurately-on-split.patch added to mm-unstable branch Andrew Morton
2026-12-03 21:41 ` [PATCH v8 16/19] mm/huge_memory: mark folio as accessed more accurately on split sashiko-bot
2026-12-04 19:59 ` Kairui Song
2026-12-03 17:02 ` [PATCH v8 17/19] mm/mglru: make PG_workingset helpers work based on folio LRU refs Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-make-pg_workingset-helpers-work-based-on-folio-lru-refs.patch added to mm-unstable branch Andrew Morton
2026-12-03 17:02 ` [PATCH v8 18/19] mm/mglru: folio LRU refs based active/inactive number accounting Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:19 ` + mm-mglru-folio-lru-refs-based-active-inactive-number-accounting.patch added to mm-unstable branch Andrew Morton
2026-12-03 22:18 ` [PATCH v8 18/19] mm/mglru: folio LRU refs based active/inactive number accounting sashiko-bot
2026-12-03 17:02 ` [PATCH v8 19/19] mm/mglru: make folio_inc_lru_refs lruvec lockless Kairui Song
2026-12-03 17:02 ` Kairui Song via B4 Relay
2026-12-03 18:20 ` + mm-mglru-make-folio_inc_lru_refs-lruvec-lockless.patch added to mm-unstable branch Andrew Morton
2026-12-03 22:39 ` [PATCH v8 19/19] mm/mglru: make folio_inc_lru_refs lruvec lockless sashiko-bot
2026-12-04 17:10 ` Kairui Song
2026-12-03 18:18 ` [PATCH v8 00/19] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup Andrew Morton
2026-12-03 22:39 ` sashiko-bot
2026-12-04 20:07 ` Kairui Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203181942.E58A01F00896@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=kasong@tencent.com \
--cc=mm-commits@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.