From: Octavian Purdila <opurdila@ixiacom.com>
To: netdev@vger.kernel.org
Subject: Re: [net-next-2.6 PATCH] net: fast consecutive name allocation
Date: Fri, 13 Nov 2009 07:20:19 +0200 [thread overview]
Message-ID: <200911130720.19671.opurdila@ixiacom.com> (raw)
In-Reply-To: <200911130701.14847.opurdila@ixiacom.com>
On Friday 13 November 2009 07:01:14 you wrote:
> This patch speeds up the network device name allocation for the case
> where a significant number of devices of the same type are created
> consecutively.
>
> Tests performed on a PPC750 @ 800Mhz machine with per device sysctl
> and sysfs entries disabled:
>
> Without the patch With the patch
>
> real 0m 43.43s real 0m 0.49s
> user 0m 0.00s user 0m 0.00s
> sys 0m 43.43s sys 0m 0.48s
>
Oops, pasting root prompts (e.g. # modprobe ....) directly into the git commit message is not a good idea :) Here it is again, with the full commit message.
[net-next-2.6 PATCH] net: fast consecutive name allocation
This patch speeds up the network device name allocation for the case
where a significant number of devices of the same type are created
consecutively.
Tests performed on a PPC750 @ 800Mhz machine with per device sysctl
and sysfs entries disabled:
$ time insmod /lib/modules/dummy.ko numdummies=8000
Without the patch With the patch
real 0m 43.43s real 0m 0.49s
user 0m 0.00s user 0m 0.00s
sys 0m 43.43s sys 0m 0.48s
Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
---
include/net/net_namespace.h | 3 +++
net/core/dev.c | 23 ++++++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 0addd45..39c65a2 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -56,6 +56,9 @@ struct net {
struct list_head dev_base_head;
struct hlist_head *dev_name_head;
struct hlist_head *dev_index_head;
+ /* fast consecutive name allocation (e.g. eth0, eth1, ...) */
+ char fcna_name[IFNAMSIZ];
+ int fcna_no;
/* core fib_rules */
struct list_head rules_ops;
diff --git a/net/core/dev.c b/net/core/dev.c
index ad8e320..008e3c7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -226,8 +226,12 @@ static int list_netdevice(struct net_device *dev)
*/
static void unlist_netdevice(struct net_device *dev)
{
+ struct net *net = dev_net(dev);
+
ASSERT_RTNL();
+ net->fcna_no = -1;
+
/* Unlink dev from the device chain */
write_lock_bh(&dev_base_lock);
list_del_rcu(&dev->dev_list);
@@ -872,6 +876,16 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
if (p[1] != 'd' || strchr(p + 2, '%'))
return -EINVAL;
+ /* avoid fast allocation for strange templates like "fan%dcy" */
+ if (net->fcna_no >= 0 && p[2] == 0 &&
+ net->fcna_name[p - name] == 0 &&
+ memcmp(name, net->fcna_name, p - name) == 0) {
+ snprintf(buf, IFNAMSIZ, name, ++net->fcna_no);
+ if (!__dev_get_by_name(net, buf))
+ return net->fcna_no;
+ net->fcna_no = -1;
+ }
+
/* Use one page as a bit array of possible slots */
inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
if (!inuse)
@@ -894,8 +908,15 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
}
snprintf(buf, IFNAMSIZ, name, i);
- if (!__dev_get_by_name(net, buf))
+ if (!__dev_get_by_name(net, buf)) {
+ if (p[2] == 0) {
+ memcpy(net->fcna_name, name, p - name);
+ net->fcna_name[p - name] = 0;
+ net->fcna_no = i;
+ } else
+ net->fcna_no = -1;
return i;
+ }
/* It is possible to run out of possible slots
* when the name is long and there isn't enough space left
--
1.5.6.5
next prev parent reply other threads:[~2009-11-13 5:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-13 5:01 [net-next-2.6 PATCH] net: fast consecutive name allocation Octavian Purdila
2009-11-13 5:20 ` Octavian Purdila [this message]
2009-11-13 6:12 ` Eric Dumazet
2009-11-13 6:26 ` Stephen Hemminger
2009-11-13 7:09 ` Eric Dumazet
2009-11-13 9:51 ` Octavian Purdila
2009-11-13 22:29 ` Stephen Hemminger
2009-11-13 22:40 ` Benjamin LaHaise
2009-11-13 22:49 ` Stephen Hemminger
2009-11-13 23:35 ` Benjamin LaHaise
2009-11-13 23:39 ` Stephen Hemminger
2009-11-13 23:52 ` Benjamin LaHaise
2009-11-14 2:59 ` David Miller
2009-11-14 6:24 ` Benjamin LaHaise
2009-11-14 22:36 ` Mark Smith
2009-11-15 1:22 ` Stephen Hemminger
2009-11-15 1:49 ` Mark Smith
2009-11-15 1:55 ` Denys Fedoryschenko
2009-11-15 7:48 ` Eric Dumazet
2009-11-15 16:50 ` Benjamin LaHaise
2009-11-14 7:08 ` Benny Amorsen
2009-11-14 7:21 ` Eric Dumazet
2009-11-14 16:16 ` Ben Greear
2009-11-13 9:55 ` Octavian Purdila
2009-11-13 16:40 ` Ben Greear
2009-11-14 0:04 ` Stephen Hemminger
2009-11-14 0:14 ` Octavian Purdila
2009-11-14 0:20 ` Stephen Hemminger
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=200911130720.19671.opurdila@ixiacom.com \
--to=opurdila@ixiacom.com \
--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).