netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb
@ 2023-10-17 12:45 Eric Dumazet
  2023-10-17 14:38 ` Stefan Wahren
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-10-17 12:45 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: netdev, eric.dumazet, Eric Dumazet, Stefan Wahren, Neal Cardwell

In commit 75eefc6c59fd ("tcp: tsq: add a shortcut in tcp_small_queue_check()")
we allowed to send an skb regardless of TSQ limits being hit if rtx queue
was empty or had a single skb, in order to better fill the pipe
when/if TX completions were slow.

Then later, commit 75c119afe14f ("tcp: implement rb-tree based
retransmit queue") accidentally removed the special case for
one skb in rtx queue.

Stefan Wahren reported a regression in single TCP flow throughput
using a 100Mbit fec link, starting from commit 65466904b015 ("tcp: adjust
TSO packet sizes based on min_rtt"). This last commit only made the
regression more visible, because it locked the TCP flow on a particular
behavior where TSQ prevented two skbs being pushed downstream,
adding silences on the wire between each TSO packet.

Many thanks to Stefan for his invaluable help !

Fixes: 75c119afe14f ("tcp: implement rb-tree based retransmit queue")
Link: https://lore.kernel.org/netdev/7f31ddc8-9971-495e-a1f6-819df542e0af@gmx.net/
Reported-by: Stefan Wahren <wahrenst@gmx.net>
Tested-by: Stefan Wahren <wahrenst@gmx.net>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
---
 net/ipv4/tcp_output.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 9c8c42c280b7638f0f4d94d68cd2c73e3c6c2bcc..e61a3a381d51b554ec8440928e22a290712f0b6b 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2542,6 +2542,18 @@ static bool tcp_pacing_check(struct sock *sk)
 	return true;
 }
 
+static bool tcp_rtx_queue_empty_or_single_skb(const struct sock *sk)
+{
+	const struct rb_node *node = sk->tcp_rtx_queue.rb_node;
+
+	/* No skb in the rtx queue. */
+	if (!node)
+		return true;
+
+	/* Only one skb in rtx queue. */
+	return !node->rb_left && !node->rb_right;
+}
+
 /* TCP Small Queues :
  * Control number of packets in qdisc/devices to two packets / or ~1 ms.
  * (These limits are doubled for retransmits)
@@ -2579,12 +2591,12 @@ static bool tcp_small_queue_check(struct sock *sk, const struct sk_buff *skb,
 		limit += extra_bytes;
 	}
 	if (refcount_read(&sk->sk_wmem_alloc) > limit) {
-		/* Always send skb if rtx queue is empty.
+		/* Always send skb if rtx queue is empty or has one skb.
 		 * No need to wait for TX completion to call us back,
 		 * after softirq/tasklet schedule.
 		 * This helps when TX completions are delayed too much.
 		 */
-		if (tcp_rtx_queue_empty(sk))
+		if (tcp_rtx_queue_empty_or_single_skb(sk))
 			return false;
 
 		set_bit(TSQ_THROTTLED, &sk->sk_tsq_flags);
-- 
2.42.0.655.g421f12c284-goog


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

* Re: [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb
  2023-10-17 12:45 [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb Eric Dumazet
@ 2023-10-17 14:38 ` Stefan Wahren
  2023-10-17 15:25 ` Neal Cardwell
  2023-10-19  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Wahren @ 2023-10-17 14:38 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: netdev, eric.dumazet, Neal Cardwell

Hi,

Am 17.10.23 um 14:45 schrieb Eric Dumazet:
> In commit 75eefc6c59fd ("tcp: tsq: add a shortcut in tcp_small_queue_check()")
> we allowed to send an skb regardless of TSQ limits being hit if rtx queue
> was empty or had a single skb, in order to better fill the pipe
> when/if TX completions were slow.
>
> Then later, commit 75c119afe14f ("tcp: implement rb-tree based
> retransmit queue") accidentally removed the special case for
> one skb in rtx queue.
>
> Stefan Wahren reported a regression in single TCP flow throughput
> using a 100Mbit fec link, starting from commit 65466904b015 ("tcp: adjust
> TSO packet sizes based on min_rtt"). This last commit only made the
> regression more visible, because it locked the TCP flow on a particular
> behavior where TSQ prevented two skbs being pushed downstream,
> adding silences on the wire between each TSO packet.
>
> Many thanks to Stefan for his invaluable help !
>
just some figures using my ARM platform (Tarragon) as iperf client and a
PC (Ubuntu 22.04) as iperf server.

Using current net ( 95535e37e895 ) without the patch

# iperf -t 10 -i 1 -c 192.168.1.129
------------------------------------------------------------
Client connecting to 192.168.1.129, TCP port 5001
TCP window size: 96.2 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.12 port 33152 connected with 192.168.1.129 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  10.1 MBytes  84.9 Mbits/sec
[  3]  1.0- 2.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  2.0- 3.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  3.0- 4.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  4.0- 5.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  5.0- 6.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  6.0- 7.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  7.0- 8.0 sec  9.75 MBytes  81.8 Mbits/sec
[  3]  8.0- 9.0 sec  9.62 MBytes  80.7 Mbits/sec
[  3]  9.0-10.0 sec  10.0 MBytes  83.9 Mbits/sec
[  3]  0.0-10.0 sec  97.2 MBytes  81.5 Mbits/sec

Using current net with applied patch

# iperf -t 10 -i 1 -c 192.168.1.129
------------------------------------------------------------
Client connecting to 192.168.1.129, TCP port 5001
TCP window size: 96.2 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.12 port 32854 connected with 192.168.1.129 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  11.5 MBytes  96.5 Mbits/sec
[  3]  1.0- 2.0 sec  11.4 MBytes  95.4 Mbits/sec
[  3]  2.0- 3.0 sec  11.2 MBytes  94.4 Mbits/sec
[  3]  3.0- 4.0 sec  11.1 MBytes  93.3 Mbits/sec
[  3]  4.0- 5.0 sec  11.2 MBytes  94.4 Mbits/sec
[  3]  5.0- 6.0 sec  11.2 MBytes  94.4 Mbits/sec
[  3]  6.0- 7.0 sec  11.1 MBytes  93.3 Mbits/sec
[  3]  7.0- 8.0 sec  11.2 MBytes  94.4 Mbits/sec
[  3]  8.0- 9.0 sec  11.2 MBytes  94.4 Mbits/sec
[  3]  9.0-10.0 sec  11.2 MBytes  94.4 Mbits/sec
[  3]  0.0-10.0 sec   113 MBytes  94.4 Mbits/sec

Thanks

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

* Re: [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb
  2023-10-17 12:45 [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb Eric Dumazet
  2023-10-17 14:38 ` Stefan Wahren
@ 2023-10-17 15:25 ` Neal Cardwell
  2023-10-19  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Neal Cardwell @ 2023-10-17 15:25 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
	eric.dumazet, Stefan Wahren

On Tue, Oct 17, 2023 at 8:45 AM Eric Dumazet <edumazet@google.com> wrote:
>
> In commit 75eefc6c59fd ("tcp: tsq: add a shortcut in tcp_small_queue_check()")
> we allowed to send an skb regardless of TSQ limits being hit if rtx queue
> was empty or had a single skb, in order to better fill the pipe
> when/if TX completions were slow.
>
> Then later, commit 75c119afe14f ("tcp: implement rb-tree based
> retransmit queue") accidentally removed the special case for
> one skb in rtx queue.
>
> Stefan Wahren reported a regression in single TCP flow throughput
> using a 100Mbit fec link, starting from commit 65466904b015 ("tcp: adjust
> TSO packet sizes based on min_rtt"). This last commit only made the
> regression more visible, because it locked the TCP flow on a particular
> behavior where TSQ prevented two skbs being pushed downstream,
> adding silences on the wire between each TSO packet.
>
> Many thanks to Stefan for his invaluable help !
>
> Fixes: 75c119afe14f ("tcp: implement rb-tree based retransmit queue")
> Link: https://lore.kernel.org/netdev/7f31ddc8-9971-495e-a1f6-819df542e0af@gmx.net/
> Reported-by: Stefan Wahren <wahrenst@gmx.net>
> Tested-by: Stefan Wahren <wahrenst@gmx.net>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Neal Cardwell <ncardwell@google.com>
> ---

Acked-by: Neal Cardwell <ncardwell@google.com>

Thank you to Eric for the nice find and fix, and thank you to Stefan
for the bug report and all the useful testing and data!

neal

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

* Re: [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb
  2023-10-17 12:45 [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb Eric Dumazet
  2023-10-17 14:38 ` Stefan Wahren
  2023-10-17 15:25 ` Neal Cardwell
@ 2023-10-19  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-19  1:10 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, netdev, eric.dumazet, wahrenst, ncardwell

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 17 Oct 2023 12:45:26 +0000 you wrote:
> In commit 75eefc6c59fd ("tcp: tsq: add a shortcut in tcp_small_queue_check()")
> we allowed to send an skb regardless of TSQ limits being hit if rtx queue
> was empty or had a single skb, in order to better fill the pipe
> when/if TX completions were slow.
> 
> Then later, commit 75c119afe14f ("tcp: implement rb-tree based
> retransmit queue") accidentally removed the special case for
> one skb in rtx queue.
> 
> [...]

Here is the summary with links:
  - [net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb
    https://git.kernel.org/netdev/net/c/f921a4a5bffa

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-10-19  1:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-17 12:45 [PATCH net] tcp: tsq: relax tcp_small_queue_check() when rtx queue contains a single skb Eric Dumazet
2023-10-17 14:38 ` Stefan Wahren
2023-10-17 15:25 ` Neal Cardwell
2023-10-19  1:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).