Re: [PATCH] mm/mglru: fix cgroup OOM during MGLRU state switching
From: Barry Song
Date: Sat Feb 28 2026 - 17:41:38 EST
On Sun, Mar 1, 2026 at 5:28 AM Barry Song <21cnbao@xxxxxxxxx> wrote:
[...]
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 3e51190a55e4..ba306e986050 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -509,6 +509,8 @@ struct lru_gen_folio {
> atomic_long_t refaulted[NR_HIST_GENS][ANON_AND_FILE][MAX_NR_TIERS];
> /* whether the multi-gen LRU is enabled */
> bool enabled;
> + /* whether the multi-gen LRU is switching from/to active/inactive LRU */
> + bool switching;
> /* the memcg generation this lru_gen_folio belongs to */
> u8 gen;
> /* the list segment this lru_gen_folio belongs to */
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 0fc9373e8251..60fc611067c7 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -5196,6 +5196,7 @@ static void lru_gen_change_state(bool enabled)
> VM_WARN_ON_ONCE(!state_is_valid(lruvec));
>
> lruvec->lrugen.enabled = enabled;
> + smp_store_release(&lruvec->lrugen.switching, true);
Sorry, I actually meant:
+ smp_store_release(&lruvec->lrugen.switching, true);
lruvec->lrugen.enabled = enabled;
But I guess we could still hit a race condition in extreme cases—switching
MGLRU on or off as frequently as possible. The only reliable way is to check
enabled during shrinking while holding the lruvec’s lock.
Thanks
Barry