lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0f6a8c37-95e0-4009-a13b-99ce0e25ea47@cdn77.com>
Date: Thu, 7 Aug 2025 12:22:01 +0200
From: Daniel Sedlak <daniel.sedlak@...77.com>
To: Shakeel Butt <shakeel.butt@...ux.dev>,
 Kuniyuki Iwashima <kuniyu@...gle.com>
Cc: "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 8/7/25 1:34 AM, Shakeel Butt wrote:
> On Wed, Aug 06, 2025 at 03:01:44PM -0700, Kuniyuki Iwashima wrote:
>> 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.

Thanks for the KCSAN recommendation, I didn't know about this sanitizer.

>>>>
>>>> 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:

Thanks for the snippet, will incorporate it.

>>>
>>>          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 ?
> 
> We don't really need lock protection for sk_pressure_duration. The lock

By this you mean that we don't need the possible new global lock or the 
local memcg->net_pressure_lock?

> is only giving us consistent value of diff. Once we have computed the
> diff, we can add it to sk_pressure_duration of a memcg and all of its
> ancestor without lock.

Thanks!
Daniel


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ