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: add tcp_release_cb_cond() helper

Majority of tcp_release_cb() calls do nothing at all.

Provide tcp_release_cb_cond() helper so that release_sock()
can avoid these calls.

Also hint the compiler that __release_sock() and wake_up()
are rarely called.

$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-77 (-77)
Function old new delta
release_sock 258 181 -77
Total: Before=25235790, After=25235713, chg -0.00%

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260310124451.2280968-1-edumazet@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Eric Dumazet and committed by
Paolo Abeni
6f459eda 4320f1f1

+29 -11
+7
include/linux/tcp.h
··· 548 548 TCPF_ACK_DEFERRED = BIT(TCP_ACK_DEFERRED), 549 549 }; 550 550 551 + /* Flags of interest for tcp_release_cb() */ 552 + #define TCP_DEFERRED_ALL (TCPF_TSQ_DEFERRED | \ 553 + TCPF_WRITE_TIMER_DEFERRED | \ 554 + TCPF_DELACK_TIMER_DEFERRED | \ 555 + TCPF_MTU_REDUCED_DEFERRED | \ 556 + TCPF_ACK_DEFERRED) 557 + 551 558 #define tcp_sk(ptr) container_of_const(ptr, struct tcp_sock, inet_conn.icsk_inet.sk) 552 559 553 560 /* Variant of tcp_sk() upgrading a const sock to a read/write tcp socket.
+14
include/net/tcp.h
··· 375 375 int tcp_wmem_schedule(struct sock *sk, int copy); 376 376 void tcp_push(struct sock *sk, int flags, int mss_now, int nonagle, 377 377 int size_goal); 378 + 378 379 void tcp_release_cb(struct sock *sk); 380 + 381 + static inline bool tcp_release_cb_cond(struct sock *sk) 382 + { 383 + #ifdef CONFIG_INET 384 + if (likely(sk->sk_prot->release_cb == tcp_release_cb)) { 385 + if (unlikely(smp_load_acquire(&sk->sk_tsq_flags) & TCP_DEFERRED_ALL)) 386 + tcp_release_cb(sk); 387 + return true; 388 + } 389 + #endif 390 + return false; 391 + } 392 + 379 393 void tcp_wfree(struct sk_buff *skb); 380 394 void tcp_write_timer_handler(struct sock *sk); 381 395 void tcp_delack_timer_handler(struct sock *sk);
+8 -6
net/core/sock.c
··· 3807 3807 void release_sock(struct sock *sk) 3808 3808 { 3809 3809 spin_lock_bh(&sk->sk_lock.slock); 3810 - if (sk->sk_backlog.tail) 3810 + 3811 + if (unlikely(sk->sk_backlog.tail)) 3811 3812 __release_sock(sk); 3812 3813 3813 - if (sk->sk_prot->release_cb) 3814 - INDIRECT_CALL_INET_1(sk->sk_prot->release_cb, 3815 - tcp_release_cb, sk); 3816 - 3814 + if (sk->sk_prot->release_cb) { 3815 + if (!tcp_release_cb_cond(sk)) 3816 + sk->sk_prot->release_cb(sk); 3817 + } 3817 3818 sock_release_ownership(sk); 3818 - if (waitqueue_active(&sk->sk_lock.wq)) 3819 + if (unlikely(waitqueue_active(&sk->sk_lock.wq))) 3819 3820 wake_up(&sk->sk_lock.wq); 3821 + 3820 3822 spin_unlock_bh(&sk->sk_lock.slock); 3821 3823 } 3822 3824 EXPORT_SYMBOL(release_sock);
-5
net/ipv4/tcp_output.c
··· 1320 1320 } 1321 1321 } 1322 1322 1323 - #define TCP_DEFERRED_ALL (TCPF_TSQ_DEFERRED | \ 1324 - TCPF_WRITE_TIMER_DEFERRED | \ 1325 - TCPF_DELACK_TIMER_DEFERRED | \ 1326 - TCPF_MTU_REDUCED_DEFERRED | \ 1327 - TCPF_ACK_DEFERRED) 1328 1323 /** 1329 1324 * tcp_release_cb - tcp release_sock() callback 1330 1325 * @sk: socket