]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
nsproxy: move free_nsproxy() out of do_exit() path
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Sat, 21 Jul 2012 00:55:01 +0000 (10:55 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 25 Jul 2012 03:53:23 +0000 (13:53 +1000)
free_nsproxy() is too heavy to be on the exit path.  Let's free namespaces
asynchronously to not block exit_group() syscall.

Microbenchmark:

: #define _GNU_SOURCE
: #include <unistd.h>
: #include <sched.h>
: #include <stdlib.h>
: #include <sys/wait.h>
:
: int
: main(void)
: {
:       int i;
:       for (i = 0; i < 1024; i++) {
:               if (fork()) {
:                       wait(NULL);
:                       continue;
:               }
:               unshare(CLONE_NEWIPC);
:               exit(0);
:       }
:       return 0;
: }

Before the patch:

real    0m8.335s
user    0m0.000s
sys     0m0.265s

After:

real    0m0.569s
user    0m0.001s
sys     0m0.154s

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: "Dmitry V. Levin" <ldv@altlinux.org>
Cc: Pavel Emelyanov <xemul@openvz.org>
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Doug Ledford <dledford@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/nsproxy.h
kernel/nsproxy.c

index cc37a55ad004391597661e13071f3c6e1c708c19..1d26be717d3a065aa19ff53c61925e04125aa60a 100644 (file)
@@ -24,6 +24,7 @@ struct fs_struct;
  */
 struct nsproxy {
        atomic_t count;
+       struct work_struct free_nsproxy_work;
        struct uts_namespace *uts_ns;
        struct ipc_namespace *ipc_ns;
        struct mnt_namespace *mnt_ns;
index b576f7f14bc6957fdf04ba0324f7416f78995c6a..ebc7d400157634b086fc36fca8af3be59bdcbad6 100644 (file)
@@ -41,13 +41,17 @@ struct nsproxy init_nsproxy = {
 #endif
 };
 
+static void free_nsproxy_work(struct work_struct *work);
+
 static inline struct nsproxy *create_nsproxy(void)
 {
        struct nsproxy *nsproxy;
 
        nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
-       if (nsproxy)
+       if (nsproxy) {
                atomic_set(&nsproxy->count, 1);
+               INIT_WORK(&nsproxy->free_nsproxy_work, free_nsproxy_work);
+       }
        return nsproxy;
 }
 
@@ -166,6 +170,14 @@ out:
 
 void free_nsproxy(struct nsproxy *ns)
 {
+       /*
+        * wait for others to get what they want from this nsproxy.
+        *
+        * cannot release this nsproxy via the call_rcu() since
+        * put_mnt_ns() will want to sleep
+        */
+       synchronize_rcu();
+
        if (ns->mnt_ns)
                put_mnt_ns(ns->mnt_ns);
        if (ns->uts_ns)
@@ -178,6 +190,14 @@ void free_nsproxy(struct nsproxy *ns)
        kmem_cache_free(nsproxy_cachep, ns);
 }
 
+static void free_nsproxy_work(struct work_struct *work)
+{
+       struct nsproxy *ns = container_of(work, struct nsproxy,
+                       free_nsproxy_work);
+
+       free_nsproxy(ns);
+}
+
 /*
  * Called from unshare. Unshare all the namespaces part of nsproxy.
  * On success, returns the new nsproxy.
@@ -215,16 +235,8 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new)
 
        rcu_assign_pointer(p->nsproxy, new);
 
-       if (ns && atomic_dec_and_test(&ns->count)) {
-               /*
-                * wait for others to get what they want from this nsproxy.
-                *
-                * cannot release this nsproxy via the call_rcu() since
-                * put_mnt_ns() will want to sleep
-                */
-               synchronize_rcu();
-               free_nsproxy(ns);
-       }
+       if (ns && atomic_dec_and_test(&ns->count))
+               schedule_work(&ns->free_nsproxy_work);
 }
 
 void exit_task_namespaces(struct task_struct *p)