Re: [PATCH v2] mm: memcg: use rstat for non-hierarchical stats

From: Yosry Ahmed
Date: Wed Jul 26 2023 - 11:16:00 EST


On Wed, Jul 26, 2023 at 8:13 AM Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
>
> On Tue, Jul 25, 2023 at 05:36:45PM -0700, Yosry Ahmed wrote:
> > On Tue, Jul 25, 2023 at 5:29 PM Yosry Ahmed <yosryahmed@xxxxxxxxxx> wrote:
> > > - Fix a subtle bug where updating a local counter would be missed if it
> > > was cancelled out by a pending update from child memcgs.
> >
> >
> > Johannes, I fixed a subtle bug here and I kept your Ack, I wasn't sure
> > what the Ack retention policy should be here. A quick look at the fix
> > would be great.
>
> Ah, I found it:
>
> > > @@ -5542,19 +5539,23 @@ static void mem_cgroup_css_rstat_flush(struct cgroup_subsys_state *css, int cpu)
> > > memcg->vmstats->state_pending[i] = 0;
> > >
> > > /* Add CPU changes on this level since the last flush */
> > > + delta_cpu = 0;
> > > v = READ_ONCE(statc->state[i]);
> > > if (v != statc->state_prev[i]) {
> > > - delta += v - statc->state_prev[i];
> > > + delta_cpu = v - statc->state_prev[i];
> > > + delta += delta_cpu;
> > > statc->state_prev[i] = v;
> > > }
> > >
> > > - if (!delta)
> > > - continue;
> > > -
> > > /* Aggregate counts on this level and propagate upwards */
> > > - memcg->vmstats->state[i] += delta;
> > > - if (parent)
> > > - parent->vmstats->state_pending[i] += delta;
> > > + if (delta_cpu)
> > > + memcg->vmstats->state_local[i] += delta_cpu;
>
> When delta nulls out, but delta_cpu is non-zero... subtle.

Yup, led to a few missed updates, was not trivial to track down :)

>
> This fixed version looks good, please keep my ack :)

Thanks!