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

Ziran Zhang posted 1 patch 3 weeks, 4 days 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 3 weeks, 4 days 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 Paolo Abeni 3 weeks, 2 days ago
On 9/1/26 4:35 AM, 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.
> 
> 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
> +						 */

I'm sorry, I have the feeling the above does not clarify much. Also
AFAICS it's not a 'sharp' drop but any negative delta.

/P
Re: [PATCH net-next] tcp: fix mdev comment in tcp_rtt_estimator()
Posted by Eric Dumazet 3 weeks, 2 days ago
On Thu, Sep 3, 2026 at 10:08 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 9/1/26 4:35 AM, 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.
> >
> > 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
> > +                                              */
>
> I'm sorry, I have the feeling the above does not clarify much. Also
> AFAICS it's not a 'sharp' drop but any negative delta.

I agree, this is a 'legacy comment' that should probably stay for one
more century :)