Re: [PATCH v2 3/7] mm/mglru: enhance cold/hot inversion handling in inc_min_seq()
From: Ridong Chen
Date: Sat Aug 29 2026 - 22:44:22 EST
On 8/28/2026 7:47 AM, Barry Song (Xiaomi) wrote:
During aging, a folio's generation may already have been updated by
folio_update_gen(), even though it has not yet been moved to the
corresponding generation list. Such folios are hotter than those
already in that generation.
It makes sense for inc_min_seq() to increment the generation of
folios that were never promoted during aging and move them to the
tail of the new oldest generation. However, folios that were already
promoted should instead be moved to the head of their updated
generation, just as sort_folio() does in scan_folios().
Otherwise, promoted folios could end up behind folios that were
never promoted, effectively inverting their hot/cold ordering.
Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
Reviewed-by: Kairui Song <kasong@xxxxxxxxxxx>
Tested-by: Xueyuan Chen <xueyuan.chen21@xxxxxxxxx>
---
mm/vmscan.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 07c22d51debd..b10d1703d907 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3949,9 +3949,12 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) != zone, folio);
new_gen = __folio_inc_gen(folio, old_gen, &gen_increased);
- list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]);
- if (gen_increased)
+ if (gen_increased) {
delta += nr_pages;
+ list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]);
Nit.
This is a bit confusing to me.
When I read the code, I thought this implementation contradicts what the commit message says, which means I thought that we move the folios that have been promoted to the tail.
+ } else {
Maybe adding a comment would make it clearer, like:
If gen_increased == false, it means the folio has been promoted, so move it to the head.
+ list_move(&folio->lru, &lrugen->folios[new_gen][type][zone]);
+ }
/* don't count the workingset being lazily promoted */
if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) {
int tier = lru_tier_from_refs(refs, workingset);
Overall, looks good to me.
Reviewed-by: Ridong Chen <ridong.chen@xxxxxxxxx>
--
Best regards
Ridong