linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH linux-next] ns: do not allocate a new nsproxy at each call
@ 2013-10-15 17:35 Guillaume Gaudonville
  2013-10-15 18:40 ` Eric W. Biederman
  0 siblings, 1 reply; 12+ messages in thread
From: Guillaume Gaudonville @ 2013-10-15 17:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: ebiederm, serge.hallyn, akpm, viro, davem, cmetcalf,
	Guillaume Gaudonville

Currently, at each call of setns system call a new nsproxy is allocated,
the old nsproxy namespaces are copied into the new one and the old nsproxy
is freed if the task was the only one to use it.

It can creates large delays on hardware with large number of cpus since
to free a nsproxy a synchronize_rcu() call is done.

When a task is the only one to use a nsproxy, only the task can do an action
that will make this nsproxy to be shared by another task or thread (fork,...).
So when the refcount of the nsproxy is equal to 1, we can simply update the
current nsproxy field without allocating a new one and freeing the old one.

The install operations of each kind of namespace cannot fails, so there's no
need to check for an error and calling ops->install().

Tested on TileGX (36 cores) and Intel (32 cores).

Reported-by: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: Guillaume Gaudonville <guillaume.gaudonville@6wind.com>
---
 kernel/nsproxy.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index afc0456..afc04ac 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -255,6 +255,18 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
 	if (nstype && (ops->type != nstype))
 		goto out;
 
+	/*
+	 * If count == 1, only the current task can increment it,
+	 * by doing a fork for example so we can safely update the
+	 * current nsproxy pointers without allocate a new one,
+	 * update it and destroy the old one
+	 */
+	if (atomic_read(&tsk->nsproxy->count) == 1) {
+		err = ops->install(tsk->nsproxy, ei->ns);
+		fput(file);
+		return err;
+	}
+
 	new_nsproxy = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs);
 	if (IS_ERR(new_nsproxy)) {
 		err = PTR_ERR(new_nsproxy);
-- 
1.7.2.5


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

end of thread, other threads:[~2013-10-23  8:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-15 17:35 [RFC PATCH linux-next] ns: do not allocate a new nsproxy at each call Guillaume Gaudonville
2013-10-15 18:40 ` Eric W. Biederman
2013-10-16  8:48   ` Guillaume Gaudonville
2013-10-16 19:42     ` Eric W. Biederman
2013-10-18 14:46       ` [RFC PATCH linux-next v2] " Guillaume Gaudonville
2013-10-18 22:34         ` Eric W. Biederman
2013-10-22 15:52           ` Guillaume Gaudonville
2013-10-22 16:53             ` Paul E. McKenney
2013-10-22 18:47               ` Eric W. Biederman
2013-10-22 19:44                 ` Eric W. Biederman
2013-10-22 21:42                   ` Paul E. McKenney
2013-10-23  8:27                   ` Guillaume Gaudonville

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).