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

tcp: move tcp_memory_allocated into net_aligned_data

____cacheline_aligned_in_smp attribute only makes sure to align
a field to a cache line. It does not prevent the linker to use
the remaining of the cache line for other variables, causing
potential false sharing.

Move tcp_memory_allocated into a dedicated cache line.

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

authored by

Eric Dumazet and committed by
Jakub Kicinski
83081337 998642e9

+11 -6
+3
include/net/aligned_data.h
··· 11 11 */ 12 12 struct net_aligned_data { 13 13 atomic64_t net_cookie ____cacheline_aligned_in_smp; 14 + #if defined(CONFIG_INET) 15 + atomic_long_t tcp_memory_allocated ____cacheline_aligned_in_smp; 16 + #endif 14 17 }; 15 18 16 19 extern struct net_aligned_data net_aligned_data;
-1
include/net/tcp.h
··· 267 267 #define TCP_RACK_STATIC_REO_WND 0x2 /* Use static RACK reo wnd */ 268 268 #define TCP_RACK_NO_DUPTHRESH 0x4 /* Do not use DUPACK threshold in RACK */ 269 269 270 - extern atomic_long_t tcp_memory_allocated; 271 270 DECLARE_PER_CPU(int, tcp_memory_per_cpu_fw_alloc); 272 271 273 272 extern struct percpu_counter tcp_sockets_allocated;
+2
net/core/hotdata.c
··· 4 4 #include <linux/list.h> 5 5 #include <net/aligned_data.h> 6 6 #include <net/hotdata.h> 7 + #include <net/ip.h> 7 8 #include <net/proto_memory.h> 8 9 9 10 struct net_hotdata net_hotdata __cacheline_aligned = { ··· 26 25 EXPORT_SYMBOL(net_hotdata); 27 26 28 27 struct net_aligned_data net_aligned_data; 28 + EXPORT_IPV6_MOD(net_aligned_data);
-2
net/ipv4/tcp.c
··· 302 302 long sysctl_tcp_mem[3] __read_mostly; 303 303 EXPORT_IPV6_MOD(sysctl_tcp_mem); 304 304 305 - atomic_long_t tcp_memory_allocated ____cacheline_aligned_in_smp; /* Current allocated memory. */ 306 - EXPORT_IPV6_MOD(tcp_memory_allocated); 307 305 DEFINE_PER_CPU(int, tcp_memory_per_cpu_fw_alloc); 308 306 EXPORT_PER_CPU_SYMBOL_GPL(tcp_memory_per_cpu_fw_alloc); 309 307
+2 -1
net/ipv4/tcp_ipv4.c
··· 59 59 #include <linux/slab.h> 60 60 #include <linux/sched.h> 61 61 62 + #include <net/aligned_data.h> 62 63 #include <net/net_namespace.h> 63 64 #include <net/icmp.h> 64 65 #include <net/inet_hashtables.h> ··· 3391 3390 .sockets_allocated = &tcp_sockets_allocated, 3392 3391 .orphan_count = &tcp_orphan_count, 3393 3392 3394 - .memory_allocated = &tcp_memory_allocated, 3393 + .memory_allocated = &net_aligned_data.tcp_memory_allocated, 3395 3394 .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc, 3396 3395 3397 3396 .memory_pressure = &tcp_memory_pressure,
+2 -1
net/ipv6/tcp_ipv6.c
··· 41 41 #include <linux/random.h> 42 42 #include <linux/indirect_call_wrapper.h> 43 43 44 + #include <net/aligned_data.h> 44 45 #include <net/tcp.h> 45 46 #include <net/ndisc.h> 46 47 #include <net/inet6_hashtables.h> ··· 2357 2356 .stream_memory_free = tcp_stream_memory_free, 2358 2357 .sockets_allocated = &tcp_sockets_allocated, 2359 2358 2360 - .memory_allocated = &tcp_memory_allocated, 2359 + .memory_allocated = &net_aligned_data.tcp_memory_allocated, 2361 2360 .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc, 2362 2361 2363 2362 .memory_pressure = &tcp_memory_pressure,
+2 -1
net/mptcp/protocol.c
··· 11 11 #include <linux/netdevice.h> 12 12 #include <linux/sched/signal.h> 13 13 #include <linux/atomic.h> 14 + #include <net/aligned_data.h> 14 15 #include <net/sock.h> 15 16 #include <net/inet_common.h> 16 17 #include <net/inet_hashtables.h> ··· 3730 3729 .stream_memory_free = mptcp_stream_memory_free, 3731 3730 .sockets_allocated = &mptcp_sockets_allocated, 3732 3731 3733 - .memory_allocated = &tcp_memory_allocated, 3732 + .memory_allocated = &net_aligned_data.tcp_memory_allocated, 3734 3733 .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc, 3735 3734 3736 3735 .memory_pressure = &tcp_memory_pressure,