Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp294353rdb; Thu, 19 Oct 2023 05:01:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgB0L/QVzFlGFFqY+OLcaUONU1+cYLxtEkYe6IHNz6Z6HAYUidDIl7iKhmjH8zmTUrjmLA X-Received: by 2002:a05:6e02:1e0b:b0:34c:e84b:4c5c with SMTP id g11-20020a056e021e0b00b0034ce84b4c5cmr2664316ila.27.1697716891789; Thu, 19 Oct 2023 05:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697716891; cv=none; d=google.com; s=arc-20160816; b=pziwt1HVvPJzIcz0bzWR2lXpVcUdtSZ0ohu+cSnX8W0KvkwI8a+Znxlxnsf1zxRgwC DCHl7d/EVC/Sq5melKXIEj49AwDOwDgJlunegp4LAtSTPcbLegKQ2P8BpVtxUatbb8AP jRUcnVUz4mGheIcDbgNclj0MfPt/m19R3YRRRsoN8rBHiFqyThx5X7vJow5MIwJY7kJL 3A+Pu2XLoIG6JmagmZBDKV4DON2RMOa29JKUoxQBtZIp4yI9jSoT50uPkSTQhTlBFYUo xr1hrW9GnnI6dQ9orX20DyRJ3I4r4WerTrh9fg8KFG/1Tox0Jhi4DZRbRnzpoGDTUmJF a0pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=j1m9BRSdkNRQ5Yt+ICOw8D17wxDsW5CRYVDGGwLbORQ=; fh=NAzjwYjhJuad6Dfdv6L/yFkzoQ/crn31I7NowP28YKE=; b=IKTD2tNerBH4zTcoOnIPd7MwZSHfsJVoiTSBNV1h0JAznGS6etYEUEi8fhmHxisJkq 5r4J7EEz50EkS9UHDRMsGp0MyiemTjfiE54QSp/KLxjiTD+VWc0CQTLVq6AbY7JD/4jG LXR+ueQZu14KVeoKaY1zAfyI4ijaqAW4MTTsTh9V7UVcmBTHbYLRot2wb2qpQggI354X syYFmzCc1kmemMjIXRkTU/hYbczUuCcnQN1YF+GsmAv3x/3+JU0ONwuHrOEUjG/SraBL syXzn1n2QG957F+P+sKSlwZlC7LB2i9WykYE47SWi/oDMG9rxuwetmEfwNnfqcFUTkWh GOlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=bbQ5Rrbx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id m19-20020a656a13000000b00578fcb85b89si4403325pgu.726.2023.10.19.05.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=bbQ5Rrbx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 15E60810CABF; Thu, 19 Oct 2023 05:01:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235333AbjJSMBP (ORCPT + 99 others); Thu, 19 Oct 2023 08:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235309AbjJSMBL (ORCPT ); Thu, 19 Oct 2023 08:01:11 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F274312D for ; Thu, 19 Oct 2023 05:00:46 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c5c91bec75so55633935ad.3 for ; Thu, 19 Oct 2023 05:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1697716846; x=1698321646; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=j1m9BRSdkNRQ5Yt+ICOw8D17wxDsW5CRYVDGGwLbORQ=; b=bbQ5RrbxNDWIPvEhnImaGP7g1m1qLa4QiJU8cEt5/7mEvKzmiHZbKbZkh1haueDNRj XDjxfHZZbNZkoZhT1RBlP63eexVbqlzYMXkcI86yiNtovwx1uNgDZ34eL9fJWTv00YK1 vJwuBiXoYA2a4AUz9LrvAWHfZRe81cu9ZLdud7Cfl0P+QhT6eDAcsUT6rdXAuU9IRd6i o95s5mLYVidS0A67ITr1VM9tHxI601kzx5uRDwHKoyh+zLpbIl2WDaNjtTmJ0XKQ2GgN Pj+0XPZkuprOq7Lwx6IDLTkOjnji48C2qHkyXWkPgbsx13SZOMy9rhVSM9QoWlvvO6D7 U9oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697716846; x=1698321646; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j1m9BRSdkNRQ5Yt+ICOw8D17wxDsW5CRYVDGGwLbORQ=; b=gryLgI89q2+XmMXQPf6YLQnMQOmEmnoMYpeqFMfWbTbQ5rJsaG52yOo9DOsmQPU6kZ loCD/1rxsh+YwRlVQ+5aQJ2256VBXzBCNha+FwGNAgE4hPrLo/UQ7+EmxQQyZYShkSJl OwP2QlJNRmw14auYUOkczbEoHOEpRpcy8fE9oQjjCF8hAx51QT5CqwGDge4KQrEaemlQ tDmChN0J2e2P+gowNoBUFdnxDMYw58JbTolxyKBuCPQomiXMasCADNvy35FYliy6Q3bG YzE2arqz13eLgXpca9TxRusTeQjjPHi7bHepc0VBG6UQ/jnM2crIdXfPf0u4Rq6viM68 1D1Q== X-Gm-Message-State: AOJu0Yw+Dguw2QDi+7JPQzg1u4f4+tJ1wy5HXw5L0G+UF6jp1bUtMETB 2flusH1XTsMdl/fTt6mOK2zyWg== X-Received: by 2002:a17:902:fa45:b0:1ca:3c63:d5cc with SMTP id lb5-20020a170902fa4500b001ca3c63d5ccmr1833983plb.49.1697716846435; Thu, 19 Oct 2023 05:00:46 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id jg9-20020a17090326c900b001c727d3ea6bsm1785646plb.74.2023.10.19.05.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:00:46 -0700 (PDT) From: Abel Wu To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shakeel Butt Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Wu Subject: [PATCH net v3 1/3] sock: Code cleanup on __sk_mem_raise_allocated() Date: Thu, 19 Oct 2023 20:00:24 +0800 Message-Id: <20231019120026.42215-1-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:01:28 -0700 (PDT) Code cleanup for both better simplicity and readability. No functional change intended. Signed-off-by: Abel Wu Acked-by: Shakeel Butt --- net/core/sock.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/net/core/sock.c b/net/core/sock.c index 16584e2dd648..4412c47466a7 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3041,17 +3041,19 @@ EXPORT_SYMBOL(sk_wait_data); */ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) { - bool memcg_charge = mem_cgroup_sockets_enabled && sk->sk_memcg; + struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL; struct proto *prot = sk->sk_prot; - bool charged = true; + bool charged = false; long allocated; sk_memory_allocated_add(sk, amt); allocated = sk_memory_allocated(sk); - if (memcg_charge && - !(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt, - gfp_memcg_charge()))) - goto suppress_allocation; + + if (memcg) { + if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge())) + goto suppress_allocation; + charged = true; + } /* Under limit. */ if (allocated <= sk_prot_mem_limits(sk, 0)) { @@ -3106,8 +3108,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) */ if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) { /* Force charge with __GFP_NOFAIL */ - if (memcg_charge && !charged) { - mem_cgroup_charge_skmem(sk->sk_memcg, amt, + if (memcg && !charged) { + mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge() | __GFP_NOFAIL); } return 1; @@ -3119,8 +3121,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) sk_memory_allocated_sub(sk, amt); - if (memcg_charge && charged) - mem_cgroup_uncharge_skmem(sk->sk_memcg, amt); + if (charged) + mem_cgroup_uncharge_skmem(memcg, amt); return 0; } -- 2.37.3