From patchwork Mon Apr 29 13:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13646986 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F10071B47 for ; Mon, 29 Apr 2024 13:40:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398031; cv=none; b=ErE4k72UwXIiMNNR77u+ays7hIKQylJTLralhUv7n5UePST+YzjzxZNc2akjckmK1ZCNCz90Ww9C+eP1sjbJrM20NqxERx1WoHPZ7K+NvXAZzjjN6Yn9CCtm0I7uqXzakfBiw5sT8tsWssYiggUe8m2JE9G8xGmYs3FGTyiYnKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398031; c=relaxed/simple; bh=4LwSGpsH4EVfi88dCSIGFVdR/ciAyCPoiIpnaatD3DY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Fuulo3Zzhd9JkyfbwoJI7SAo6KB1C8i+ydBYwQ1yZkO2XiIqgf39e+Haa4x7VDiWFSv5A5Osa/L6zFq70R2lw/D0GHPZE54hxI2FQqH53RtfNdGYYWIEthDQW4nQN/ztND5iBqzeefXTqjUBpWKGswk10EHftSnKahNBodnIAbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=13a2OFxV; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="13a2OFxV" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61b1200cc92so86996517b3.0 for ; Mon, 29 Apr 2024 06:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714398029; x=1715002829; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=weBRy1mL/8+GKOw1EeGuZyc7Rd3303raB1gmLNP7l4I=; b=13a2OFxVz2NysHFBKkboQ899Kk/AWThk3nzXgk+6mc5FO0XzQC/4iUQv1Y+JQHPmN/ hAkt5eZyalG55ZWPBDp57ZzWIVdU8Km2S0768h5BgzGrVgppL1i2a4B99qCqhCAkyy3L d5Kn0fFenAI0zHJcXdzM1s1kYP3VDZluOuPbmfbTFfeTK7yDuENg9cI67H9/NHWE8teK eThOvrvfppnYsKROaZgKL2qnEZ6ak1gDWfCvGChaPRoHC1xw4fa6Ak91SixGRFmbUXPW nkyQmZvRfMOVFMogBmYXckNQewDpibNw+EwVaDJuejJ9HHNBq6Ay1AhJ8+/ihNMS5Pq2 IuTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714398029; x=1715002829; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=weBRy1mL/8+GKOw1EeGuZyc7Rd3303raB1gmLNP7l4I=; b=mHI1CucIiPCdRVhYKUr/eSIDm6N9zScj8gjrffa9FBOyOIiO/CRTPVOTp9QelS1BXO hCBugHbWJzTT186+3M7dUb4RuOY5njdVo11eXpxUW2Mqyj3mgUuPBq0UJjWKFk3ZIwoD qUhHXrXrxh3/AjJfNznVnl01MhaXxt7u2E8U2Cl41vINAYTxq3XEp/+VPy5aNbM55iCr ec8fj1NTn2/EhJDKkusBIIjkjXTcknDXvA01TEPab0u201Evk1dxm/Nqsir8aK3tP8x3 w0NRooK8RxhmPPfTSRZPjZ8lUU20nWD0KCNI8VLVsTbfLOROgB1xMjJ7tnU3ru3C03eW i9gw== X-Gm-Message-State: AOJu0YwvHIJvLmQaKcx05ezJPM4xlKQVXmuyPcwkcxuZu8S7TU/BqETK Ff8kFjB2zO9ZdA+s/IlnEzJ0MDlH7jasmTkzYfSQzki+I9uCXDigBpjX45F9hjGrJMymsSbZeX1 5xoqTVD+whg== X-Google-Smtp-Source: AGHT+IHfKV7hk/R2IvzKcS4G7q3acN6BGYX/03MgQtzBGa0064hquhKM7S6EzLhXwHtMzn3NTD5FivpRSiz3Dg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:c0b:b0:de5:1e69:6447 with SMTP id fs11-20020a0569020c0b00b00de51e696447mr3381435ybb.6.1714398029007; Mon, 29 Apr 2024 06:40:29 -0700 (PDT) Date: Mon, 29 Apr 2024 13:40:21 +0000 In-Reply-To: <20240429134025.1233626-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429134025.1233626-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240429134025.1233626-2-edumazet@google.com> Subject: [PATCH net-next 1/5] net: move sysctl_max_skb_frags to net_hotdata From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org sysctl_max_skb_frags is used in TCP and MPTCP fast paths, move it to net_hodata for better cache locality. Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 2 -- include/net/hotdata.h | 1 + net/core/hotdata.c | 1 + net/core/skbuff.c | 5 +---- net/core/sysctl_net_core.c | 2 +- net/ipv4/tcp.c | 3 ++- net/mptcp/protocol.c | 3 ++- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index f76825e5b92a334f7726d7f7c99aa60ec69a8e07..4f99a39db2eb2868d9a14334070d4a574ba1f9a3 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -353,8 +353,6 @@ struct sk_buff; #define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS -extern int sysctl_max_skb_frags; - /* Set skb_shinfo(skb)->gso_size to this in case you want skb_segment to * segment using its current segmentation instead. */ diff --git a/include/net/hotdata.h b/include/net/hotdata.h index 003667a1efd6b63fc0f0d7cadd2c8472281331b0..a6cff65904267f338fbd258d23be79d46a062f9e 100644 --- a/include/net/hotdata.h +++ b/include/net/hotdata.h @@ -38,6 +38,7 @@ struct net_hotdata { int max_backlog; int dev_tx_weight; int dev_rx_weight; + int sysctl_max_skb_frags; }; #define inet_ehash_secret net_hotdata.tcp_protocol.secret diff --git a/net/core/hotdata.c b/net/core/hotdata.c index c8a7a451c18a383d091e413a510d84d163473f2f..f17cbb4807b99937b272be12953f790c66cc2cd1 100644 --- a/net/core/hotdata.c +++ b/net/core/hotdata.c @@ -18,5 +18,6 @@ struct net_hotdata net_hotdata __cacheline_aligned = { .max_backlog = 1000, .dev_tx_weight = 64, .dev_rx_weight = 64, + .sysctl_max_skb_frags = MAX_SKB_FRAGS, }; EXPORT_SYMBOL(net_hotdata); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 0c8b82750000f63b097cb4b7b990c647c81019df..65779b8f0b126a1c039cf24a47474c0cb80ff6ae 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -109,9 +109,6 @@ static struct kmem_cache *skbuff_ext_cache __ro_after_init; #define SKB_SMALL_HEAD_HEADROOM \ SKB_WITH_OVERHEAD(SKB_SMALL_HEAD_CACHE_SIZE) -int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS; -EXPORT_SYMBOL(sysctl_max_skb_frags); - /* kcm_write_msgs() relies on casting paged frags to bio_vec to use * iov_iter_bvec(). These static asserts ensure the cast is valid is long as the * netmem is a page. @@ -7040,7 +7037,7 @@ static void skb_splice_csum_page(struct sk_buff *skb, struct page *page, ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, ssize_t maxsize, gfp_t gfp) { - size_t frag_limit = READ_ONCE(sysctl_max_skb_frags); + size_t frag_limit = READ_ONCE(net_hotdata.sysctl_max_skb_frags); struct page *pages[8], **ppages = pages; ssize_t spliced = 0, ret = 0; unsigned int i; diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 903ab4a51c178a4705b7eb610958c81c5ebcfdf5..e75375d54b9e50673af28f6d6b3bb83fc74cb1f8 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -595,7 +595,7 @@ static struct ctl_table net_core_table[] = { }, { .procname = "max_skb_frags", - .data = &sysctl_max_skb_frags, + .data = &net_hotdata.sysctl_max_skb_frags, .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_minmax, diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 4ec0f4feee003d91fa5ae37ed4dd50e09c4c874a..388f6e115bf168e6f70b762096a984a2cacfa5c9 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -280,6 +280,7 @@ #include #include #include +#include #include /* Track pending CMSGs. */ @@ -1188,7 +1189,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) if (!skb_can_coalesce(skb, i, pfrag->page, pfrag->offset)) { - if (i >= READ_ONCE(sysctl_max_skb_frags)) { + if (i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) { tcp_mark_push(tp, skb); goto new_segment; } diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 4b13ca362efa395a2ef7a92e553a8c49feebec79..aff17597e6a71ecc4b9aef4d02f039318fa1fe7f 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -20,6 +20,7 @@ #include #endif #include +#include #include #include #include "protocol.h" @@ -1272,7 +1273,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, i = skb_shinfo(skb)->nr_frags; can_coalesce = skb_can_coalesce(skb, i, dfrag->page, offset); - if (!can_coalesce && i >= READ_ONCE(sysctl_max_skb_frags)) { + if (!can_coalesce && i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) { tcp_mark_push(tcp_sk(ssk), skb); goto alloc_skb; } From patchwork Mon Apr 29 13:40:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13646987 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DDD174404 for ; Mon, 29 Apr 2024 13:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398033; cv=none; b=Zos3PYDZlmJY/HTxkH/30dI9PK77hTrF4fdu1lpRLEA7kEgRkn7Ndp7I8j0fspvyQN7kFsElmydysAAFXleMXbA7eZX812R4VfSMz2HxZq6BPjNxChvTkuV1uuncq8i0Zki25Jhapd1q53q2RstKlARK4m4Ye/qG5Znqw8tgZzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398033; c=relaxed/simple; bh=CKyRb0jRgbcMZjZuRKL4Xo1l1UZfaQnuMg8GDrAD7bk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q+KnJErlwj9xEKyd3RQOoKtGc2k05CGp+djsF9uL5NQzbPkWOE+tbRsKQ5Lpe7YizCpadvfTpWh7xcsoYBKnKjpYiOz+lFXLYX579WnjswbLks/f3bgiuGtIpS2tSVcXvhE4wu8CfnzUtfzNnhKNUdJuOMgzjg3U68eIm4n3gZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JNW098sd; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JNW098sd" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de45c577ca9so6630984276.0 for ; Mon, 29 Apr 2024 06:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714398030; x=1715002830; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BamTd/jje90Vv3sMBUF4Hr/QM7nsdp+JZ7ooDodhurU=; b=JNW098sdRw6AdAAJBwKSEsPneKRzYTGMfCB2iwNxzdaiX0BDQBaNEEzwxQsYXkUuy4 v6kUm6uOyv+7L4K9gVQxnsU5LFXzEbGVZwoOzw9AJCUaedHPMZLPJsvtMpbRz11Bn1wt 5WuaF9dyLjvU45yHRT4cuxeypsmbhAhDXgYZoC+1+1E0xYNuHVhGutCfDEaNx1qcXfOF o2Vtnusu/BAeHq0z5Wm3aabUEGK87gseHruAaIsi7Are8vJDA3h00qx11ZdygeQ02Wxv lFCRWBfzBwcyKEdGHDz7TrST1n0o5EA5P1WjgAC9fs6wuePL4wqWYnVaDSVCqTt0BYJG qGCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714398030; x=1715002830; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BamTd/jje90Vv3sMBUF4Hr/QM7nsdp+JZ7ooDodhurU=; b=q4tVZlUeV6QqDh9X1sDxNwolXvzVZuqqer8NmpPRSj/rYlnqu7rGdU877FWu6eun7T 1PC7v2VtMQVgrGIVpCFyJQRItkeI4c7e6GBUA7zN6DkELAM6DU5onWILcizl2uBrZ79F 6hgu2mNZRr6BkdoYGHFR6HRxGynVQI4RKH0EzqK7c7UC4LvukQ+JK+iy3cKu+d0lQAO4 ZRPO/r8MX+BzbSYxbFRFkgU61VA5/yjLwKK1BtQp8n3lYP/06NnegUYL7CPlGV4v0mCl 4W+l1X3bu+hI2dY4mNbxHLbGoguZg1DcRhH4mkAGlZ7j3K3W3SKZG2twczaAxbM9SxPp loNg== X-Gm-Message-State: AOJu0Yz5a9Lx6DuIgQnuQknBcTrpzTMLvrxH1zl/rsy6ECRW9FsatK3o R06BVekXO+yvSVKmBvdEQT7knbdrgh+X8tU7vBaQPw0CyMxWhgzBXQkpaGNNVfsa5uYSzh2N/d2 MbQvGOT5YWg== X-Google-Smtp-Source: AGHT+IFrkFK8wRzbA1m7Z2shwn6mczSz/NG0IlBSxoC5lwg2ecBzfKKPCRcZi4UWxm/R+Hh84K7Tye4BKSxD5w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d850:0:b0:de5:dcb8:5c8a with SMTP id p77-20020a25d850000000b00de5dcb85c8amr1309356ybg.2.1714398030620; Mon, 29 Apr 2024 06:40:30 -0700 (PDT) Date: Mon, 29 Apr 2024 13:40:22 +0000 In-Reply-To: <20240429134025.1233626-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429134025.1233626-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240429134025.1233626-3-edumazet@google.com> Subject: [PATCH net-next 2/5] net: move sysctl_skb_defer_max to net_hotdata From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org sysctl_skb_defer_max is used in TCP fast path, move it to net_hodata. Signed-off-by: Eric Dumazet --- include/net/hotdata.h | 1 + net/core/dev.c | 1 - net/core/dev.h | 1 - net/core/hotdata.c | 1 + net/core/skbuff.c | 2 +- net/core/sysctl_net_core.c | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/net/hotdata.h b/include/net/hotdata.h index a6cff65904267f338fbd258d23be79d46a062f9e..290499f72e18d45a8ed7bd9e8880a51f7ef2b94c 100644 --- a/include/net/hotdata.h +++ b/include/net/hotdata.h @@ -39,6 +39,7 @@ struct net_hotdata { int dev_tx_weight; int dev_rx_weight; int sysctl_max_skb_frags; + int sysctl_skb_defer_max; }; #define inet_ehash_secret net_hotdata.tcp_protocol.secret diff --git a/net/core/dev.c b/net/core/dev.c index c9e59eff8ec841f6267c2749489fdc7fe0d03430..cd7ba50eac15341c1d3a2136f8b4a3584d5c2669 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4450,7 +4450,6 @@ EXPORT_SYMBOL(__dev_direct_xmit); *************************************************************************/ static DEFINE_PER_CPU(struct task_struct *, backlog_napi); -unsigned int sysctl_skb_defer_max __read_mostly = 64; int weight_p __read_mostly = 64; /* old backlog weight */ int dev_weight_rx_bias __read_mostly = 1; /* bias for backlog weight */ int dev_weight_tx_bias __read_mostly = 1; /* bias for output_queue quota */ diff --git a/net/core/dev.h b/net/core/dev.h index 8572d2c8dc4adce75c98868c888363e6a32e0f52..b7b518bc2be55aa42847fee3f21749a658d97f35 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -36,7 +36,6 @@ int dev_addr_init(struct net_device *dev); void dev_addr_check(struct net_device *dev); /* sysctls not referred to from outside net/core/ */ -extern unsigned int sysctl_skb_defer_max; extern int netdev_unregister_timeout_secs; extern int weight_p; extern int dev_weight_rx_bias; diff --git a/net/core/hotdata.c b/net/core/hotdata.c index f17cbb4807b99937b272be12953f790c66cc2cd1..a359ff160d54ad379eac7e56e1810a7e840f9275 100644 --- a/net/core/hotdata.c +++ b/net/core/hotdata.c @@ -19,5 +19,6 @@ struct net_hotdata net_hotdata __cacheline_aligned = { .dev_tx_weight = 64, .dev_rx_weight = 64, .sysctl_max_skb_frags = MAX_SKB_FRAGS, + .sysctl_skb_defer_max = 64, }; EXPORT_SYMBOL(net_hotdata); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 65779b8f0b126a1c039cf24a47474c0cb80ff6ae..5f382e94b4d1d2a1913867f28c639881fce962c0 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6985,7 +6985,7 @@ nodefer: kfree_skb_napi_cache(skb); DEBUG_NET_WARN_ON_ONCE(skb->destructor); sd = &per_cpu(softnet_data, cpu); - defer_max = READ_ONCE(sysctl_skb_defer_max); + defer_max = READ_ONCE(net_hotdata.sysctl_skb_defer_max); if (READ_ONCE(sd->defer_count) >= defer_max) goto nodefer; diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index e75375d54b9e50673af28f6d6b3bb83fc74cb1f8..118c78615543852eabd3067bbb7920418b7da7b3 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -654,7 +654,7 @@ static struct ctl_table net_core_table[] = { }, { .procname = "skb_defer_max", - .data = &sysctl_skb_defer_max, + .data = &net_hotdata.sysctl_skb_defer_max, .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_dointvec_minmax, From patchwork Mon Apr 29 13:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13646988 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0499745E5 for ; Mon, 29 Apr 2024 13:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398034; cv=none; b=lKQt1lj8w8kOlmfoXUHJ89g2uwK2Y1ruBGoCftNo9Rq9L/DpUdDXgpsPUhO7t5qwNKWfondo940SuwWPGkrIMrVpx7EjfoAIi4RSGjLUUcXOPTmmbf+vfCCisa5tA92h5Vc3LGnMeqJg+2HJreDIE302WUJvwyomPnOQz2PKkRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398034; c=relaxed/simple; bh=7pV90Q5Ihi9rLSac7cbe5iS2rypHyXNXcMjhPs3Rg7g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PixnZr2QqIGxQWNKN3Mmy+lOB8Zxr9ww4OdcHZMqRoO9MGMtUXX12Gtta9NRJhiW69xLv+e0R8KRFU7PPiB0ysDBQFyV13ST6QJtPu4NBkr9u0yq+kZ9Syq59d/Cnh+/px2W0XLfmExNsWWkQjomftLeR9tEeNYPS8nXCK+/biY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AJisP3TL; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AJisP3TL" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b269686aso7467499276.1 for ; Mon, 29 Apr 2024 06:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714398032; x=1715002832; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fSlmQg4KJrc53W+wqm3ZW/aeFGj8jFIF2sA21GFh/RU=; b=AJisP3TLO81IiTACvbC29FKcrvj5NwjvUfFneimvRNtvcmRVV0fcsd8TINLvuHj5lC qyEvyInGor9Zr0H5u1gelqqZPB2Shs0vSR1yD9FCXYQv+yUGWkSRRFhzV6btCScdBPAa 5di8Kq2431cj3j/JrmCyHXutar24N9auIrK8G4fuo+vSEaZR+y65Vc4Oi4PsTkEqh7wZ P51lkQHko76l50o9YPTdT2Y8+Gs9SCgS8yse8PBDIl04T5qkNtC8v85qiilLZI6roBbG MqJjSQmMBaz2Aegkl8U8ok74oL/emnjYm+AoHtvJ/7n/0YuTj0c6SnCy4jqOsDs7kO2S FQJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714398032; x=1715002832; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fSlmQg4KJrc53W+wqm3ZW/aeFGj8jFIF2sA21GFh/RU=; b=Ll4VNmzOBEzg3U489yzC9UVOnGUYUqrC47sqZCO9VMh2uJdXB2vnxe0kiLB0+Cu4Vi Yv10nmKao3j9zg3Fzf5r7AjOuVAEIqFBBC8JVoByhs4xLxLZMMqmARVzwfrfUVEHfKYY IBeS7pjWFE/h9KqRE+3tbRlKYkjFB/gUv8GHbtQ/tDPTpEHTaDn1b4ULYw266B3e1tGv J60m/+7qM5NO9PIRvvwC7d31xI/G5ZVmuwkXGkhL2Gf0Ey1vdBPqRK9n0D9skh9993lc 7UGwg/EOW1SffzKABogRAFN8FreyiuM956ymc+mNcLYrm3V2ebilKHp5yIRvybdg2CFW LcuA== X-Gm-Message-State: AOJu0Yw/1Bgh7Ae5owaKmDrWgHiySngHr96rulSKyWkBFvVxifcedDEM 5rKSUZwD2NfVM33YNQdnPp+TNie4wSXVsSJX41R3NHIPokNIFnScLtGW7HlUC5Ar1qPVDGUTsDw WpXSruDhKIg== X-Google-Smtp-Source: AGHT+IEYOhc3vHQS7/QV+Kpdv3JY9wgjOz9vfdDGJfHGkjqzRTEojIeYxV/Mghn10wQanTNEEcEgygq/OULPiw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:703:b0:de4:c681:ca96 with SMTP id k3-20020a056902070300b00de4c681ca96mr671511ybt.2.1714398032004; Mon, 29 Apr 2024 06:40:32 -0700 (PDT) Date: Mon, 29 Apr 2024 13:40:23 +0000 In-Reply-To: <20240429134025.1233626-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429134025.1233626-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240429134025.1233626-4-edumazet@google.com> Subject: [PATCH net-next 3/5] tcp: move tcp_out_of_memory() to net/ipv4/tcp.c From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org tcp_out_of_memory() has a single caller: tcp_check_oom(). Following patch will also make sk_memory_allocated() not anymore visible from and Add const qualifier to sock argument of tcp_out_of_memory() and tcp_check_oom(). Signed-off-by: Eric Dumazet --- include/net/tcp.h | 10 +--------- net/ipv4/tcp.c | 10 +++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index a9eb21251195c3707c892247bfba5b430e7bc1bb..39e36b9a5f1c11462b0ff01a2de7b08ee0fb9258 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -296,14 +296,6 @@ static inline bool between(__u32 seq1, __u32 seq2, __u32 seq3) return seq3 - seq2 >= seq1 - seq2; } -static inline bool tcp_out_of_memory(struct sock *sk) -{ - if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && - sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) - return true; - return false; -} - static inline void tcp_wmem_free_skb(struct sock *sk, struct sk_buff *skb) { sk_wmem_queued_add(sk, -skb->truesize); @@ -316,7 +308,7 @@ static inline void tcp_wmem_free_skb(struct sock *sk, struct sk_buff *skb) void sk_forced_mem_schedule(struct sock *sk, int size); -bool tcp_check_oom(struct sock *sk, int shift); +bool tcp_check_oom(const struct sock *sk, int shift); extern struct proto tcp_prot; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 388f6e115bf168e6f70b762096a984a2cacfa5c9..0a3aa30470837f27d7db1a0328228b2e3323bad0 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2752,7 +2752,15 @@ static bool tcp_too_many_orphans(int shift) READ_ONCE(sysctl_tcp_max_orphans); } -bool tcp_check_oom(struct sock *sk, int shift) +static bool tcp_out_of_memory(const struct sock *sk) +{ + if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && + sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) + return true; + return false; +} + +bool tcp_check_oom(const struct sock *sk, int shift) { bool too_many_orphans, out_of_socket_memory; From patchwork Mon Apr 29 13:40:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13646989 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C020974E09 for ; Mon, 29 Apr 2024 13:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398036; cv=none; b=Wai7vB24pbyD6F8ryYaR+iOgAUsBVG4dw1IJbZM8tB1YggOEpz9c5FbXjBC447Q3tJWoDbYV8cqL0L/DydHpKU5tkWVwR0Nlsi9ARKl3Dih3p2kq18bUT8vLvqmYRNGSBy6fSCzIS8AeIZACD9cUeF0SIyyuZHPlZhiKaH20uos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398036; c=relaxed/simple; bh=fIg0MfMNwSDO3L4o+Zp7tqwRu1d68+eflAMmSm1udvc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A9r+6BLeZbQwcLtjqaQpCYMBKBxmC2u5GMncrjGlTezNxxi6w2XkL4AK526t3YW+r92iDRCaFXMJoJsuaifMQSDef0dXLv+oJgS8LIXDvwZmnpHD3M+k8a+uuo8T6aRnq0yvA+GqNdL6RgfK+bT6VAAB1w9n9E6aJsSJs7MZS1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kq/I+IBJ; arc=none smtp.client-ip=209.85.222.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kq/I+IBJ" Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-790f62a7046so138688485a.1 for ; Mon, 29 Apr 2024 06:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714398033; x=1715002833; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oEFKwFXVmCaTrrUiwMT40XJKqg5rhAiy1a8h28o2bEs=; b=kq/I+IBJ5qTfcHPJhcKVbMXYjAvh9k3wNcoMDa4cv08KEaRbGC+Tgg98M1mhz52pdM 3eLYB1NbYprJNqvICGDerNX0bMK7ArwUW6Istl+Bp6fuR4vj9OtUcq9UHQKj+FyoGgMD zPj4x8S3I69AO4wPqIQi3QiBhXgM7ZwCBZKT7KzYA+Zuz596mrcmrGpwvvxTDmWj2Hq1 7OLpMbIeQJgDhrcOqOnTvBIdvCvcXWXqm6hBzvhqbsqzQpufB5up15GnWoyO493UKmO2 OOJgaV09X++ZQ+uK5qTtwlXNGKkSIHbUYkrT12BSDODBFtmygmooIbCQkSH3O9fzBbfd RSyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714398033; x=1715002833; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oEFKwFXVmCaTrrUiwMT40XJKqg5rhAiy1a8h28o2bEs=; b=CA2WnPzgvcwgBePNS9u0gpYbi5o9Ry5IbRGZBK/SeJoFk1q2SJ7/pqg8M2QOAsclbU c/Y46S+Q1lo9wH/nKyEoDemufDbobASCQF+aG+Rm4H/pWvEXU0uLAI6ck77+uHcQGA96 Gtg/oyVXgzTpRoXubp76VINz4sBRz5EzIH6HPfGJxDZ+0QfsjvHj29XmSfTsrc35bfsJ lyiKaDUy8mXp82rJKMeOZEiHiX+CPU02+9OJs0Lct3aB6XQ80xI5bX+XuzKEo5ru/VpO 77j/Lo/gjqbvdlXxD+5s1mj8cAnpnAf6nqWWiF2OqfI5TrZVfAi6fmMu3/epQXjJ+Up6 pwnA== X-Gm-Message-State: AOJu0YxIgPKvtxyz4/cuKz9X4fQu4hqTb4mcO48iIdteL+2WUf7IrtX6 0IJZEv1lj/03Qjam6qznM6+9HWDK2dx+v/bk38Z2nLHejJEY7Vo0ewwm5lauob1JZkfxfWbHDqQ RVq74tHkguQ== X-Google-Smtp-Source: AGHT+IFFTPe6n/49nVFY1ot7UhlNY4ksxPgiKzMWJr8uSMEmFHYJvkWgC9U+lyNFGDXgHbjVuedsF4sIjvwl0g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:620a:672:b0:790:c7f8:76c8 with SMTP id a18-20020a05620a067200b00790c7f876c8mr20630qkh.2.1714398033755; Mon, 29 Apr 2024 06:40:33 -0700 (PDT) Date: Mon, 29 Apr 2024 13:40:24 +0000 In-Reply-To: <20240429134025.1233626-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429134025.1233626-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240429134025.1233626-5-edumazet@google.com> Subject: [PATCH net-next 4/5] net: add From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Move some proto memory definitions out of Very few files need them, and following patch will include from Signed-off-by: Eric Dumazet --- include/net/proto_memory.h | 83 ++++++++++++++++++++++++++++++++++++++ include/net/sock.h | 78 ----------------------------------- net/core/sock.c | 1 + net/core/sysctl_net_core.c | 1 + net/ipv4/proc.c | 1 + net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 1 + net/ipv4/tcp_output.c | 1 + net/sctp/sm_statefuns.c | 1 + 9 files changed, 90 insertions(+), 78 deletions(-) create mode 100644 include/net/proto_memory.h diff --git a/include/net/proto_memory.h b/include/net/proto_memory.h new file mode 100644 index 0000000000000000000000000000000000000000..41404d4bb6f08e84030838f0e63ef240587f65dd --- /dev/null +++ b/include/net/proto_memory.h @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _PROTO_MEMORY_H +#define _PROTO_MEMORY_H + +#include + +/* 1 MB per cpu, in page units */ +#define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT)) +extern int sysctl_mem_pcpu_rsv; + +static inline bool sk_has_memory_pressure(const struct sock *sk) +{ + return sk->sk_prot->memory_pressure != NULL; +} + +static inline bool +proto_memory_pressure(const struct proto *prot) +{ + if (!prot->memory_pressure) + return false; + return !!READ_ONCE(*prot->memory_pressure); +} + +static inline bool sk_under_global_memory_pressure(const struct sock *sk) +{ + return proto_memory_pressure(sk->sk_prot); +} + +static inline bool sk_under_memory_pressure(const struct sock *sk) +{ + if (!sk->sk_prot->memory_pressure) + return false; + + if (mem_cgroup_sockets_enabled && sk->sk_memcg && + mem_cgroup_under_socket_pressure(sk->sk_memcg)) + return true; + + return !!READ_ONCE(*sk->sk_prot->memory_pressure); +} + +static inline long +proto_memory_allocated(const struct proto *prot) +{ + return max(0L, atomic_long_read(prot->memory_allocated)); +} + +static inline long +sk_memory_allocated(const struct sock *sk) +{ + return proto_memory_allocated(sk->sk_prot); +} + +static inline void proto_memory_pcpu_drain(struct proto *proto) +{ + int val = this_cpu_xchg(*proto->per_cpu_fw_alloc, 0); + + if (val) + atomic_long_add(val, proto->memory_allocated); +} + +static inline void +sk_memory_allocated_add(const struct sock *sk, int val) +{ + struct proto *proto = sk->sk_prot; + + val = this_cpu_add_return(*proto->per_cpu_fw_alloc, val); + + if (unlikely(val >= READ_ONCE(sysctl_mem_pcpu_rsv))) + proto_memory_pcpu_drain(proto); +} + +static inline void +sk_memory_allocated_sub(const struct sock *sk, int val) +{ + struct proto *proto = sk->sk_prot; + + val = this_cpu_sub_return(*proto->per_cpu_fw_alloc, val); + + if (unlikely(val <= -READ_ONCE(sysctl_mem_pcpu_rsv))) + proto_memory_pcpu_drain(proto); +} + +#endif /* _PROTO_MEMORY_H */ diff --git a/include/net/sock.h b/include/net/sock.h index 48bcc845202f283c258803c7d35fb2b9a0fd6fe7..0450494a1766a0136fa7b446e63c7357afd4a6e6 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1371,75 +1371,6 @@ static inline int sk_under_cgroup_hierarchy(struct sock *sk, #endif } -static inline bool sk_has_memory_pressure(const struct sock *sk) -{ - return sk->sk_prot->memory_pressure != NULL; -} - -static inline bool sk_under_global_memory_pressure(const struct sock *sk) -{ - return sk->sk_prot->memory_pressure && - !!READ_ONCE(*sk->sk_prot->memory_pressure); -} - -static inline bool sk_under_memory_pressure(const struct sock *sk) -{ - if (!sk->sk_prot->memory_pressure) - return false; - - if (mem_cgroup_sockets_enabled && sk->sk_memcg && - mem_cgroup_under_socket_pressure(sk->sk_memcg)) - return true; - - return !!READ_ONCE(*sk->sk_prot->memory_pressure); -} - -static inline long -proto_memory_allocated(const struct proto *prot) -{ - return max(0L, atomic_long_read(prot->memory_allocated)); -} - -static inline long -sk_memory_allocated(const struct sock *sk) -{ - return proto_memory_allocated(sk->sk_prot); -} - -/* 1 MB per cpu, in page units */ -#define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT)) -extern int sysctl_mem_pcpu_rsv; - -static inline void proto_memory_pcpu_drain(struct proto *proto) -{ - int val = this_cpu_xchg(*proto->per_cpu_fw_alloc, 0); - - if (val) - atomic_long_add(val, proto->memory_allocated); -} - -static inline void -sk_memory_allocated_add(const struct sock *sk, int val) -{ - struct proto *proto = sk->sk_prot; - - val = this_cpu_add_return(*proto->per_cpu_fw_alloc, val); - - if (unlikely(val >= READ_ONCE(sysctl_mem_pcpu_rsv))) - proto_memory_pcpu_drain(proto); -} - -static inline void -sk_memory_allocated_sub(const struct sock *sk, int val) -{ - struct proto *proto = sk->sk_prot; - - val = this_cpu_sub_return(*proto->per_cpu_fw_alloc, val); - - if (unlikely(val <= -READ_ONCE(sysctl_mem_pcpu_rsv))) - proto_memory_pcpu_drain(proto); -} - #define SK_ALLOC_PERCPU_COUNTER_BATCH 16 static inline void sk_sockets_allocated_dec(struct sock *sk) @@ -1466,15 +1397,6 @@ proto_sockets_allocated_sum_positive(struct proto *prot) return percpu_counter_sum_positive(prot->sockets_allocated); } -static inline bool -proto_memory_pressure(struct proto *prot) -{ - if (!prot->memory_pressure) - return false; - return !!READ_ONCE(*prot->memory_pressure); -} - - #ifdef CONFIG_PROC_FS #define PROTO_INUSE_NR 64 /* should be enough for the first time */ struct prot_inuse { diff --git a/net/core/sock.c b/net/core/sock.c index fe9195186c13f51b113f8e8bc69ea25ea4a13aad..e0692b752369cc1cbf34253a40c06d18dcf350fe 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -127,6 +127,7 @@ #include #include #include +#include #include #include #include diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 118c78615543852eabd3067bbb7920418b7da7b3..a452a330d0ed649a2d1b8e65c81aaa3ff3d826f8 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "dev.h" diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index 914bc9c35cc702395aee257fb010034294e501de..6c4664c681ca530d67b9ccc54f11cbb178d32c8e 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 0a3aa30470837f27d7db1a0328228b2e3323bad0..e1f0efbb29d614ed81d4485ae81613f0f97db54a 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -272,6 +272,7 @@ #include #include #include +#include #include #include #include diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 384fa5e2f0655389ac678b5d13553949598a9c74..233c34c0b49461ddf863373f0b441e01068fb92f 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #include diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index ea7ad7d99245c26f4045ebb344bc42cd188afe37..57edf66ff91b3aebbb808604678603792025318c 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -39,6 +39,7 @@ #include #include +#include #include #include diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index 08fdf1251f46af2c7abb154b35d951913ae90fa1..5adf0c0a6c1acdb354a6815b4b77b63599e0166e 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include From patchwork Mon Apr 29 13:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13646990 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85A9871B24 for ; Mon, 29 Apr 2024 13:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398038; cv=none; b=oRsbjgNCNP8HSVe0OsZfYAcJDlGdVq3oEYqrv2vV3TlbqFRkNKTqO1nrYtUOqEMX09VfNU34nhgNhVK8yJnD/8889Fij+tnK4cFxjpz2V0ZQUlp3U+tTbjHXcuFLzu1gbGhf8ZpK7g28nOeQUkJ6B4ri5ohhkjW5HvLq+G//vLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398038; c=relaxed/simple; bh=MwuL9saMcsxuN5t8MgQHJjZ9a+aXsBlVFjFqmMbXOyg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TNIrCQiN7hwOg50br9Hpu84h0yDR8PjeRvxrGUqNHOxRV1/9puOx0WOCsfc/mfUmY2ZTZUvbODomy4qx6fe8JXRfK0U4q4Qth6UawRjOa9yraaqg+jP4bqj9MJJ+MM4z9y+4mkWTEitiAvqD0xizZCG2/HwY4TfRicF7qVvqKIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QnBtrArz; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QnBtrArz" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be3f082b0so2437387b3.1 for ; Mon, 29 Apr 2024 06:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714398035; x=1715002835; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S8D+tPGJTNwcjeDHkLETwaAeOK4SR/aOrJPXXPh0beA=; b=QnBtrArzw3JW4eveHh3B0Frt/sf5L2VQ3VqCjTUYKbr7VZXV1IIrj8DtjVtygkeGNg s02Tq39M+yJfAh4pmwfbBYkgV2pCWXRC7dt4+BDGaKBpXkwXU1fOV0O7gSEnljHlz4Le hOSrmWlrrxNndAjwag7eUn6FhtJS2Jvlh/tyvtU1Dp7mZUbAPI3qenp/gCyLFj8Vklrw zfH8gQzS6IHFT4EoaiVKYN3H80METLZ6r8y5PEF3Oy0wJ+nUrmXGUj9ixOt+/535HU1+ OjcyQ3emoEhnM47EAib0h4AFVK8u1Mm+qPfTwgDtQPa6mPd7JXV/MhDTdjTaNRSh4Lg3 uEdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714398035; x=1715002835; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S8D+tPGJTNwcjeDHkLETwaAeOK4SR/aOrJPXXPh0beA=; b=myKdSFMXhehdILKE2uBpeNz8WrdOxBEhMBMI2itvk3qaMByBi1jQl497s8Vkg3tXlg 9oL8ApDNFL450E8yaNjAhcciZQzexEPf1OsS8U23Gcuk9BSjpeonOJqzNCiik1idG+pF hN+uAbDMJB+RfJFbtNa03HoBu0zL9akviFSig39zS1dbmQyuiuG7kORHaKyPZEgg1o3q Su+8nbaPp/ecYWdrx5srJ65riHYkVaJDWAzTnfrsGLw2wV8zdFGkow1hUC3O0tJnJxNL Cp3IslWhUqhrTdQ4tpCZ6He2iMRknpNSyUYHiCrazEfeOaBbYL8Wuslw2Q/oLRu+NtBz HaQA== X-Gm-Message-State: AOJu0Yzn9NF99tRuSnY49HDa0bvs6WbPLB70IqzhaOmtl6+6JUvYB/o8 nwRc7ilf0JeOEZGuGYRC5aRPYPWafQ+WhPAq3aQntzhNIqjK76S9AcGSmD7V+y/Yyx80+u3SRiy 1fVaqRj58JQ== X-Google-Smtp-Source: AGHT+IGJe8B/eVy58+Qkx3V0fzkpbhzwkswcQPJNNy/SyULjyyczjleFxOkO0fEQN1+RzDjfgpMsW16dqFicXQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1509:b0:dce:30f5:6bc5 with SMTP id q9-20020a056902150900b00dce30f56bc5mr617087ybu.4.1714398035517; Mon, 29 Apr 2024 06:40:35 -0700 (PDT) Date: Mon, 29 Apr 2024 13:40:25 +0000 In-Reply-To: <20240429134025.1233626-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429134025.1233626-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240429134025.1233626-6-edumazet@google.com> Subject: [PATCH net-next 5/5] net: move sysctl_mem_pcpu_rsv to net_hotdata From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org sysctl_mem_pcpu_rsv is used in TCP fast path, move it to net_hodata for better cache locality. Signed-off-by: Eric Dumazet --- include/net/hotdata.h | 1 + include/net/proto_memory.h | 6 +++--- net/core/hotdata.c | 5 +++-- net/core/sock.c | 1 - net/core/sysctl_net_core.c | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/net/hotdata.h b/include/net/hotdata.h index 290499f72e18d45a8ed7bd9e8880a51f7ef2b94c..30e9570beb2afbcb4ece641d6042bdc0de80bd38 100644 --- a/include/net/hotdata.h +++ b/include/net/hotdata.h @@ -40,6 +40,7 @@ struct net_hotdata { int dev_rx_weight; int sysctl_max_skb_frags; int sysctl_skb_defer_max; + int sysctl_mem_pcpu_rsv; }; #define inet_ehash_secret net_hotdata.tcp_protocol.secret diff --git a/include/net/proto_memory.h b/include/net/proto_memory.h index 41404d4bb6f08e84030838f0e63ef240587f65dd..a6ab2f4f5e28a21ab63acb38caf157f6a7415a0b 100644 --- a/include/net/proto_memory.h +++ b/include/net/proto_memory.h @@ -3,10 +3,10 @@ #define _PROTO_MEMORY_H #include +#include /* 1 MB per cpu, in page units */ #define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT)) -extern int sysctl_mem_pcpu_rsv; static inline bool sk_has_memory_pressure(const struct sock *sk) { @@ -65,7 +65,7 @@ sk_memory_allocated_add(const struct sock *sk, int val) val = this_cpu_add_return(*proto->per_cpu_fw_alloc, val); - if (unlikely(val >= READ_ONCE(sysctl_mem_pcpu_rsv))) + if (unlikely(val >= READ_ONCE(net_hotdata.sysctl_mem_pcpu_rsv))) proto_memory_pcpu_drain(proto); } @@ -76,7 +76,7 @@ sk_memory_allocated_sub(const struct sock *sk, int val) val = this_cpu_sub_return(*proto->per_cpu_fw_alloc, val); - if (unlikely(val <= -READ_ONCE(sysctl_mem_pcpu_rsv))) + if (unlikely(val <= -READ_ONCE(net_hotdata.sysctl_mem_pcpu_rsv))) proto_memory_pcpu_drain(proto); } diff --git a/net/core/hotdata.c b/net/core/hotdata.c index a359ff160d54ad379eac7e56e1810a7e840f9275..d0aaaaa556f229ded4e1997bf814a2b690b46920 100644 --- a/net/core/hotdata.c +++ b/net/core/hotdata.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later -#include #include #include #include - +#include +#include struct net_hotdata net_hotdata __cacheline_aligned = { .offload_base = LIST_HEAD_INIT(net_hotdata.offload_base), @@ -20,5 +20,6 @@ struct net_hotdata net_hotdata __cacheline_aligned = { .dev_rx_weight = 64, .sysctl_max_skb_frags = MAX_SKB_FRAGS, .sysctl_skb_defer_max = 64, + .sysctl_mem_pcpu_rsv = SK_MEMORY_PCPU_RESERVE }; EXPORT_SYMBOL(net_hotdata); diff --git a/net/core/sock.c b/net/core/sock.c index e0692b752369cc1cbf34253a40c06d18dcf350fe..8d6e638b5426daf84ff71d22101252943f9c5466 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -284,7 +284,6 @@ __u32 sysctl_rmem_max __read_mostly = SK_RMEM_MAX; EXPORT_SYMBOL(sysctl_rmem_max); __u32 sysctl_wmem_default __read_mostly = SK_WMEM_MAX; __u32 sysctl_rmem_default __read_mostly = SK_RMEM_MAX; -int sysctl_mem_pcpu_rsv __read_mostly = SK_MEMORY_PCPU_RESERVE; int sysctl_tstamp_allow_data __read_mostly = 1; diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index a452a330d0ed649a2d1b8e65c81aaa3ff3d826f8..6da5995ac86a08a58e63af9a1e62c7a136c08dc9 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -416,7 +416,7 @@ static struct ctl_table net_core_table[] = { }, { .procname = "mem_pcpu_rsv", - .data = &sysctl_mem_pcpu_rsv, + .data = &net_hotdata.sysctl_mem_pcpu_rsv, .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_minmax,