The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: use likely() for srtt check in tcp_rtt_estimator()
@ 2026-08-08 11:00 Ziran Zhang
  2026-08-10 12:51 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Ziran Zhang @ 2026-08-08 11:00 UTC (permalink / raw)
  To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
	Paolo Abeni
  Cc: Kuniyuki Iwashima, Simon Horman, netdev, linux-kernel,
	Ziran Zhang

In tcp_rtt_estimator(), srtt is initialized to a non-zero value
after the first RTT measurement (srtt = m << 3) and never returns
to zero for the lifetime of the connection. Thus, the "srtt != 0"
branch is almost always true.

Marking it with likely() helps the compiler generate better code
for this hot path.

No functional change is introduced.

Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
 net/ipv4/tcp_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 5b6378b94..a4c4d4760 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1089,7 +1089,7 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
 	 * does not matter how to _calculate_ it. Seems, it was trap
 	 * that VJ failed to avoid. 8)
 	 */
-	if (srtt != 0) {
+	if (likely(srtt != 0)) {
 		m -= (srtt >> 3);	/* m is now error in rtt est */
 		srtt += m;		/* rtt = 7/8 rtt + 1/8 new */
 		if (m < 0) {
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] tcp: use likely() for srtt check in tcp_rtt_estimator()
  2026-08-08 11:00 [PATCH net-next] tcp: use likely() for srtt check in tcp_rtt_estimator() Ziran Zhang
@ 2026-08-10 12:51 ` Eric Dumazet
  2026-08-10 13:25   ` Ziran Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2026-08-10 12:51 UTC (permalink / raw)
  To: Ziran Zhang
  Cc: Neal Cardwell, David S . Miller, Jakub Kicinski, Paolo Abeni,
	Kuniyuki Iwashima, Simon Horman, netdev, linux-kernel

On Sat, Aug 8, 2026 at 1:01 PM Ziran Zhang <zhangcoder@yeah.net> wrote:
>
> In tcp_rtt_estimator(), srtt is initialized to a non-zero value
> after the first RTT measurement (srtt = m << 3) and never returns
> to zero for the lifetime of the connection. Thus, the "srtt != 0"
> branch is almost always true.
>
> Marking it with likely() helps the compiler generate better code
> for this hot path.
>
> No functional change is introduced.
>
> Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
> ---
>  net/ipv4/tcp_input.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 5b6378b94..a4c4d4760 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -1089,7 +1089,7 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
>          * does not matter how to _calculate_ it. Seems, it was trap
>          * that VJ failed to avoid. 8)
>          */
> -       if (srtt != 0) {
> +       if (likely(srtt != 0)) {
>                 m -= (srtt >> 3);       /* m is now error in rtt est */
>                 srtt += m;              /* rtt = 7/8 rtt + 1/8 new */
>                 if (m < 0) {

Many flows are short lived, unfortunately.

I would suggest not adding a likely() here, and let FDO/LTO decide
here on a case by case.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] tcp: use likely() for srtt check in tcp_rtt_estimator()
  2026-08-10 12:51 ` Eric Dumazet
@ 2026-08-10 13:25   ` Ziran Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Ziran Zhang @ 2026-08-10 13:25 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Simon Horman, Jakub Kicinski, Kuniyuki Iwashima,
	linux-kernel, Neal Cardwell, netdev, Paolo Abeni, Ziran Zhang

On Mon, 10 Aug 2026 14:51:09 +0200, Eric Dumazet wrote:
> Many flows are short lived, unfortunately.
> 
> I would suggest not adding a likely() here, and let FDO/LTO decide
> here on a case by case.

Hi Eric,

Thank you for your review.

I didn't fully take into account the large number of short-lived flows 
in real-world networks. I agree with your assessment, so I will drop this patch.

Thanks,
Ziran Zhang


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-10 13:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-08 11:00 [PATCH net-next] tcp: use likely() for srtt check in tcp_rtt_estimator() Ziran Zhang
2026-08-10 12:51 ` Eric Dumazet
2026-08-10 13:25   ` Ziran Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox