[PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()

Ziran Zhang posted 1 patch 1 month, 1 week ago
There is a newer version of this series
net/ipv4/tcp_input.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()
Posted by Ziran Zhang 1 month, 1 week ago
The old comment "mdev = 3/4 mdev + 1/4 new" only describes the
common case. However, when RTT drops sharply, the code applies
a finer gain of 1/32 instead of 1/4, resulting in:
mdev = 31/32 mdev + 1/32 * new.

Express both cases with a unified formula using variable
gain g.

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

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 0f60a1dbf..2c9feb181 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1108,7 +1108,10 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
 		} else {
 			m -= (tp->mdev_us >> 2);   /* similar update on mdev */
 		}
-		tp->mdev_us += m;		/* mdev = 3/4 mdev + 1/4 new */
+		tp->mdev_us += m;		/*
+						 * mdev = (1-g)*mdev + g*new, g=1/4 normally,
+						 * g=1/32 on sharp RTT drop
+						 */
 		if (tp->mdev_us > tp->mdev_max_us) {
 			tp->mdev_max_us = tp->mdev_us;
 			if (tp->mdev_max_us > tp->rttvar_us)
-- 
2.51.0
Re: [PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()
Posted by Jakub Kicinski 1 month, 1 week ago
On Tue, 18 Aug 2026 16:51:53 +0800 Ziran Zhang wrote:
> The old comment "mdev = 3/4 mdev + 1/4 new" only describes the
> common case. However, when RTT drops sharply, the code applies
> a finer gain of 1/32 instead of 1/4, resulting in:
> mdev = 31/32 mdev + 1/32 * new.
> 
> Express both cases with a unified formula using variable
> gain g.

## Form letter - net-next-closed

The merge window for v7.3 has started, and therefore net-next is closed
for new drivers, features, code refactoring and optimizations.
We will only consider applying net-next patches which were posted
before the announcement:

https://lore.kernel.org/20260816155953.072d73da@kernel.org

Fixes are obviously welcome at any time. net-next patches may be sent
for review and discussion only with an RFC tag.

Please repost when net-next reopens.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
-- 
pw-bot: defer
pv-bot: closed
Re: [PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()
Posted by Ziran Zhang 1 month, 1 week ago
On Tue, 18 Aug 2026 08:13:46 -0700 Jakub Kicinski wrote:
> ## Form letter - net-next-closed
> 
> The merge window for v7.3 has started, and therefore net-next is closed
> for new drivers, features, code refactoring and optimizations.
> We will only consider applying net-next patches which were posted
> before the announcement:
> 
> https://lore.kernel.org/20260816155953.072d73da@kernel.org
> 
> Fixes are obviously welcome at any time. net-next patches may be sent
> for review and discussion only with an RFC tag.
> 
> Please repost when net-next reopens.
> 
> See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
> -- 
> pw-bot: defer
> pv-bot: closed

Hi Jakub,

Thanks for your reply.

I understand that net-next is currently closed. I will wait for it to reopen 
and then resubmit the patch.

Thanks,
Ziran Zhang
Re: [PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()
Posted by Jakub Kicinski 1 month, 1 week ago
On Tue, 18 Aug 2026 23:42:53 +0800 Ziran Zhang wrote:
> Thanks for your reply.
> 
> I understand that net-next is currently closed. I will wait for it to reopen 
> and then resubmit the patch.

TBH I'm not sure this patch is worth the review overhead in the first
place.
Re: [PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()
Posted by Ziran Zhang 1 month, 1 week ago
On Tue, 18 Aug 2026 08:53:54 -0700, Jakub Kicinski wrote:
> TBH I'm not sure this patch is worth the review overhead in the first
> place.

Hi Jakub,

Thanks for your feedback.

I understand the concern about review overhead. The reason I think this
patch is worthwhile is that the current comment has been misleading for
years. It only describes the common case but omits the sharp RTT drop
case, which can confuse developers (especially newbies) trying to
understand the RTO calculation logic.

If you still think this fix is not worth a standalone patch, I'm happy
to follow your suggestion on how to best get it in.

Thanks,
Ziran Zhang