Netdev List
 help / color / mirror / Atom feed
From: Lin Lei <llleigoing@gmail.com>
To: Eric Dumazet <edumazet@kernel.org>
Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
	ncardwell@google.com, kuniyu@google.com, davem@davemloft.net,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org,
	llleigoing@outlook.com
Subject: Re: [PATCH net 2/3] net: bound receive window predictions before narrowing
Date: Fri, 27 Nov 2026 15:04:25 +0000	[thread overview]
Message-ID: <20261127150425.1393380-1-llleigoing@gmail.com> (raw)
In-Reply-To: <CAL4WiiqM1E9wzfjCzHcOy2SN6j0CjN6r94JYdPNt=RoLLDL5hw@mail.gmail.com>

Hi Eric,

Sorry for the late reply -- it took me some time to put together clean
WAN reproducers and check the tracepoints carefully before getting back
to you.

Reading your comments on patches 1 and 2, I realize my v1 changelogs
did not explain the failure mode clearly and conflated two separate
issues:

  1) an implementation bug where 32-bit wrap coupled with the
     unconditional rcvq_space.space update can leave sk_rcvbuf stuck at
     its initial value across subsequent steady in-order streaming; and
  2) the pre-existing overshoot of the slow-start heuristic itself on
     burst or backlog samples.

I think it is clearer to look at them separately. Replies inline below.

On Thu, 19 Nov 2026 08:56:32 +0100, Eric Dumazet wrote:
> What happens today: this round gets a smaller sk_rcvbuf increase than
> the formula asked for (or none). sk_rcvbuf never shrinks here, and
> the next measurement has a sane @oldval. So we lose one step.

Looking closer at tcp_rcvbuf_grow(), it seems this can lose more than
one step -- once @rcvwin wraps, sk_rcvbuf can stay stuck at its initial
value across subsequent steady in-order RTTs (barring an OOO packet
hitting tcp_data_queue_ofo() or another multi-RTT stall).

In tcp_rcvbuf_grow(), tp->rcvq_space.space is overwritten with @newval
at the top of the function, even when u32 @rcvwin wraps and
sk->sk_rcvbuf (and therefore tp->window_clamp) is not updated:

  void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
  {
          ...
          oldval = tp->rcvq_space.space;
          tp->rcvq_space.space = newval;   /* updated unconditionally */
          ...
          rcvwin = newval << 1;
          ...
          grow = div_u64(((u64)rcvwin << 1) * (newval - oldval), oldval);
          rcvwin += grow;                  /* wraps in u32 */
          ...
          rcvbuf = min_t(u32, tcp_space_from_win(sk, rcvwin), cap);
          if (rcvbuf > sk->sk_rcvbuf) {    /* false after wrap */
                  WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
                  WRITE_ONCE(tp->window_clamp,
                             tcp_win_from_space(sk, rcvbuf));
          }
  }

Concretely, taking the values from the TCP trace below (rtt_us = 100000,
ooo = 0, scaling_ratio = 158):

  1. Initial sk_rcvbuf = 6,382,000 gives tp->window_clamp = 3,938,890,
     with initial oldval = 14,480.

  2. After an initial receiver stall, a measurement sees copied =
     3,987,000 and inq = 39,096, so net @newval = 3,947,904:
       - tp->rcvq_space.space becomes 3,947,904;
       - the unnarrowed prediction is 4,297,614,134 (2^32 + 2,646,838),
         which wraps in u32 @rcvwin to 2,646,838 -> rcvbuf = 4,288,547;
       - since rcvbuf < sk->sk_rcvbuf, neither sk->sk_rcvbuf nor
         tp->window_clamp changes.

  3. Now tp->rcvq_space.space (3,947,904) exceeds tp->window_clamp
     (3,938,890) by 9,014 bytes. (tcp_measure_rcv_mss() clamps
     rcvq_space.space down to window_clamp only when scaling_ratio
     changes.)

  4. Across the rest of the 64 MiB steady in-order transfer with
     continuous reads, each ~1-RTT sample stays below 3,947,904, so
     tcp_rcv_space_adjust() keeps taking:

       if (copied <= tp->rcvq_space.space)
           goto new_measure;

     no further tcp_rcvbuf_grow tracepoint fires, and sk_rcvbuf stays
     at 6,382,000.

A similar lock-in happens in mptcp_rcvbuf_grow(): once
msk->rcvq_space.space is set to 3,963,800 (with oldval = 14,600,
wrapping 4,296,650,602 to 1,683,306 -> rcvbuf = 3,215,868 at
scaling_ratio = 134), sk_rcvbuf stays at 6,553,600 (whose full-budget
window at that ratio is ~3.43 MB) throughout steady streaming.

> For TCP, the slow start branch is only taken if the RTT is above
> tcp_rcvbuf_low_rtt (1ms by default). I guess you had to change this
> sysctl to get this result over loopback ? Please describe the full
> setup, including tcp_rmem[1].
>
> More importantly, reaching tcp_rmem[2] after a single 4MB burst is
> not a goal. What is the user visible problem here ? Do you have
> numbers (throughput, drops, rcv window) for a real flow ?

Yes -- my v1 loopback test for TCP had lowered tcp_rcvbuf_low_rtt
(MPTCP has no low_rtt check). To test without touching that sysctl, I
reran over a simulated WAN on 7.4.0-rc2 (mptcp_net-next commit
800508bf1ccd, keeping tcp_rcvbuf_low_rtt = 1000 us and tcp_timestamps =
1 at defaults, with tcp_wmem raised so the sender is not
send-buffer-bound):

1) WAN reproducer setup and results:

   I tuned tcp_rmem[1] and the initial write size here specifically to
   land inside the narrow (~1.8 KB on TCP, ~1.6 KB on MPTCP)
   non-growing wrap window and verify whether the flow recovers on
   subsequent RTTs; I do not have data suggesting this narrow window is
   hit frequently on mainline.

   Trigger conditions:
     - Path: two netns over veth + tc netem with 100 ms RTT and
       1 Gbit/s (BDP = 12.5 MB), MTU 1500, TSO/GSO/GRO disabled.
     - Budgets: tcp_rmem[1] ~ 6.1-6.25 MiB, tcp_rmem[2] = 64 MiB,
       tcp_wmem[1] = 16 MiB on TCP / 8 MiB on MPTCP, tcp_wmem[2] =
       64 MiB.
     - Traffic: Phase 1 queues an initial burst before draining so that
       the resulting sample lands in the first 4 GiB wrap window (on
       Phase 1's drain for MPTCP, and as Phase 2 starts for TCP);
       Phase 2 streams 64 MiB with normal continuous reads.

   Results (Phase 2 application goodput over 64 MiB):
     - Plain TCP (tcp_rmem = "4096 6382000 67108864"):
       * unpatched: SO_RCVBUF stays 6382000 -> 6382000 -> 6382000;
         trace_tcp_rcvbuf_grow fires once (time=113917 rtt_us=100000
         copied=3987000 inq=39096 space=14480 ooo=0 scaling_ratio=158
         window_clamp=3938890); 64 MiB takes 1.823s (294.4 Mbit/s).
       * with v1 patches 1+2: SO_RCVBUF reaches 67108864 and 64 MiB
         takes 0.767s (699.8 Mbit/s).

     - MPTCP (tcp_rmem = "4096 6553600 67108864"):
       * unpatched: SO_RCVBUF stays 6553600 -> 6553600 -> 6553600;
         trace_mptcp_rcvbuf_grow fires once; 64 MiB takes 2.019s
         (265.9 Mbit/s).
       * with v1 patches 1+2: SO_RCVBUF reaches 67108864 and 64 MiB
         takes 0.815s (658.8 Mbit/s).

   Standalone reproducer scripts for TCP and MPTCP:
     https://gist.githubusercontent.com/llleixx/5201855b015831b5377a02478f843949/raw/repro_tcp_lockin.sh
     https://gist.githubusercontent.com/llleixx/5201855b015831b5377a02478f843949/raw/repro_mptcp_lockin.sh

2) Original workload (your question on patch 1): I first ran into a
   stuck receive buffer on an Ubuntu 6.8 kernel with default tcp_rmem
   ("4096 131072 6291456") on MPTCP over a high-jitter path; in a local
   6.8 reproduction of that setup, sk_rcvbuf stayed at 131,072
   alongside msk->rcvq_space.space = 16,282,074. (On 6.8,
   mptcp_rcv_space_adjust() kept rcvwin in u64 but narrowed at int win
   in __tcp_space_from_win(), and its older msk rtt_us caching could
   allow a longer sampling interval.) While auditing current mainline
   from there, I noticed the u32 @rcvwin wrap above as well.

> This needs @newval to be ~256 times @oldval between two consecutive
> measurements. The "allow the sender to double its rate" logic was
> never meant to be meaningful for such a sample: a 4GB prediction
> out of 4MB copied to user space is garbage, wrapped or not.
> [...]
> What happens with your patch: a single sample like this sends
> sk_rcvbuf straight to tcp_rmem[2].
>
> This is the kind of sk_rcvbuf inflation we have been trying to avoid
> lately, see commit aa251c84636c and the tcp_rcvbuf_low_rtt logic.
> I am not convinced this is an improvement.
> [...]
> If there is a real case where growth is too slow, I would rather
> discuss the heuristic than the type of @rcvwin.

Agreed -- a 4 GB prediction from a 4 MB read makes no sense, and
jumping straight to tcp_rmem[2] on a single burst is undesirable.

It seems this overshoot is inherent to the current formula rather than
caused by widening @rcvwin: even on unpatched mainline, with
oldval = 14,480 and scaling_ratio = 158, a burst or OOO release of
~382 KiB already yields rcvwin > 39.5 MiB and sends sk_rcvbuf straight
to a 64 MiB tcp_rmem[2] (~342 KiB already reaches ~51 MiB). Around
~3.95 MB, the u32 wrap turns that overshoot into the lock-in above.

Following the comment above the formula ("slow start: allow the sender
to double its rate"), one option (with u64 @rcvwin) might be to cap the
growth ratio (newval - oldval) / oldval at 1:

  grow = rcvwin << 1;
  if (newval - oldval < oldval)
          grow = div_u64(grow * (newval - oldval), oldval);

That leaves rising samples up to 2x unchanged while bounding larger
jumps to a 6 * newval window (~3.6 MiB rcvbuf instead of 64 MiB for a
382 KiB burst, though a 3.95 MB burst still yields ~36.6 MiB). Since
genuine slow-start samples can exceed 2x slightly (e.g. ~2.2x in commit
aa251c84636c's trace), this would still need to be evaluated against
the slow-start workloads from aa251c84636c to check the ramp-up vs.
peak-budget trade-off.

> If you send this again:
>
> - net-next, no Fixes: tag, unless you can show a real regression.
>
> - Please split TCP and MPTCP changes. One patch with a "net:" prefix
>   touching both, with a single Fixes: tag pointing to a TCP commit
>   is not right for mptcp_rcvbuf_grow().
> [...]
> Same remark about the Signed-off-by: than for patch 1.

Understood -- for any follow-up patches, I will target net-next without
Fixes:, split TCP and MPTCP, and fix my From:/Signed-off-by:
consistency. On patch 1, I also agree with your point about huge
best-effort SO_RCVLOWAT values.

To summarize:

  1) The 32-bit @rcvwin wrap coupled with the unconditional
     rcvq_space.space update is an implementation bug that can leave
     sk_rcvbuf stuck across steady in-order streaming on both TCP and
     MPTCP, rather than only losing one step.
  2) Jumping straight to tcp_rmem[2] on a burst is a separate
     limitation of the current unbounded slow-start extrapolation,
     which could potentially be tamed by bounding (newval - oldval) /
     oldval (e.g. at 1, subject to slow-start benchmarking).

The above is just my personal take on these issues -- I would really
appreciate your thoughts and advice.

Thanks,
Lin

  reply	other threads:[~2026-11-27 15:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
2026-11-17  5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
2026-11-19  7:54   ` Eric Dumazet
2026-11-20  8:22   ` netdev-bot+sashiko
2026-11-17  5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
2026-11-19  7:56   ` Eric Dumazet
2026-11-27 15:04     ` Lin Lei [this message]
2026-11-20  8:22   ` netdev-bot+sashiko
2026-11-17  5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
2026-11-19  7:59   ` Eric Dumazet
2026-11-19 18:33     ` Matthieu Baerts
2026-11-20  8:05       ` Lin Lei
2026-11-20  8:22   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127150425.1393380-1-llleigoing@gmail.com \
    --to=llleigoing@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=llleigoing@outlook.com \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox