* [PATCH net-next] tcp: batch calls to sk_flush_backlog()
@ 2019-08-09 12:04 Eric Dumazet
2019-08-09 13:08 ` Soheil Hassas Yeganeh
2019-08-09 18:07 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2019-08-09 12:04 UTC (permalink / raw)
To: David S . Miller
Cc: netdev, Eric Dumazet, Eric Dumazet, Soheil Hassas Yeganeh
Starting from commit d41a69f1d390 ("tcp: make tcp_sendmsg() aware of socket backlog")
loopback flows got hurt, because for each skb sent, the socket receives an
immediate ACK and sk_flush_backlog() causes extra work.
Intent was to not let the backlog grow too much, but we went a bit too far.
We can check the backlog every 16 skbs (about 1MB chunks)
to increase TCP over loopback performance by about 15 %
Note that the call to sk_flush_backlog() handles a single ACK,
thanks to coalescing done on backlog, but cleans the 16 skbs
found in rtx rb-tree.
Reported-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/tcp.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index a0a66321c0ee99918b2080219dbaefcf3c398e13..f8fa1686f7f3e64f5d4ea8163e7f87538cc0d672 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1162,7 +1162,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
struct sockcm_cookie sockc;
int flags, err, copied = 0;
int mss_now = 0, size_goal, copied_syn = 0;
- bool process_backlog = false;
+ int process_backlog = 0;
bool zc = false;
long timeo;
@@ -1254,9 +1254,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
if (!sk_stream_memory_free(sk))
goto wait_for_sndbuf;
- if (process_backlog && sk_flush_backlog(sk)) {
- process_backlog = false;
- goto restart;
+ if (unlikely(process_backlog >= 16)) {
+ process_backlog = 0;
+ if (sk_flush_backlog(sk))
+ goto restart;
}
first_skb = tcp_rtx_and_write_queues_empty(sk);
skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation,
@@ -1264,7 +1265,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
if (!skb)
goto wait_for_memory;
- process_backlog = true;
+ process_backlog++;
skb->ip_summed = CHECKSUM_PARTIAL;
skb_entail(sk, skb);
--
2.23.0.rc1.153.gdeed80330f-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] tcp: batch calls to sk_flush_backlog()
2019-08-09 12:04 [PATCH net-next] tcp: batch calls to sk_flush_backlog() Eric Dumazet
@ 2019-08-09 13:08 ` Soheil Hassas Yeganeh
2019-08-09 18:07 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Soheil Hassas Yeganeh @ 2019-08-09 13:08 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David S . Miller, netdev, Eric Dumazet
On Fri, Aug 9, 2019 at 8:04 AM Eric Dumazet <edumazet@google.com> wrote:
>
> Starting from commit d41a69f1d390 ("tcp: make tcp_sendmsg() aware of socket backlog")
> loopback flows got hurt, because for each skb sent, the socket receives an
> immediate ACK and sk_flush_backlog() causes extra work.
>
> Intent was to not let the backlog grow too much, but we went a bit too far.
>
> We can check the backlog every 16 skbs (about 1MB chunks)
> to increase TCP over loopback performance by about 15 %
>
> Note that the call to sk_flush_backlog() handles a single ACK,
> thanks to coalescing done on backlog, but cleans the 16 skbs
> found in rtx rb-tree.
>
> Reported-by: Soheil Hassas Yeganeh <soheil@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Thank you very much, Eric!
> ---
> net/ipv4/tcp.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index a0a66321c0ee99918b2080219dbaefcf3c398e13..f8fa1686f7f3e64f5d4ea8163e7f87538cc0d672 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1162,7 +1162,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> struct sockcm_cookie sockc;
> int flags, err, copied = 0;
> int mss_now = 0, size_goal, copied_syn = 0;
> - bool process_backlog = false;
> + int process_backlog = 0;
> bool zc = false;
> long timeo;
>
> @@ -1254,9 +1254,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> if (!sk_stream_memory_free(sk))
> goto wait_for_sndbuf;
>
> - if (process_backlog && sk_flush_backlog(sk)) {
> - process_backlog = false;
> - goto restart;
> + if (unlikely(process_backlog >= 16)) {
> + process_backlog = 0;
> + if (sk_flush_backlog(sk))
> + goto restart;
> }
> first_skb = tcp_rtx_and_write_queues_empty(sk);
> skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation,
> @@ -1264,7 +1265,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> if (!skb)
> goto wait_for_memory;
>
> - process_backlog = true;
> + process_backlog++;
> skb->ip_summed = CHECKSUM_PARTIAL;
>
> skb_entail(sk, skb);
> --
> 2.23.0.rc1.153.gdeed80330f-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] tcp: batch calls to sk_flush_backlog()
2019-08-09 12:04 [PATCH net-next] tcp: batch calls to sk_flush_backlog() Eric Dumazet
2019-08-09 13:08 ` Soheil Hassas Yeganeh
@ 2019-08-09 18:07 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-08-09 18:07 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, soheil
From: Eric Dumazet <edumazet@google.com>
Date: Fri, 9 Aug 2019 05:04:47 -0700
> Starting from commit d41a69f1d390 ("tcp: make tcp_sendmsg() aware of socket backlog")
> loopback flows got hurt, because for each skb sent, the socket receives an
> immediate ACK and sk_flush_backlog() causes extra work.
>
> Intent was to not let the backlog grow too much, but we went a bit too far.
>
> We can check the backlog every 16 skbs (about 1MB chunks)
> to increase TCP over loopback performance by about 15 %
>
> Note that the call to sk_flush_backlog() handles a single ACK,
> thanks to coalescing done on backlog, but cleans the 16 skbs
> found in rtx rb-tree.
>
> Reported-by: Soheil Hassas Yeganeh <soheil@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-09 18:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-09 12:04 [PATCH net-next] tcp: batch calls to sk_flush_backlog() Eric Dumazet
2019-08-09 13:08 ` Soheil Hassas Yeganeh
2019-08-09 18:07 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox