Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7209700rwd; Mon, 19 Jun 2023 20:36:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4WGXgAXrz8z5XPzAhvbXhgz0cY6w501aWRscMN6dfrL8y/ZRN+nBJCHJKykh0ZJD9Ouy1K X-Received: by 2002:a17:902:ecc8:b0:1b5:561a:5ca9 with SMTP id a8-20020a170902ecc800b001b5561a5ca9mr6010526plh.50.1687232174639; Mon, 19 Jun 2023 20:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687232174; cv=none; d=google.com; s=arc-20160816; b=QhwI6ob1zApUBMPjtirh6f+3JIkwH22vHQk7/iyYxL60C9InkXMPa0RFT+HzySG1Zn evzmc2D7I05/c+5UKWXma0RwJ5X72AKWvmtxYujl+6AlQ9CBDs6ehvEimxd5x2dSRW8O NBqHPfgiF89JIuYszZM0s1xPCjCL878HmpLQ+DGQfWUCmM+orr0T6V2o06/8zPTmV8yP Rxlsp8p6E3GpiKmfnCo+MQckNaMI3DtPTUGCosKvPj2ghFoKSd6mMOhrYgC3h3rBC+5b 9/+RGVPAghV04UNVi9Xnb59Ubg+Y44vg+N3JFDfSmtA2w8wjrgn5KRL5HK5iXV9gEvWC X9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=FWAkX0wvK40L8Asrfp0HwD5G44IXPeP/M4M7zLIxf3U=; b=hzxEnTDqb0myclIoCqocn/EVh4fSc7l0OBlSEvBBziB1fuMS3DRbuyDRMgsszzTwWb LW/HMNsh5GCkBRT4wbDZqfuH0MXkX00AAXhd3jKlbyeBnK3Lf/7SUUnqdFBUhD1tO9+P H9G9NHY/TXbQMgebbK1DzbN6clTKrKDL+Htl6yl7ZWSuD+1yZ0cje8QD06XiP1V0EGEn Z+E4LLMQtE9RIulEW7MYqcdBGtIOR3CciDpIeVcX5odwn8VW6nmq1QMUviyLlNuh+vZ/ 8core0Sh6pu7KVuxNPUsnQuRpdd/1OcVGCyKGQGMCzopbVSSO4JeG+J7XfyPiFxsMvmh bPeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=djRrFrDb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a170902eb8200b001aaf6228a70si1025395plg.325.2023.06.19.20.36.01; Mon, 19 Jun 2023 20:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=djRrFrDb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229454AbjFTDFH (ORCPT + 99 others); Mon, 19 Jun 2023 23:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjFTDFD (ORCPT ); Mon, 19 Jun 2023 23:05:03 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37391E42 for ; Mon, 19 Jun 2023 20:04:37 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-25ea1b6b659so2225460a91.2 for ; Mon, 19 Jun 2023 20:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687230276; x=1689822276; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=FWAkX0wvK40L8Asrfp0HwD5G44IXPeP/M4M7zLIxf3U=; b=djRrFrDbBleVZdWXxrOVE2nAKGvwYAf4SY5iAtcImwDM+I6r6WJcylT6f6OEkUtoBV xgbl/pjdRjjbtHc5UotGCivqqLtUAFWTziJfP4qHWqCtF3SY3KH3HJwKpd1WN5JBEG90 ng3L0GsmDo5iSLEF2nMA4rY9ABP63GvoZFfSCMxckB4194G8VI6P5u4dtP98jj7qLMf2 YzUEmrXwxvwxdwbyzx+rsdyhmdambZrPMuzPZQ5DkaaChocbcjRoKD3NAYMiSqvWhTXT kwwa5Jhcfy1oQ+S8CId5jxKKVoOfz97qM3yf/h8BF4LWcxiXsSjjfx16mVBROj/iokmL 33iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687230276; x=1689822276; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FWAkX0wvK40L8Asrfp0HwD5G44IXPeP/M4M7zLIxf3U=; b=VBbcQ4SzbcwmeMUjKUmmygD5OuJRPWrsgHsBuQuUmXoNYoFNWI01zVSxnmLTvkM3Tq 6w4ed9pPPTRNdDNPu4pUolF/q92VTBxZBviQawy5SY8qdOPW0heQd4SMfNlXwyqjqHPJ IBgHqTKZovoQDTcK9+32729V8at2PAthwE3+pg6HVkUdl78LzH9lEqD6Z07tsn4oog1k STB+fxNVQmBxu4fqUPGoUkNNVfvSc8OgEIszc7ADJqEE7Y0xapF0tUWKB8OJYcYayg3u iLXmKSlz+NFIz1qRM3D2XoG19T4E9kbrqIxK8wUiC3UntqNJtMMMwioQbSM/KwOzxsKV X+hg== X-Gm-Message-State: AC+VfDzSnwtnN5iTZys4+HRy0tQRZTiICvVnXAhW7mhgXmL6PB4pmiL0 e7qcQSKullxlewaIn27GY3Hm3w== X-Received: by 2002:a17:90a:19cb:b0:25e:e211:d300 with SMTP id 11-20020a17090a19cb00b0025ee211d300mr5873247pjj.4.1687230276680; Mon, 19 Jun 2023 20:04:36 -0700 (PDT) Received: from [10.94.58.170] ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id iz7-20020a170902ef8700b001b0603829a0sm457578plb.199.2023.06.19.20.04.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Jun 2023 20:04:35 -0700 (PDT) Message-ID: <6ed78c81-c1ac-dba4-059c-12f6b2bb9c53@bytedance.com> Date: Tue, 20 Jun 2023 11:04:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: Re: [PATCH net-next] inet: Save one atomic op if no memcg to charge Content-Language: en-US To: Eric Dumazet Cc: "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , "open list:NETWORKING [IPv4/IPv6]" , open list References: <20230619082547.73929-1-wuyun.abel@bytedance.com> From: Abel Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/19/23 6:08 PM, Eric Dumazet wrote: > On Mon, Jun 19, 2023 at 10:26 AM Abel Wu 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 >> --- >> 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