mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Abel Wu <wuyun.abel@bytedance.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	David Ahern <dsahern@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"open list:NETWORKING [IPv4/IPv6]" <netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: Re: [PATCH net-next] inet: Save one atomic op if no memcg to charge
Date: Tue, 20 Jun 2023 11:04:30 +0800	[thread overview]
Message-ID: <6ed78c81-c1ac-dba4-059c-12f6b2bb9c53@bytedance.com> (raw)
In-Reply-To: <CANn89i+deprQWB0dmsUD1sRmy1VQCQwKnZUkLu_AEGV=ow=PKQ@mail.gmail.com>

On 6/19/23 6:08 PM, Eric Dumazet wrote:
> On Mon, Jun 19, 2023 at 10:26 AM Abel Wu <wuyun.abel@bytedance.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@bytedance.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

  reply	other threads:[~2023-06-20  3:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-19  8:25 Abel Wu
2023-06-19 10:08 ` Eric Dumazet
2023-06-20  3:04   ` Abel Wu [this message]
2023-06-20  8:46     ` Eric Dumazet
2023-06-20 10:13       ` Abel Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ed78c81-c1ac-dba4-059c-12f6b2bb9c53@bytedance.com \
    --to=wuyun.abel@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®