tcp: add tcp_release_cb_cond() helper
Subsystems (4)
PATCH 1/1 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 thar __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%
--- include/linux/tcp.h | 7 +++++++ include/net/tcp.h | 14 ++++++++++++++ net/core/sock.c | 14 ++++++++------ net/ipv4/tcp_output.c | 5 ----- 4 files changed, 29 insertions(+), 11 deletions(-)
include/linux/tcp.h +7 -0
@@ -548,6 +548,13 @@ enum tsq_flags { TCPF_ACK_DEFERRED = BIT(TCP_ACK_DEFERRED), }; +/* Flags of interest for tcp_release_cb() */ +#define TCP_DEFERRED_ALL (TCPF_TSQ_DEFERRED | \ + TCPF_WRITE_TIMER_DEFERRED | \ + TCPF_DELACK_TIMER_DEFERRED | \ + TCPF_MTU_REDUCED_DEFERRED | \ + TCPF_ACK_DEFERRED) +#define tcp_sk (ptr) container_of_const(ptr, struct tcp_sock, inet_conn.icsk_inet.sk)/* Variant of tcp_sk() upgrading a const sock to a read/write tcp socket.
include/net/tcp.h +14 -0
@@ -375,7 +375,21 @@ int tcp_send_mss(struct sock *sk, int *size_goal, int flags);int tcp_wmem_schedule (struct sock *sk,int copy);void tcp_push (struct sock *sk,int flags,int mss_now,int nonagle,int size_goal); +void tcp_release_cb (struct sock *sk); + +static inline bool tcp_release_cb_cond (struct sock *sk) +{ +#ifdef CONFIG_INET +if (likely (sk->sk_prot->release_cb == tcp_release_cb)) { +if (unlikely (smp_load_acquire (&sk->sk_tsq_flags) &TCP_DEFERRED_ALL )) +tcp_release_cb (sk); +return true; + } +#endif +return false; +} +void tcp_wfree (struct sk_buff *skb);void tcp_write_timer_handler (struct sock *sk);void tcp_delack_timer_handler (struct sock *sk);
net/core/sock.c +8 -6
@@ -3807,16 +3807,18 @@ EXPORT_SYMBOL(lock_sock_nested);void release_sock (struct sock *sk) {spin_lock_bh (&sk->sk_lock.slock); -if (sk->sk_backlog.tail) -__release_sock (sk); -if (sk->sk_prot->release_cb) -INDIRECT_CALL_INET_1 (sk->sk_prot->release_cb, - tcp_release_cb, sk); +if (unlikely (sk->sk_backlog.tail)) +__release_sock (sk); +if (sk->sk_prot->release_cb) { +if (!tcp_release_cb_cond (sk)) + sk->sk_prot->release_cb (sk); + }sock_release_ownership (sk); -if (waitqueue_active (&sk->sk_lock.wq)) +if (unlikely (waitqueue_active (&sk->sk_lock.wq)))wake_up (&sk->sk_lock.wq); +spin_unlock_bh (&sk->sk_lock.slock); }EXPORT_SYMBOL (release_sock);
net/ipv4/tcp_output.c +0 -5
@@ -1320,11 +1320,6 @@ static void tcp_tsq_workfn(struct work_struct *work) } } -#define TCP_DEFERRED_ALL (TCPF_TSQ_DEFERRED | \ - TCPF_WRITE_TIMER_DEFERRED | \ - TCPF_DELACK_TIMER_DEFERRED | \ - TCPF_MTU_REDUCED_DEFERRED | \ - TCPF_ACK_DEFERRED)/** * tcp_release_cb - tcp release_sock() callback * @sk: socket
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 9 lines · Eric Dumazet
Majority of
tcp_release_cb()calls do nothing at all.Provide
tcp_release_cb_cond()helper so thatrelease_sock()can avoid these calls.Also hint the compiler thar
__release_sock()andwake_up()are rarely called.
Quoted 7 lines
$ 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 <[email protected]>
Paolo Abeni
maintainerQuoted 6 lines · Eric Dumazet
Majority of
tcp_release_cb()calls do nothing at all.Provide
tcp_release_cb_cond()helper so thatrelease_sock()can avoid these calls.Also hint the compiler thar
__release_sock()andwake_up()
I took the liberty of fixing the above typo while applying the patch.
Quoted 1 line
are rarely called.
For my education: out of sheer ignorance and lack of relevant H/W to actually measure the thing, I thought that on very high speed link with big TCP enabled, user-space process and BH processing running on different CPUs backlog usage would be quite probable?!?
/P
Quoted 9 lines · Paolo Abeni
Quoted 6 lines · Eric Dumazet
Majority of
tcp_release_cb()calls do nothing at all.Provide
tcp_release_cb_cond()helper so thatrelease_sock()can avoid these calls.Also hint the compiler thar
__release_sock()andwake_up()
Quoted 8 lines
I took the liberty of fixing the above typo while applying the patch.
Quoted 1 line
are rarely called.
For my education: out of sheer ignorance and lack of relevant H/W to actually measure the thing, I thought that on very high speed link with big TCP enabled, user-space process and BH processing running on different CPUs backlog usage would be quite probable?!?
Yes, but in this case each system call pumps in or out a lot of data.
Majority of data center traffic is RPC, overall probability of calling
__release_sock()
is less than 5 %.
I mostly see that by looking at the difference between non FDO compilations and FDO kernels.
Thanks !
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Tue, 10 Mar 2026 12:44:51 +0000 you wrote:
Majority of
tcp_release_cb()calls do nothing at all.Provide
tcp_release_cb_cond()helper so thatrelease_sock()can avoid these calls.Also hint the compiler thar
__release_sock()andwake_up()are rarely called.[...]
Here is the summary with links:
- [net-next] tcp: add tcp_release_cb_cond() helper
https://git.kernel.org/netdev/net-next/c/6f459eda8b60
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html