All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Aksola <aakso@iki.fi>
To: netdev@vger.kernel.org
Cc: nicolas.dichtel@6wind.com
Subject: [PATCH v2] iproute2: build nsid-name cache only for commands that need it
Date: Fri, 16 Sep 2016 07:22:29 +0000	[thread overview]
Message-ID: <20160916072225.GA10536@toys.tundra.dog-lvm.novalocal> (raw)

The calling of netns_map_init() before command parsing introduced
a performance issue with large number of namespaces.

As commands such as add, del and exec do not need to iterate through
/var/run/netns it would be good not no build the cache before executing
these commands.

Example:
unpatched:
time seq 1 1000 | xargs -n 1 ip netns add

real    0m16.832s
user    0m1.350s
sys    0m15.029s

patched:
time seq 1 1000 | xargs -n 1 ip netns add

real    0m3.859s
user    0m0.132s
sys    0m3.205s

Signed-off-by: Anton Aksola <aakso@iki.fi>
---
 ip/ipnetns.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index af87065..564d034 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -775,17 +775,21 @@ static int netns_monitor(int argc, char **argv)
 
 int do_netns(int argc, char **argv)
 {
-	netns_map_init();
-
-	if (argc < 1)
+	if (argc < 1) {
+		netns_map_init();
 		return netns_list(0, NULL);
+	}
 
 	if ((matches(*argv, "list") == 0) || (matches(*argv, "show") == 0) ||
-	    (matches(*argv, "lst") == 0))
+	    (matches(*argv, "lst") == 0)) {
+		netns_map_init();
 		return netns_list(argc-1, argv+1);
+	}
 
-	if ((matches(*argv, "list-id") == 0))
+	if ((matches(*argv, "list-id") == 0)) {
+		netns_map_init();
 		return netns_list_id(argc-1, argv+1);
+	}
 
 	if (matches(*argv, "help") == 0)
 		return usage();
-- 
1.8.3.1

             reply	other threads:[~2016-09-16  7:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-16  7:22 Anton Aksola [this message]
2016-09-16  9:13 ` [PATCH v2] iproute2: build nsid-name cache only for commands that need it Nicolas Dichtel
2016-09-16  9:23   ` Vadim Kochan
2016-09-16  9:44     ` Nicolas Dichtel
     [not found]       ` <CAAL2ahKKFWcxhA=k+=3Td8sb-upnRUFs373EOhkHDaxvcgYjOw@mail.gmail.com>
2016-09-16 11:25         ` Vadim Kochan
2016-09-16 12:02           ` Anton Aksola
2016-09-16 13:18   ` Anton Aksola
2016-09-16 15:43     ` Nicolas Dichtel

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=20160916072225.GA10536@toys.tundra.dog-lvm.novalocal \
    --to=aakso@iki.fi \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    /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 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.