[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAVpQUCCg-7kvzMeSSsKp3+Fu8pvvE5U-H5wkt=xMryNmnF5CA@mail.gmail.com>
Date: Wed, 6 Aug 2025 15:01:44 -0700
From: Kuniyuki Iwashima <kuniyu@...gle.com>
To: Shakeel Butt <shakeel.butt@...ux.dev>
Cc: Daniel Sedlak <daniel.sedlak@...77.com>, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>, Jonathan Corbet <corbet@....net>, Neal Cardwell <ncardwell@...gle.com>,
David Ahern <dsahern@...nel.org>, Andrew Morton <akpm@...ux-foundation.org>,
Yosry Ahmed <yosry.ahmed@...ux.dev>, linux-mm@...ck.org, netdev@...r.kernel.org,
Johannes Weiner <hannes@...xchg.org>, Michal Hocko <mhocko@...nel.org>,
Roman Gushchin <roman.gushchin@...ux.dev>, Muchun Song <muchun.song@...ux.dev>,
cgroups@...r.kernel.org, Tejun Heo <tj@...nel.org>,
Michal Koutný <mkoutny@...e.com>,
Matyas Hurtik <matyas.hurtik@...77.com>
Subject: Re: [PATCH v4] memcg: expose socket memory pressure in a cgroup
On Wed, Aug 6, 2025 at 2:54 PM Shakeel Butt <shakeel.butt@...ux.dev> wrote:
>
> On Wed, Aug 06, 2025 at 12:20:25PM -0700, Kuniyuki Iwashima wrote:
> > > > - WRITE_ONCE(memcg->socket_pressure, jiffies + HZ);
> > > > + socket_pressure = jiffies + HZ;
> > > > +
> > > > + jiffies_diff = min(socket_pressure - READ_ONCE(memcg->socket_pressure), HZ);
> > > > + memcg->socket_pressure_duration += jiffies_to_usecs(jiffies_diff);
> > >
> > > KCSAN will complain about this. I think we can use atomic_long_add() and
> > > don't need the one with strict ordering.
> >
> > Assuming from atomic_ that vmpressure() could be called concurrently
> > for the same memcg, should we protect socket_pressure and duration
> > within the same lock instead of mixing WRITE/READ_ONCE() and
> > atomic? Otherwise jiffies_diff could be incorrect (the error is smaller
> > than HZ though).
> >
>
> Yeah good point. Also this field needs to be hierarchical. So, with lock
> something like following is needed:
>
> if (!spin_trylock(memcg->net_pressure_lock))
> return;
>
> socket_pressure = jiffies + HZ;
> diff = min(socket_pressure - READ_ONCE(memcg->socket_pressure), HZ);
READ_ONCE() should be unnecessary here.
>
> if (diff) {
> WRITE_ONCE(memcg->socket_pressure, socket_pressure);
> // mod_memcg_state(memcg, MEMCG_NET_PRESSURE, diff);
> // OR
> // while (memcg) {
> // memcg->sk_pressure_duration += diff;
> // memcg = parent_mem_cgroup(memcg);
The parents' sk_pressure_duration is not protected by the lock
taken by trylock. Maybe we need another global mutex if we want
the hierarchy ?
> // }
> }
>
> spin_unlock(memcg->net_pressure_lock);
>
> Regarding the hierarchical, we can avoid rstat infra as this code path
> is not really performance critical.
Powered by blists - more mailing lists