Commit 98c0d07cbf2a8582a0341b05ad564247e608f6f9

Authored by Cedric Le Goater
Committed by Linus Torvalds
1 parent 467e9f4b50

add a kmem_cache for nsproxy objects

It should improve performance in some scenarii where a lot of
these nsproxy objects are created by unsharing namespaces. This is
a typical use of virtual servers that are being created or entered.

This is also a good tool to find leaks and gather statistics on
namespace usage.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Pavel Emelianov <xemul@openvz.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 17 additions and 4 deletions Side-by-side Diff

... ... @@ -21,6 +21,8 @@
21 21 #include <linux/utsname.h>
22 22 #include <linux/pid_namespace.h>
23 23  
  24 +static struct kmem_cache *nsproxy_cachep;
  25 +
24 26 struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
25 27  
26 28 static inline void get_nsproxy(struct nsproxy *ns)
27 29  
... ... @@ -43,9 +45,11 @@
43 45 {
44 46 struct nsproxy *ns;
45 47  
46   - ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
47   - if (ns)
  48 + ns = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
  49 + if (ns) {
  50 + memcpy(ns, orig, sizeof(struct nsproxy));
48 51 atomic_set(&ns->count, 1);
  52 + }
49 53 return ns;
50 54 }
51 55  
... ... @@ -109,7 +113,7 @@
109 113 if (new_nsp->mnt_ns)
110 114 put_mnt_ns(new_nsp->mnt_ns);
111 115 out_ns:
112   - kfree(new_nsp);
  116 + kmem_cache_free(nsproxy_cachep, new_nsp);
113 117 return ERR_PTR(err);
114 118 }
115 119  
... ... @@ -160,7 +164,7 @@
160 164 put_pid_ns(ns->pid_ns);
161 165 if (ns->user_ns)
162 166 put_user_ns(ns->user_ns);
163   - kfree(ns);
  167 + kmem_cache_free(nsproxy_cachep, ns);
164 168 }
165 169  
166 170 /*
... ... @@ -185,4 +189,13 @@
185 189 err = PTR_ERR(*new_nsp);
186 190 return err;
187 191 }
  192 +
  193 +static int __init nsproxy_cache_init(void)
  194 +{
  195 + nsproxy_cachep = kmem_cache_create("nsproxy", sizeof(struct nsproxy),
  196 + 0, SLAB_PANIC, NULL, NULL);
  197 + return 0;
  198 +}
  199 +
  200 +module_init(nsproxy_cache_init);