All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] tcp: ensure epoll edge trigger wakeup when write queue is empty
@ 2015-05-20 15:52 Jason Baron
  2015-05-20 17:09 ` Eric Dumazet
  2015-05-21 22:53 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Baron @ 2015-05-20 15:52 UTC (permalink / raw)
  To: davem; +Cc: eric.dumazet, netdev

From: Jason Baron <jbaron@akamai.com>

We currently rely on the setting of SOCK_NOSPACE in the write()
path to ensure that we wake up any epoll edge trigger waiters when
acks return to free space in the write queue. However, if we fail
to allocate even a single skb in the write queue, we could end up
waiting indefinitely.

Fix this by explicitly issuing a wakeup when we detect the condition
of an empty write queue and a return value of -EAGAIN. This allows
userspace to re-try as we expect this to be a temporary failure.

I've tested this approach by artificially making
sk_stream_alloc_skb() return NULL periodically. In that case,
epoll edge trigger waiters will hang indefinitely in epoll_wait()
without this patch.

Signed-off-by: Jason Baron <jbaron@akamai.com>
---
v2:
- ensure it compiles :)

 net/ipv4/tcp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index c724195..6247c24 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -997,6 +997,9 @@ do_error:
 	if (copied)
 		goto out;
 out_err:
+	/* make sure we wake any epoll edge trigger waiter */
+	if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 && err == -EAGAIN))
+		sk->sk_write_space(sk);
 	return sk_stream_error(sk, flags, err);
 }
 
@@ -1285,6 +1288,9 @@ do_error:
 		goto out;
 out_err:
 	err = sk_stream_error(sk, flags, err);
+	/* make sure we wake any epoll edge trigger waiter */
+	if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 && err == -EAGAIN))
+		sk->sk_write_space(sk);
 	release_sock(sk);
 	return err;
 }
-- 
1.8.2.rc2

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

* Re: [PATCH net-next v2] tcp: ensure epoll edge trigger wakeup when write queue is empty
  2015-05-20 15:52 [PATCH net-next v2] tcp: ensure epoll edge trigger wakeup when write queue is empty Jason Baron
@ 2015-05-20 17:09 ` Eric Dumazet
  2015-05-21 22:53 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2015-05-20 17:09 UTC (permalink / raw)
  To: Jason Baron; +Cc: davem, netdev

On Wed, 2015-05-20 at 15:52 +0000, Jason Baron wrote:
> From: Jason Baron <jbaron@akamai.com>
> 
> We currently rely on the setting of SOCK_NOSPACE in the write()
> path to ensure that we wake up any epoll edge trigger waiters when
> acks return to free space in the write queue. However, if we fail
> to allocate even a single skb in the write queue, we could end up
> waiting indefinitely.
> 
> Fix this by explicitly issuing a wakeup when we detect the condition
> of an empty write queue and a return value of -EAGAIN. This allows
> userspace to re-try as we expect this to be a temporary failure.
> 
> I've tested this approach by artificially making
> sk_stream_alloc_skb() return NULL periodically. In that case,
> epoll edge trigger waiters will hang indefinitely in epoll_wait()
> without this patch.
> 
> Signed-off-by: Jason Baron <jbaron@akamai.com>
> ---

Acked-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH net-next v2] tcp: ensure epoll edge trigger wakeup when write queue is empty
  2015-05-20 15:52 [PATCH net-next v2] tcp: ensure epoll edge trigger wakeup when write queue is empty Jason Baron
  2015-05-20 17:09 ` Eric Dumazet
@ 2015-05-21 22:53 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-05-21 22:53 UTC (permalink / raw)
  To: jbaron; +Cc: eric.dumazet, netdev

From: Jason Baron <jbaron@akamai.com>
Date: Wed, 20 May 2015 15:52:53 +0000 (GMT)

> From: Jason Baron <jbaron@akamai.com>
> 
> We currently rely on the setting of SOCK_NOSPACE in the write()
> path to ensure that we wake up any epoll edge trigger waiters when
> acks return to free space in the write queue. However, if we fail
> to allocate even a single skb in the write queue, we could end up
> waiting indefinitely.
> 
> Fix this by explicitly issuing a wakeup when we detect the condition
> of an empty write queue and a return value of -EAGAIN. This allows
> userspace to re-try as we expect this to be a temporary failure.
> 
> I've tested this approach by artificially making
> sk_stream_alloc_skb() return NULL periodically. In that case,
> epoll edge trigger waiters will hang indefinitely in epoll_wait()
> without this patch.
> 
> Signed-off-by: Jason Baron <jbaron@akamai.com>
> ---
> v2:
> - ensure it compiles :)

Applied, thanks Jason :)

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

end of thread, other threads:[~2015-05-21 22:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20 15:52 [PATCH net-next v2] tcp: ensure epoll edge trigger wakeup when write queue is empty Jason Baron
2015-05-20 17:09 ` Eric Dumazet
2015-05-21 22:53 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.