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.

tcp: Remove sk->sk_prot->orphan_count.

TCP tracks the number of orphaned (SOCK_DEAD but not yet destructed)
sockets in tcp_orphan_count.

In some code that was shared with DCCP, tcp_orphan_count is referenced
via sk->sk_prot->orphan_count.

Let's reference tcp_orphan_count directly.

inet_csk_prepare_for_destroy_sock() is moved to inet_connection_sock.c
due to header dependency.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250829215641.711664-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
7051b54f 864ecc4a

+24 -18
+2 -2
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
··· 505 505 506 506 chtls_send_reset(child, CPL_ABORT_SEND_RST, skb); 507 507 sock_orphan(child); 508 - INC_ORPHAN_COUNT(child); 508 + tcp_orphan_count_inc(); 509 509 if (child->sk_state == TCP_CLOSE) 510 510 inet_csk_destroy_sock(child); 511 511 } ··· 870 870 * created only after 3 way handshake is done. 871 871 */ 872 872 sock_orphan(child); 873 - INC_ORPHAN_COUNT(child); 873 + tcp_orphan_count_inc(); 874 874 chtls_release_resources(child); 875 875 chtls_conn_done(child); 876 876 } else {
-1
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h
··· 95 95 #define WSCALE_OK(tp) ((tp)->rx_opt.wscale_ok) 96 96 #define TSTAMP_OK(tp) ((tp)->rx_opt.tstamp_ok) 97 97 #define SACK_OK(tp) ((tp)->rx_opt.sack_ok) 98 - #define INC_ORPHAN_COUNT(sk) this_cpu_inc(*(sk)->sk_prot->orphan_count) 99 98 100 99 /* TLS SKB */ 101 100 #define skb_ulp_tls_inline(skb) (ULP_SKB_CB(skb)->ulp.tls.ofld)
+1 -7
include/net/inet_connection_sock.h
··· 299 299 return (unsigned long)min_t(u64, timeout, max_timeout); 300 300 } 301 301 302 - static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk) 303 - { 304 - /* The below has to be done to allow calling inet_csk_destroy_sock */ 305 - sock_set_flag(sk, SOCK_DEAD); 306 - this_cpu_inc(*sk->sk_prot->orphan_count); 307 - } 308 - 309 302 void inet_csk_destroy_sock(struct sock *sk); 303 + void inet_csk_prepare_for_destroy_sock(struct sock *sk); 310 304 void inet_csk_prepare_forced_close(struct sock *sk); 311 305 312 306 /*
-2
include/net/sock.h
··· 1353 1353 unsigned int useroffset; /* Usercopy region offset */ 1354 1354 unsigned int usersize; /* Usercopy region size */ 1355 1355 1356 - unsigned int __percpu *orphan_count; 1357 - 1358 1356 struct request_sock_ops *rsk_prot; 1359 1357 struct timewait_sock_ops *twsk_prot; 1360 1358
+10
include/net/tcp.h
··· 54 54 DECLARE_PER_CPU(unsigned int, tcp_orphan_count); 55 55 int tcp_orphan_count_sum(void); 56 56 57 + static inline void tcp_orphan_count_inc(void) 58 + { 59 + this_cpu_inc(tcp_orphan_count); 60 + } 61 + 62 + static inline void tcp_orphan_count_dec(void) 63 + { 64 + this_cpu_dec(tcp_orphan_count); 65 + } 66 + 57 67 DECLARE_PER_CPU(u32, tcp_tw_isn); 58 68 59 69 void tcp_time_wait(struct sock *sk, int state, int timeo);
+9 -2
net/ipv4/inet_connection_sock.c
··· 1296 1296 1297 1297 xfrm_sk_free_policy(sk); 1298 1298 1299 - this_cpu_dec(*sk->sk_prot->orphan_count); 1299 + tcp_orphan_count_dec(); 1300 1300 1301 1301 sock_put(sk); 1302 1302 } 1303 1303 EXPORT_SYMBOL(inet_csk_destroy_sock); 1304 + 1305 + void inet_csk_prepare_for_destroy_sock(struct sock *sk) 1306 + { 1307 + /* The below has to be done to allow calling inet_csk_destroy_sock */ 1308 + sock_set_flag(sk, SOCK_DEAD); 1309 + tcp_orphan_count_inc(); 1310 + } 1304 1311 1305 1312 /* This function allows to force a closure of a socket after the call to 1306 1313 * tcp_create_openreq_child(). ··· 1376 1369 1377 1370 sock_orphan(child); 1378 1371 1379 - this_cpu_inc(*sk->sk_prot->orphan_count); 1372 + tcp_orphan_count_inc(); 1380 1373 1381 1374 if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(req)->tfo_listener) { 1382 1375 BUG_ON(rcu_access_pointer(tcp_sk(child)->fastopen_rsk) != req);
+1 -1
net/ipv4/inet_hashtables.c
··· 707 707 if (ok) { 708 708 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 709 709 } else { 710 - this_cpu_inc(*sk->sk_prot->orphan_count); 710 + tcp_orphan_count_inc(); 711 711 inet_sk_set_state(sk, TCP_CLOSE); 712 712 sock_set_flag(sk, SOCK_DEAD); 713 713 inet_csk_destroy_sock(sk);
+1 -1
net/ipv4/tcp.c
··· 3195 3195 /* remove backlog if any, without releasing ownership. */ 3196 3196 __release_sock(sk); 3197 3197 3198 - this_cpu_inc(tcp_orphan_count); 3198 + tcp_orphan_count_inc(); 3199 3199 3200 3200 /* Have we already been destroyed by a softirq or backlog? */ 3201 3201 if (state != TCP_CLOSE && sk->sk_state == TCP_CLOSE)
-1
net/ipv4/tcp_ipv4.c
··· 3517 3517 .leave_memory_pressure = tcp_leave_memory_pressure, 3518 3518 .stream_memory_free = tcp_stream_memory_free, 3519 3519 .sockets_allocated = &tcp_sockets_allocated, 3520 - .orphan_count = &tcp_orphan_count, 3521 3520 3522 3521 .memory_allocated = &net_aligned_data.tcp_memory_allocated, 3523 3522 .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc,
-1
net/ipv6/tcp_ipv6.c
··· 2353 2353 .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc, 2354 2354 2355 2355 .memory_pressure = &tcp_memory_pressure, 2356 - .orphan_count = &tcp_orphan_count, 2357 2356 .sysctl_mem = sysctl_tcp_mem, 2358 2357 .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_tcp_wmem), 2359 2358 .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_tcp_rmem),