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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 20 Jun 2023 11:04:30 +0800
From: Abel Wu <wuyun.abel@...edance.com>
To: Eric Dumazet <edumazet@...gle.com>
Cc: "David S. Miller" <davem@...emloft.net>, David Ahern
 <dsahern@...nel.org>, Jakub Kicinski <kuba@...nel.org>,
 Paolo Abeni <pabeni@...hat.com>,
 "open list:NETWORKING [IPv4/IPv6]" <netdev@...r.kernel.org>,
 open list <linux-kernel@...r.kernel.org>
Subject: Re: Re: [PATCH net-next] inet: Save one atomic op if no memcg to
 charge

On 6/19/23 6:08 PM, Eric Dumazet wrote:
> On Mon, Jun 19, 2023 at 10:26 AM Abel Wu <wuyun.abel@...edance.com> wrote:
>>
>> If there is no net-memcg associated with the sock, don't bother
>> calculating its memory usage for charge.
>>
>> Signed-off-by: Abel Wu <wuyun.abel@...edance.com>
>> ---
>>   net/ipv4/inet_connection_sock.c | 18 +++++++++++-------
>>   1 file changed, 11 insertions(+), 7 deletions(-)
>>
>> diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
>> index 65ad4251f6fd..73798282c1ef 100644
>> --- a/net/ipv4/inet_connection_sock.c
>> +++ b/net/ipv4/inet_connection_sock.c
>> @@ -706,20 +706,24 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
>>   out:
>>          release_sock(sk);
>>          if (newsk && mem_cgroup_sockets_enabled) {
>> -               int amt;
>> +               int amt = 0;
>>
>>                  /* atomically get the memory usage, set and charge the
>>                   * newsk->sk_memcg.
>>                   */
>>                  lock_sock(newsk);
>>
>> -               /* The socket has not been accepted yet, no need to look at
>> -                * newsk->sk_wmem_queued.
>> -                */
>> -               amt = sk_mem_pages(newsk->sk_forward_alloc +
>> -                                  atomic_read(&newsk->sk_rmem_alloc));
>>                  mem_cgroup_sk_alloc(newsk);
>> -               if (newsk->sk_memcg && amt)
>> +               if (newsk->sk_memcg) {
>> +                       /* The socket has not been accepted yet, no need
>> +                        * to look at newsk->sk_wmem_queued.
>> +                        */
>> +                       amt = sk_mem_pages(newsk->sk_forward_alloc +
>> +                                          atomic_read(&newsk->sk_rmem_alloc));
>> +
>> +               }
>> +
>> +               if (amt)
>>                          mem_cgroup_charge_skmem(newsk->sk_memcg, amt,
>>                                                  GFP_KERNEL | __GFP_NOFAIL);
> 
> This looks correct, but claiming reading an atomic_t is an 'atomic op'
> is a bit exaggerated.

Yeah, shall I change subject to 'inet: Skip usage calculation if no
memcg to charge'? Or do you have any suggestions?

Thanks,
	Abel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ