Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: move net_cookie into net_aligned_data

Using per-cpu data for net->net_cookie generation is overkill,
because even busy hosts do not create hundreds of netns per second.

Make sure to put net_cookie in a private cache line to avoid
potential false sharing.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250630093540.3052835-3-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
998642e9 3715b5df

+4 -6
+2
include/net/aligned_data.h
··· 2 2 #ifndef _NET_ALIGNED_DATA_H 3 3 #define _NET_ALIGNED_DATA_H 4 4 5 + #include <linux/atomic.h> 5 6 #include <linux/types.h> 6 7 7 8 /* Structure holding cacheline aligned fields on SMP builds. ··· 10 9 * attribute to ensure no accidental false sharing can happen. 11 10 */ 12 11 struct net_aligned_data { 12 + atomic64_t net_cookie ____cacheline_aligned_in_smp; 13 13 }; 14 14 15 15 extern struct net_aligned_data net_aligned_data;
+2 -6
net/core/net_namespace.c
··· 19 19 #include <linux/net_namespace.h> 20 20 #include <linux/sched/task.h> 21 21 #include <linux/uidgid.h> 22 - #include <linux/cookie.h> 23 22 #include <linux/proc_fs.h> 24 23 24 + #include <net/aligned_data.h> 25 25 #include <net/sock.h> 26 26 #include <net/netlink.h> 27 27 #include <net/net_namespace.h> ··· 63 63 #define INITIAL_NET_GEN_PTRS 13 /* +1 for len +2 for rcu_head */ 64 64 65 65 static unsigned int max_gen_ptrs = INITIAL_NET_GEN_PTRS; 66 - 67 - DEFINE_COOKIE(net_cookie); 68 66 69 67 static struct net_generic *net_alloc_generic(void) 70 68 { ··· 432 434 LIST_HEAD(net_exit_list); 433 435 int error = 0; 434 436 435 - preempt_disable(); 436 - net->net_cookie = gen_cookie_next(&net_cookie); 437 - preempt_enable(); 437 + net->net_cookie = atomic64_inc_return(&net_aligned_data.net_cookie); 438 438 439 439 list_for_each_entry(ops, &pernet_list, list) { 440 440 error = ops_init(ops, net);