From: Eric Dumazet <dada1@cosmosbay.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: Re: [RFC,PATCH] loopback: calls netif_receive_skb() instead of netif_rx()
Date: Sun, 23 Mar 2008 19:48:29 +0100 [thread overview]
Message-ID: <47E6A5FD.6060407@cosmosbay.com> (raw)
In-Reply-To: <20080323.032949.194309002.davem@davemloft.net>
[-- Attachment #1: Type: text/plain, Size: 2029 bytes --]
David Miller a écrit :
> From: Eric Dumazet <dada1@cosmosbay.com>
> Date: Sat, 01 Mar 2008 11:26:17 +0100
>
>> [PATCH] loopback: calls netif_receive_skb() instead of netif_rx()
>
> Eric, did you get a chance to kernel stack usage stress this
> thing out like I asked?
>
I noticed some paths in kernel are very stack aggressive, and on i386 with
CONFIG_4KSTACKS we were really in a dangerous land, even without my patch.
What we call 4K stacks is in fact 4K - sizeof(struct task_struct), so a litle
bit more than 2K. (not counting some insane configuration were struct
task_struct take 3.5 KB, see CONFIG_LATENCYTOP for an example)
So I cooked a different patch that explicitly test available stack space
instead of counting a depth value.
The problem is that this patch depends on CONFIG_STACK_GROWSUP and I had an
issue with it
(see http://kerneltrap.org/mailarchive/linux-kernel/2008/3/5/1079774)
and I had no answer from Kyle or others on this subject.
So I had to disable the optimisation for HPPA arch (it seems the only arch
that has CONFIG_STACK_GROWSUP)
[PATCH] loopback: calls netif_receive_skb() instead of netif_rx()
Loopback transmit function loopback_xmit() actually calls netif_rx() to queue
a skb to the softnet queue, and arms a softirq so that this skb can be handled
later.
This has a cost on SMP, because we need to hold a reference on the device, and
free this reference when softirq dequeues packet.
Following patch directly calls netif_receive_skb() and avoids lot of atomic
operations.
(atomic_inc(&dev->refcnt), set_and_set_bit(NAPI_STATE_SCHED, &n->state), ...
atomic_dec(&dev->refcnt)...), cache line ping-pongs on device refcnt, but also
softirq overhead.
This gives a nice boost on tbench for example (5 % on my machine)
We check available free stack space to take the decision of directly call
netif_receive_skb() or queue the packet for further softirq handling, when
stack space will be back to an acceptable level.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: loopback.patch --]
[-- Type: text/plain, Size: 991 bytes --]
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index f2a6e71..656e29c 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -126,6 +126,17 @@ static void emulate_large_send_offload(struct sk_buff *skb)
}
#endif /* LOOPBACK_TSO */
+static int enough_stack_space(void)
+{
+#ifdef CONFIG_STACK_GROWSUP
+ return 0;
+#else
+ unsigned long free = (unsigned long)&free -
+ (unsigned long)end_of_stack(current);
+ return free >= THREAD_SIZE/3 ;
+#endif
+}
+
/*
* The higher levels take care of making this non-reentrant (it's
* called with bh's disabled).
@@ -158,7 +169,14 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
lb_stats->bytes += skb->len;
lb_stats->packets++;
- netif_rx(skb);
+ /*
+ * We can call netif_receive_skb() instead of netif_rx()
+ * to speedup processing, but only if we have enough stack space.
+ */
+ if (enough_stack_space())
+ netif_receive_skb(skb);
+ else
+ netif_rx(skb);
return 0;
}
next prev parent reply other threads:[~2008-03-23 18:48 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-21 18:51 [RFC,PATCH] loopback: calls netif_receive_skb() instead of netif_rx() Eric Dumazet
2008-02-21 20:14 ` Daniel Lezcano
2008-02-21 23:19 ` Eric Dumazet
2008-02-22 10:19 ` Daniel Lezcano
2008-02-27 2:21 ` David Miller
2008-02-27 7:20 ` Jarek Poplawski
2008-02-27 7:23 ` David Miller
2008-02-27 7:34 ` Jarek Poplawski
2008-03-01 10:26 ` Eric Dumazet
2008-03-04 4:55 ` David Miller
2008-03-04 5:15 ` Stephen Hemminger
2008-03-04 6:27 ` Eric Dumazet
2008-03-23 10:29 ` David Miller
2008-03-23 18:48 ` Eric Dumazet [this message]
2008-03-23 19:15 ` Andi Kleen
2008-03-29 1:36 ` David Miller
2008-03-29 8:18 ` Eric Dumazet
2008-03-29 23:54 ` David Miller
2008-03-31 6:38 ` Eric Dumazet
2008-03-31 9:48 ` Ingo Molnar
2008-03-31 10:01 ` Eric Dumazet
2008-03-31 10:12 ` Ingo Molnar
2008-04-01 9:19 ` Eric Dumazet
2008-04-03 14:06 ` Pavel Machek
2008-04-03 16:19 ` Eric Dumazet
2008-03-31 10:08 ` David Miller
2008-03-31 10:44 ` Ingo Molnar
2008-03-31 11:02 ` David Miller
2008-03-31 11:36 ` poor network loopback performance and scalability (was: Re: [RFC,PATCH] loopback: calls netif_receive_skb() instead of netif_rx()) Ingo Molnar
2008-04-21 3:24 ` Herbert Xu
2008-04-21 3:38 ` poor network loopback performance and scalability David Miller
2008-04-21 8:11 ` Ingo Molnar
2008-04-21 8:16 ` David Miller
2008-04-21 10:19 ` Herbert Xu
2008-04-21 10:22 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47E6A5FD.6060407@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).