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=1795940628; b=yZ4Fx1zMfJs63gFfWvqr36XBY5Ve33+60vRCyzlVnmxwjmZsIJbQSC9xshwlnlRL8JDG A1KWZsKmxJbec2TVeDcq4/VAcbpxzZYiA9F5q5/gAyldSuswWtDrrYkDTb2pARSRQJoKv aZ1sAAC/CM+L5IfBJr85OadLFCUGq5iWaa7IFEXmZE/qnB1rmLAendfpfH0tBNBzzbUut 70SgE0naI18Tah9rY2/kHtQIE316jliH1uqtmQKBPLHLeMSu1Hix2/cu57QyPT5mOCmLd VfqJmjjbt2JnqhkuPPC49mlX2fm6HoxyUFQt8ntDsAkWtUdYwEkktojzHZB5Ge/0gPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795940628; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=jtxd8cMh8308ZA0ZwLd67J3eNdX3mpMXaz8758j4CZM=; b=XzsNWEjg7+bf/H1MormeELEmjzdXcren2lID9YtLTOFGEFOQtBOZkNiDL+ZuGS0G9Qcm S3IneJNzjZHkLEstvnXMtBhrqs0p1A1iZMntdsy0qW5RL34n5kzWk0aM3D7//Ht2azxWM 7lodltM6c6SQnK+qdViUBrm/u51Z22lTgm1C7L5BVy6cjyVIOq8zA1wQ9bRbjuG+8DO2G bcBkQbsJbn8PdS3mqSxCbxx7ueOCO22Kxv3ughGjd9PSigAIThsbGto0hZR//7ivm5++M L2p8trgZ+iFCwzaO8NTx/9aPXU0ULGDPCtYzmlE/PzeZz090N7onQS/DobzAkggm0RQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=zXGh8LjN; 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 7FC43606A31C for ; Sun, 29 Nov 2026 08:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=zXGh8LjN Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF5541F00896; Sun, 29 Nov 2026 08:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1795940628; bh=jtxd8cMh8308ZA0ZwLd67J3eNdX3mpMXaz8758j4CZM=; h=Date:To:From:In-Reply-To:References:Subject; b=zXGh8LjNTWqTNxXRItD8pw5WWVPNw3MVNRDxoklz1+xGP04HINUnxE6KOYZ8LUHuD 9eVYY4FUlO6QV5hlm1pHpWXseudUaK1UVZjwfNLYKZkXCHfuZPQbGwCABGFrsQO3QY At+Uh5I6JnutdeEa1T3U6Vfpc9Dbs2ufSz0vF8zk= Date: Sun, 29 Nov 2026 00:23:47 -0800 To: mm-commits@vger.kernel.org,yuzhao@google.com,yuanchu@google.com, weixugc@google.com,vbabka@kernel.org,shakeel.butt@linux.dev,ryncsn@gmail.com, rppt@kernel.org,qi.zheng@linux.dev,mhocko@suse.com,liam@infradead.org, kasong@tencent.com,hannes@cmpxchg.org,david@kernel.org,baoquan.he@linux.dev, baolin.wang@linux.alibaba.com,baohua@kernel.org,axelrasmussen@google.com, chenridong@xiaomi.com,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261127031110.1034854-2-ridong.chen@linux.dev> References: <20261127031110.1034854-2-ridong.chen@linux.dev> Subject: + mm-mglru-pass-a-seq-range-to-lru_gen_add_folio.patch added to mm-new branch Message-Id: <20261129082347.DF5541F00896@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/mglru: pass a seq range to lru_gen_add_folio() has been added to the -mm mm-new branch. Its filename is mm-mglru-pass-a-seq-range-to-lru_gen_add_folio.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-pass-a-seq-range-to-lru_gen_add_folio.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next 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: Ridong Chen Subject: mm/mglru: pass a seq range to lru_gen_add_folio() Date: Fri, 27 Nov 2026 11:11:09 +0800 Patch series "mm/mglru: deactivate anon folios into the oldest generation", v4. With MGLRU, folio_deactivate() puts anon folios that are not in the swap cache into max_seq - 1, the second youngest generation, so MADV_COLD and DAMOS_LRU_DEPRIO move them away from eviction instead of towards it. Patch 1 lets lru_gen_add_folio() take a [min_seq, max_seq] range for the target generation and renames "reclaiming" to "tail", as Kairui suggested. No functional change intended. Patch 2 uses it in lru_deactivate() to add the folio to the head of the oldest generation, which matches the classic LRU, as Barry suggested. This patch (of 2): lru_gen_add_folio() and lru_gen_add_rejected_folio() are wrappers around __lru_gen_add_folio(), which can only raise the generation picked by lru_gen_folio_seq(), through scanned_seq. There is no way for a caller to lower it, e.g. to put a folio into the oldest generation without also adding it to the tail. Let lru_gen_add_folio() take a range [min_seq, max_seq] that the target generation is capped to, and drop the two wrappers. MIN_SEQ_UNBOUNDED (0) and MAX_SEQ_UNBOUNDED (ULONG_MAX) mean no limit on that side. They leave the seq unchanged when capped to, so no special case is needed for them. move_folios_to_lru() passes scanned_seq + 1 as min_seq for rejected folios, as before. Also rename "reclaiming" to "tail", and make it only pick which end of the list the folio is added to. The generation is now only decided by lru_gen_folio_seq() and the range, so lru_gen_folio_seq() no longer needs the argument. The two callers that add to the tail of the oldest generation, lruvec_add_folio_tail() and fill_evictable() for inactive folios, pass min_seq[type] as max_seq instead. This does not change behavior. lru_gen_folio_seq() never returns a seq below min_seq[type], so capping it to min_seq[type] gives min_seq[type], which is what the old reclaiming branch resulted in. That branch was only skipped for active folios, and none of the callers that pass true add an active folio. No functional change intended. Link: https://lore.kernel.org/20261127031110.1034854-1-ridong.chen@linux.dev Link: https://patch.msgid.link/20261127031110.1034854-2-ridong.chen@linux.dev Signed-off-by: Ridong Chen Signed-off-by: Andrew Morton Suggested-by: Kairui Song Suggested-by: Barry Song Reviewed-by: Barry Song Cc: David Hildenbrand Cc: Johannes Weiner Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Michal Hocko Cc: Qi Zheng Cc: Shakeel Butt Cc: Axel Rasmussen Cc: Yuanchu Xie Cc: Wei Xu Cc: Baoquan He Cc: Baolin Wang Cc: Yu Zhao Cc: Kairui Song include/linux/mm_inline.h | 57 +++++++++++++++++------------------- mm/vmscan.c | 16 +++++----- 2 files changed, 36 insertions(+), 37 deletions(-) --- a/include/linux/mm_inline.h~mm-mglru-pass-a-seq-range-to-lru_gen_add_folio +++ a/include/linux/mm_inline.h @@ -106,6 +106,10 @@ static __always_inline enum lru_list fol return lru; } +/* no limit on that side of the seq range for lru_gen_add_folio() */ +#define MIN_SEQ_UNBOUNDED 0UL +#define MAX_SEQ_UNBOUNDED ULONG_MAX + #ifdef CONFIG_LRU_GEN static inline bool lru_gen_switching(void) @@ -299,8 +303,7 @@ static inline void lru_gen_update_size(s } static inline unsigned long lru_gen_folio_seq(const struct lruvec *lruvec, - const struct folio *folio, - bool reclaiming) + const struct folio *folio) { int gen; int type = folio_is_file_lru(folio); @@ -320,8 +323,6 @@ static inline unsigned long lru_gen_foli */ if (folio_test_active(folio)) gen = MIN_NR_GENS - folio_test_workingset(folio); - else if (reclaiming) - gen = MAX_NR_GENS; else if ((!folio_is_file_lru(folio) && !folio_test_swapcache(folio)) || (folio_test_reclaim(folio) && (folio_test_dirty(folio) || folio_test_writeback(folio)))) @@ -332,8 +333,14 @@ static inline unsigned long lru_gen_foli return max(READ_ONCE(lrugen->max_seq) - gen + 1, READ_ONCE(lrugen->min_seq[type])); } -static inline bool __lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, - unsigned long scanned_seq, bool reclaiming) +/* + * Cap the seq to [min_seq, max_seq], see MIN_SEQ_UNBOUNDED and + * MAX_SEQ_UNBOUNDED for no limit. tail only picks which end of the list + * the folio is added to. + */ +static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, + unsigned long min_seq, unsigned long max_seq, + bool tail) { unsigned long seq; unsigned long flags; @@ -347,9 +354,9 @@ static inline bool __lru_gen_add_folio(s if (folio_test_unevictable(folio) || !lrugen->enabled) return false; - seq = lru_gen_folio_seq(lruvec, folio, reclaiming); - if (scanned_seq != -1UL) - seq = max(seq, min(scanned_seq + 1, lrugen->max_seq)); + seq = lru_gen_folio_seq(lruvec, folio); + seq = max(seq, min(min_seq, lrugen->max_seq)); + seq = min(seq, max_seq); gen = lru_gen_from_seq(seq); flags = (gen + 1UL) << LRU_GEN_PGOFF; /* see the comment on MIN_NR_GENS about PG_active */ @@ -357,7 +364,7 @@ static inline bool __lru_gen_add_folio(s lru_gen_update_size(lruvec, folio, -1, gen); /* for folio_rotate_reclaimable() */ - if (reclaiming) + if (tail) list_add_tail(&folio->lru, &lrugen->folios[gen][type][zone]); else list_add(&folio->lru, &lrugen->folios[gen][type][zone]); @@ -365,17 +372,6 @@ static inline bool __lru_gen_add_folio(s return true; } -static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, bool reclaiming) -{ - return __lru_gen_add_folio(lruvec, folio, -1UL, reclaiming); -} - -static inline bool lru_gen_add_rejected_folio(struct lruvec *lruvec, struct folio *folio, - unsigned long scanned_seq) -{ - return __lru_gen_add_folio(lruvec, folio, scanned_seq, false); -} - static inline bool lru_gen_del_folio(struct lruvec *lruvec, struct folio *folio, bool reclaiming) { unsigned long flags; @@ -429,13 +425,9 @@ static inline bool lru_gen_in_fault(void return false; } -static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, bool reclaiming) -{ - return false; -} - -static inline bool lru_gen_add_rejected_folio(struct lruvec *lruvec, struct folio *folio, - unsigned long scanned_seq) +static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, + unsigned long min_seq, unsigned long max_seq, + bool tail) { return false; } @@ -459,7 +451,7 @@ void lruvec_add_folio(struct lruvec *lru VM_WARN_ON_ONCE_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); - if (lru_gen_add_folio(lruvec, folio, false)) + if (lru_gen_add_folio(lruvec, folio, MIN_SEQ_UNBOUNDED, MAX_SEQ_UNBOUNDED, false)) return; update_lru_size(lruvec, lru, folio_zonenum(folio), @@ -475,8 +467,13 @@ void lruvec_add_folio_tail(struct lruvec VM_WARN_ON_ONCE_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); - if (lru_gen_add_folio(lruvec, folio, true)) +#ifdef CONFIG_LRU_GEN + /* the tail of the LRU is the tail of the oldest gen */ + if (lru_gen_add_folio(lruvec, folio, MIN_SEQ_UNBOUNDED, + READ_ONCE(lruvec->lrugen.min_seq[folio_is_file_lru(folio)]), + true)) return; +#endif update_lru_size(lruvec, lru, folio_zonenum(folio), folio_nr_pages(folio)); --- a/mm/vmscan.c~mm-mglru-pass-a-seq-range-to-lru_gen_add_folio +++ a/mm/vmscan.c @@ -1978,7 +1978,8 @@ static unsigned int move_folios_to_lru(s !folio_test_referenced(folio) && folio_ref_count(folio) == folio_expected_ref_count(folio)) lruvec_add_folio_tail(lruvec, folio); - else if (seq == -1UL || !lru_gen_add_rejected_folio(lruvec, folio, seq)) + else if (seq == -1UL || + !lru_gen_add_folio(lruvec, folio, seq + 1, MAX_SEQ_UNBOUNDED, false)) lruvec_add_folio(lruvec, folio); nr_pages = folio_nr_pages(folio); @@ -5577,10 +5578,11 @@ static bool fill_evictable(struct lruvec while (!list_empty(head)) { bool success; struct folio *folio; + unsigned long max_seq; /* * lru_gen_add_folio() uses list_add_tail() rather - * than list_add() when reclaiming is true. Match + * than list_add() when tail is true. Match * its ordering to avoid cold/hot inversion. */ if (active) @@ -5594,11 +5596,11 @@ static bool fill_evictable(struct lruvec VM_WARN_ON_ONCE_FOLIO(folio_lru_gen(folio) != -1, folio); lruvec_del_folio(lruvec, folio); - /* - * Borrow reclaiming=true to place inactive folios in - * the older gens. - */ - success = lru_gen_add_folio(lruvec, folio, !active); + /* inactive folios go to the tail of the oldest gen */ + max_seq = active ? MAX_SEQ_UNBOUNDED : + READ_ONCE(lruvec->lrugen.min_seq[type]); + success = lru_gen_add_folio(lruvec, folio, MIN_SEQ_UNBOUNDED, + max_seq, !active); VM_WARN_ON_ONCE(!success); if (!--remaining) _ Patches currently in -mm which might be from chenridong@xiaomi.com are mm-memcontrol-drop-unused-vmscan-tracepoint-include.patch mm-vmscan-move-vmscan-tracepoints-to-a-local-header.patch mm-vmscan-move-struct-scan_control-to-a-dedicated-header.patch mm-vmscan-pass-scan_control-to-the-vmscan-tracepoints.patch mm-mglru-add-tracepoint-for-scan_folios.patch mm-mglru-add-lruvec_gen_size-helper.patch mm-mglru-add-tracepoint-for-aging.patch mm-mglru-pass-a-seq-range-to-lru_gen_add_folio.patch mm-mglru-deactivate-anon-folios-into-the-oldest-generation.patch