Skip to contentSkip to conversation

tcp: reduce calls to tcp_schedule_loss_probe()

PATCH Applied Eric Dumazet 4 participants 4 messages Feb 23 – Feb 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: reduce calls to tcp_schedule_loss_probe()

For RPC workloads, we alternate tcp_schedule_loss_probe() calls from output path and from input path, with tp->packets_out value oscillating between !zero and zero, leading to poor branch prediction.

Move tp->packets_out check from tcp_schedule_loss_probe() to tcp_set_xmit_timer().

We avoid one call to tcp_schedule_loss_probe() from tcp_ack() path for typical RPC workloads, while improving branch prediction.

---
 net/ipv4/tcp_input.c  | 2 +-
 net/ipv4/tcp_output.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +1 -1
index e7b41abb82aad33d8cab4fcfa989cc4771149b41..6c3f1d0314446966d0ec4e8efb0b3d83463990d9 100644
@@ -3552,7 +3552,7 @@ void tcp_rearm_rto(struct sock *sk)
 /* Try to schedule a loss probe; if that doesn't work, then schedule an RTO. */
 static void tcp_set_xmit_timer(struct sock *sk)
 {
-	if (!tcp_schedule_loss_probe(sk, true))
+	if (!tcp_sk(sk)->packets_out || !tcp_schedule_loss_probe(sk, true))
 		tcp_rearm_rto(sk);
 }
 
net/ipv4/tcp_output.c +1 -1
index 326b58ff1118d02fc396753d56f210f9d3007c7f..ada38dd9cef477e16ff77544bbdd057d695fa978 100644
@@ -3116,7 +3116,7 @@ bool tcp_schedule_loss_probe(struct sock *sk, bool advancing_rto)
 	 * not in loss recovery, that are either limited by cwnd or application.
 	 */
 	if ((early_retrans != 3 && early_retrans != 4) ||
-	    !tp->packets_out || !tcp_is_sack(tp) ||
+	    !tcp_is_sack(tp) ||
 	    (icsk->icsk_ca_state != TCP_CA_Open &&
 	     icsk->icsk_ca_state != TCP_CA_CWR))
 		return false;
Signature · 1 line
2.53.0.345.g96ddfc5eaa-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Eric Dumazet

For RPC workloads, we alternate tcp_schedule_loss_probe() calls from output path and from input path, with tp->packets_out value oscillating between !zero and zero, leading to poor branch prediction.

Quoted 8 lines

Move tp->packets_out check from tcp_schedule_loss_probe() to tcp_set_xmit_timer().

We avoid one call to tcp_schedule_loss_probe() from tcp_ack() path for typical RPC workloads, while improving branch prediction.

---

Thanks, Eric!

neal

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 5 lines · Eric Dumazet

For RPC workloads, we alternate tcp_schedule_loss_probe() calls from output path and from input path, with tp->packets_out value oscillating between !zero and zero, leading to poor branch prediction.

Quoted 7 lines

Move tp->packets_out check from tcp_schedule_loss_probe() to tcp_set_xmit_timer().

We avoid one call to tcp_schedule_loss_probe() from tcp_ack() path for typical RPC workloads, while improving branch prediction.

#3 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 23 Feb 2026 11:35:01 +0000 you wrote:

For RPC workloads, we alternate tcp_schedule_loss_probe() calls from output path and from input path, with tp->packets_out value oscillating between !zero and zero, leading to poor branch prediction.

Move tp->packets_out check from tcp_schedule_loss_probe() to tcp_set_xmit_timer().

[...]

Here is the summary with links:
- [net-next] tcp: reduce calls to tcp_schedule_loss_probe()

    https://git.kernel.org/netdev/net-next/c/fca59a2dd0b8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html