diff mbox series

[net-next,3/4] net: merge net->core.prot_inuse and net->core.sock_inuse

Message ID 20211115171150.3646016-4-eric.dumazet@gmail.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series net: prot_inuse and sock_inuse cleanups | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5067 this patch: 5067
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 900 this patch: 900
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5223 this patch: 5223
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 52 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet Nov. 15, 2021, 5:11 p.m. UTC
From: Eric Dumazet <edumazet@google.com>

net->core.sock_inuse is a per cpu variable (int),
while net->core.prot_inuse is another per cpu variable
of 64 integers.

per cpu allocator tend to place them in very different places.

Grouping them together makes sense, since it makes
updates potentially faster, if hitting the same
cache line.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/netns/core.h |  1 -
 include/net/sock.h       |  3 ++-
 net/core/sock.c          | 12 +-----------
 3 files changed, 3 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/include/net/netns/core.h b/include/net/netns/core.h
index 36c2d998a43c015c4b917428ec33f5839cde89b1..552bc25b19335e2ee07effa2550bbe5944eb33aa 100644
--- a/include/net/netns/core.h
+++ b/include/net/netns/core.h
@@ -12,7 +12,6 @@  struct netns_core {
 	int	sysctl_somaxconn;
 
 #ifdef CONFIG_PROC_FS
-	int __percpu *sock_inuse;
 	struct prot_inuse __percpu *prot_inuse;
 #endif
 };
diff --git a/include/net/sock.h b/include/net/sock.h
index cdc7ebc049b41b00aa7c851a6f1df6e58bae8430..fefffeb1cc3d5a11615afbc34e5cd7521bd6f502 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1421,6 +1421,7 @@  proto_memory_pressure(struct proto *prot)
 #ifdef CONFIG_PROC_FS
 #define PROTO_INUSE_NR	64	/* should be enough for the first time */
 struct prot_inuse {
+	int all;
 	int val[PROTO_INUSE_NR];
 };
 /* Called with local bh disabled */
@@ -1432,7 +1433,7 @@  static inline void sock_prot_inuse_add(const struct net *net,
 
 static inline void sock_inuse_add(const struct net *net, int val)
 {
-	this_cpu_add(*net->core.sock_inuse, val);
+	this_cpu_add(net->core.prot_inuse->all, val);
 }
 
 int sock_prot_inuse_get(struct net *net, struct proto *proto);
diff --git a/net/core/sock.c b/net/core/sock.c
index 214c2e816c63dba9146557a622516e73c1da142e..2f58e4d3e76296280aece28314b8695d0d40cf02 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3549,7 +3549,7 @@  int sock_inuse_get(struct net *net)
 	int cpu, res = 0;
 
 	for_each_possible_cpu(cpu)
-		res += *per_cpu_ptr(net->core.sock_inuse, cpu);
+		res += per_cpu_ptr(net->core.prot_inuse, cpu)->all;
 
 	return res;
 }
@@ -3561,22 +3561,12 @@  static int __net_init sock_inuse_init_net(struct net *net)
 	net->core.prot_inuse = alloc_percpu(struct prot_inuse);
 	if (net->core.prot_inuse == NULL)
 		return -ENOMEM;
-
-	net->core.sock_inuse = alloc_percpu(int);
-	if (net->core.sock_inuse == NULL)
-		goto out;
-
 	return 0;
-
-out:
-	free_percpu(net->core.prot_inuse);
-	return -ENOMEM;
 }
 
 static void __net_exit sock_inuse_exit_net(struct net *net)
 {
 	free_percpu(net->core.prot_inuse);
-	free_percpu(net->core.sock_inuse);
 }
 
 static struct pernet_operations net_inuse_ops = {