Re: [PATCH v2 2/5] memcg: force charges from reclaim before trying the limits
From: Muchun Song
Date: Fri Oct 30 2026 - 20:47:02 EST
> On Oct 31, 2026, at 04:54, Shakeel Butt <shakeel.butt@xxxxxxxxx> wrote:
>
> Reclaim can charge memory, for example when zswap stores a page.
> try_charge_memcg() forces these PF_MEMALLOC charges, but only after
> they fail at a limit. A charge that fits still has memory.high
> enforced. That can make a task in direct reclaim do more reclaim and
> sleep longer later, and kswapd records overage that it never handles.
>
> It is also a problem for the next patches, which make kernel threads
> queue high_work. The worker charges memory from its own reclaim, so it
> can queue itself again. With those patches but not this one, the worker
> queued itself in 118 of 284 runs in a VM test with incompressible zswap
> data.
>
> Check PF_MEMALLOC before trying the limits. Reclaim charges then skip
> memory.high, as they can already go over memory.max. Drop the
> PF_MEMALLOC check in memcg_enforce_high(), which no longer sees them.
>
> Other effects:
> - As before, the check reads current, so it also catches interrupts on
> a PF_MEMALLOC task such as kswapd. Softirqs set PF_MEMALLOC
> themselves for swap over network, so the check can't be limited to
> task context.
> - These charges no longer charge a batch or refill the per-cpu stock.
> - MEMCG_MAX still goes to the first cgroup that the charge puts over
> its limit. On cgroup v1, memory.failcnt no longer counts them.
> - high_work can still run again and again when there is nothing left
> to reclaim. This only stops reclaim from queuing more reclaim.
>
> Suggested-by: Michal Hocko <mhocko@xxxxxxxx>
> Signed-off-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>
Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
Thanks.