Re: [PATCH v2 2/5] memcg: force charges from reclaim before trying the limits

From: Michal Hocko

Date: Tue Nov 03 2026 - 03:47:09 EST


On Mon 02-11-26 20:34:40, Shakeel Butt wrote:
> On Mon, Nov 02, 2026 at 09:46:38AM +0100, Michal Hocko wrote:
[...]
> > @@ -2789,6 +2779,15 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,
> > if (do_memsw_account())
> > page_counter_charge(&memcg->memsw, nr_pages);
> >
> > + /*
> > + * If the allocation has to be enforced, don't forget to raise
> > + * a MEMCG_MAX event.
> > + */
> > + for (mem_over_limit = memcg; mem_over_limit;
> > + mem_over_limit = parent_mem_cgroup(mem_over_limit))
> > + if (!mem_cgroup_margin(mem_over_limit))
>
> Second, !mem_cgroup_margin() is true at usage == max, so a charge that fits
> exactly raises an event (unlike today).

True

>
> > + __memcg_memory_event(mem_over_limit, MEMCG_MAX, allow_spinning);
>
> Third, we definitely need a break here otherwise every ancestor at its limit gets
> an event which does not happen today.

This is a separate thing but shouldn't we actually raise the event on
all levels that are over?

> I want to keep my current version.

OK, fair enough. My intention was to have those two parts closer
together but this is not something I would insist.

Acked-by: Michal Hocko <mhocko@xxxxxxx>
Thanks!

--
Michal Hocko
SUSE Labs