Skip to content

Commit 295ce1e

Browse files
edumazetPaolo Abeni
authored andcommitted
tcp: fix tcp_tso_should_defer() vs large RTT
Neal reported that using neper tcp_stream with TCP_TX_DELAY set to 50ms would often lead to flows stuck in a small cwnd mode, regardless of the congestion control. While tcp_stream sets TCP_TX_DELAY too late after the connect(), it highlighted two kernel bugs. The following heuristic in tcp_tso_should_defer() seems wrong for large RTT: delta = tp->tcp_clock_cache - head->tstamp; /* If next ACK is likely to come too late (half srtt), do not defer */ if ((s64)(delta - (u64)NSEC_PER_USEC * (tp->srtt_us >> 4)) < 0) goto send_now; If next ACK is expected to come in more than 1 ms, we should not defer because we prefer a smooth ACK clocking. While blamed commit was a step in the good direction, it was not generic enough. Another patch fixing TCP_TX_DELAY for established flows will be proposed when net-next reopens. Fixes: 50c8339 ("tcp: tso: restore IW10 after TSO autosizing") Reported-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Neal Cardwell <ncardwell@google.com> Tested-by: Neal Cardwell <ncardwell@google.com> Link: https://patch.msgid.link/20251011115742.1245771-1-edumazet@google.com [pabeni@redhat.com: fixed whitespace issue] Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 75527d6 commit 295ce1e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

net/ipv4/tcp_output.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,8 @@ static bool tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb,
23692369
u32 max_segs)
23702370
{
23712371
const struct inet_connection_sock *icsk = inet_csk(sk);
2372-
u32 send_win, cong_win, limit, in_flight;
2372+
u32 send_win, cong_win, limit, in_flight, threshold;
2373+
u64 srtt_in_ns, expected_ack, how_far_is_the_ack;
23732374
struct tcp_sock *tp = tcp_sk(sk);
23742375
struct sk_buff *head;
23752376
int win_divisor;
@@ -2431,9 +2432,19 @@ static bool tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb,
24312432
head = tcp_rtx_queue_head(sk);
24322433
if (!head)
24332434
goto send_now;
2434-
delta = tp->tcp_clock_cache - head->tstamp;
2435-
/* If next ACK is likely to come too late (half srtt), do not defer */
2436-
if ((s64)(delta - (u64)NSEC_PER_USEC * (tp->srtt_us >> 4)) < 0)
2435+
2436+
srtt_in_ns = (u64)(NSEC_PER_USEC >> 3) * tp->srtt_us;
2437+
/* When is the ACK expected ? */
2438+
expected_ack = head->tstamp + srtt_in_ns;
2439+
/* How far from now is the ACK expected ? */
2440+
how_far_is_the_ack = expected_ack - tp->tcp_clock_cache;
2441+
2442+
/* If next ACK is likely to come too late,
2443+
* ie in more than min(1ms, half srtt), do not defer.
2444+
*/
2445+
threshold = min(srtt_in_ns >> 1, NSEC_PER_MSEC);
2446+
2447+
if ((s64)(how_far_is_the_ack - threshold) > 0)
24372448
goto send_now;
24382449

24392450
/* Ok, it looks like it is advisable to defer.

0 commit comments

Comments
 (0)