Re: [PATCH 3/6] mm/mglru: enhance cold/hot inversion handling in inc_min_seq()
From: Kairui Song
Date: Thu Aug 27 2026 - 00:38:57 EST
On Fri, Aug 21, 2026 at 7:09 PM Barry Song (Xiaomi) <baohua@xxxxxxxxxx> 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>
> ---
> mm/vmscan.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 99ee3c833d54..3b618a51cde2 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -3946,9 +3946,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]);
> + } else {
> + 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);
> --
> 2.34.1
>
>
It looks more consistent with the one in sort_folio, the idea LGTM:
Reviewed-by: Kairui Song <kasong@xxxxxxxxxxx>