Patchwork tun: Only wake up writers

login
register
mail settings
Submitter Herbert Xu
Date June 3, 2009, 12:36 p.m.
Message ID <20090603123655.GA13916@gondor.apana.org.au>
Download mbox | patch
Permalink /patch/28057/
State Accepted
Delegated to: David Miller
Headers show

Comments

Herbert Xu - June 3, 2009, 12:36 p.m.
On Wed, Jun 03, 2009 at 01:33:03PM +1000, Herbert Xu wrote:
> 
> tun: Only wake up writers
> 
> Recently net/core/sock.c was updated so that when we free an skb
> that has been transmitted we only wake up writers instead of waking
> up both readers and writers.
> 
> This patch does the same thing for tun as this code is identical
> to that in net/core/sock.c
> 
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Scratch that.  It doesn't actually work because our poll(2) doesn't
use this extra info.  Here's a patch that actually works:

tun: Only wake up writers

When I added socket accounting to tun I inadvertently introduced
spurious wake-up events that kills qemu performance.  The problem
occurs when qemu polls on the tun fd for read, and then transmits
packets.  For each packet transmitted, we will wake up qemu even
if it only cares about read events.

Now this affects all sockets, but it is only a new problem for
tun.  So this patch tries to fix it for tun first and we can then
look at the problem in general.
 
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>


Thanks,
David Miller - June 4, 2009, 4:46 a.m.
From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 3 Jun 2009 22:36:55 +1000

> tun: Only wake up writers
> 
> When I added socket accounting to tun I inadvertently introduced
> spurious wake-up events that kills qemu performance.  The problem
> occurs when qemu polls on the tun fd for read, and then transmits
> packets.  For each packet transmitted, we will wake up qemu even
> if it only cares about read events.
> 
> Now this affects all sockets, but it is only a new problem for
> tun.  So this patch tries to fix it for tun first and we can then
> look at the problem in general.
>  
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Applied to net-next-2.6, thanks Herbert!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 735bf41..eeb8af5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -840,12 +840,12 @@  static void tun_sock_write_space(struct sock *sk)
 	if (!sock_writeable(sk))
 		return;
 
-	if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
-		wake_up_interruptible_sync(sk->sk_sleep);
-
 	if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags))
 		return;
 
+	if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
+		wake_up_interruptible_sync(sk->sk_sleep);
+
 	tun = container_of(sk, struct tun_sock, sk)->tun;
 	kill_fasync(&tun->fasync, SIGIO, POLL_OUT);
 }