[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <nju55eqv56g6gkmxuavc2z2pcr26qhpmgrt76jt5dte5g4trxs@tjxld2iwdc5c>
Date: Wed, 6 Aug 2025 14:54:37 -0700
From: Shakeel Butt <shakeel.butt@...ux.dev>
To: Kuniyuki Iwashima <kuniyu@...gle.com>
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 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);
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);
// }
}
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