netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net] tcp: Prevent low rmem stalls with SO_RCVLOWAT.
@ 2020-10-23 17:48 Arjun Roy
  2020-10-23 18:31 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Arjun Roy @ 2020-10-23 17:48 UTC (permalink / raw)
  To: davem, netdev; +Cc: arjunroy, edumazet, soheil, ncardwell

From: Arjun Roy <arjunroy@google.com>

With SO_RCVLOWAT, under memory pressure,
it is possible to enter a state where:

1. We have not received enough bytes to satisfy SO_RCVLOWAT.
2. We have not entered buffer pressure (see tcp_rmem_pressure()).
3. But, we do not have enough buffer space to accept more packets.

In this case, we advertise 0 rwnd (due to #3) but the application does
not drain the receive queue (no wakeup because of #1 and #2) so the
flow stalls.

Modify the heuristic for SO_RCVLOWAT so that, if we are advertising
rwnd<=rcv_mss, force a wakeup to prevent a stall.

Without this patch, setting tcp_rmem to 6143 and disabling TCP
autotune causes a stalled flow. With this patch, no stall occurs. This
is with RPC-style traffic with large messages.

Fixes: 03f45c883c6f ("tcp: avoid extra wakeups for SO_RCVLOWAT users")
Signed-off-by: Arjun Roy <arjunroy@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>

---
 net/ipv4/tcp.c       | 2 ++
 net/ipv4/tcp_input.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index de19af65bc70..f605cf87b9be 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -521,6 +521,8 @@ static inline bool tcp_stream_is_readable(const struct tcp_sock *tp,
 			return true;
 		if (tcp_rmem_pressure(sk))
 			return true;
+		if (tcp_receive_window(tp) <= inet_csk(sk)->icsk_ack.rcv_mss)
+			return true;
 	}
 	if (sk->sk_prot->stream_memory_read)
 		return sk->sk_prot->stream_memory_read(sk);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index d285d67c0ef2..30b450ebaae0 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5294,7 +5294,8 @@ void tcp_data_ready(struct sock *sk)
 	int avail = tp->rcv_nxt - tp->copied_seq;
 
 	if (avail < sk->sk_rcvlowat && !tcp_rmem_pressure(sk) &&
-	    !sock_flag(sk, SOCK_DONE))
+	    !sock_flag(sk, SOCK_DONE) &&
+	    tcp_receive_window(tp) > inet_csk(sk)->icsk_ack.rcv_mss)
 		return;
 
 	DIRECT_CALL(sock, sk_data_ready, sk->sk_data_ready, sk);
-- 
2.29.0.rc2.309.g374f81d7ae-goog


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

* Re: [net] tcp: Prevent low rmem stalls with SO_RCVLOWAT.
  2020-10-23 17:48 [net] tcp: Prevent low rmem stalls with SO_RCVLOWAT Arjun Roy
@ 2020-10-23 18:31 ` Jakub Kicinski
  2020-10-23 18:49   ` Arjun Roy
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2020-10-23 18:31 UTC (permalink / raw)
  To: Arjun Roy; +Cc: davem, netdev, arjunroy, edumazet, soheil, ncardwell

On Fri, 23 Oct 2020 10:48:57 -0700 Arjun Roy wrote:
> From: Arjun Roy <arjunroy@google.com>
> 
> With SO_RCVLOWAT, under memory pressure,
> it is possible to enter a state where:
> 
> 1. We have not received enough bytes to satisfy SO_RCVLOWAT.
> 2. We have not entered buffer pressure (see tcp_rmem_pressure()).
> 3. But, we do not have enough buffer space to accept more packets.

Doesn't apply cleanly to net:

Applying: tcp: Prevent low rmem stalls with SO_RCVLOWAT.
error: sha1 information is lacking or useless (net/ipv4/tcp.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 tcp: Prevent low rmem stalls with SO_RCVLOWAT.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

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

* Re: [net] tcp: Prevent low rmem stalls with SO_RCVLOWAT.
  2020-10-23 18:31 ` Jakub Kicinski
@ 2020-10-23 18:49   ` Arjun Roy
  0 siblings, 0 replies; 3+ messages in thread
From: Arjun Roy @ 2020-10-23 18:49 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Arjun Roy, David Miller, netdev, Eric Dumazet,
	Soheil Hassas Yeganeh, Neal Cardwell

Acknowledged, I have rebased onto net master just now and I think that
should fix the sha1 information. v2 patch has been mailed. Sorry for
the error first time round :)

-Arjun

On Fri, Oct 23, 2020 at 11:31 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Fri, 23 Oct 2020 10:48:57 -0700 Arjun Roy wrote:
> > From: Arjun Roy <arjunroy@google.com>
> >
> > With SO_RCVLOWAT, under memory pressure,
> > it is possible to enter a state where:
> >
> > 1. We have not received enough bytes to satisfy SO_RCVLOWAT.
> > 2. We have not entered buffer pressure (see tcp_rmem_pressure()).
> > 3. But, we do not have enough buffer space to accept more packets.
>
> Doesn't apply cleanly to net:
>
> Applying: tcp: Prevent low rmem stalls with SO_RCVLOWAT.
> error: sha1 information is lacking or useless (net/ipv4/tcp.c).
> error: could not build fake ancestor
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> Patch failed at 0001 tcp: Prevent low rmem stalls with SO_RCVLOWAT.
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".

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

end of thread, other threads:[~2020-10-23 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 17:48 [net] tcp: Prevent low rmem stalls with SO_RCVLOWAT Arjun Roy
2020-10-23 18:31 ` Jakub Kicinski
2020-10-23 18:49   ` Arjun Roy

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).