Skip to content

Commit

Permalink
add a kmem_cache for nsproxy objects
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Cedric Le Goater authored and Linus Torvalds committed Jul 16, 2007
1 parent 467e9f4 commit 98c0d07
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <linux/utsname.h>
#include <linux/pid_namespace.h>

static struct kmem_cache *nsproxy_cachep;

struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);

static inline void get_nsproxy(struct nsproxy *ns)
Expand All @@ -43,9 +45,11 @@ static inline struct nsproxy *clone_nsproxy(struct nsproxy *orig)
{
struct nsproxy *ns;

ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
if (ns)
ns = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
if (ns) {
memcpy(ns, orig, sizeof(struct nsproxy));
atomic_set(&ns->count, 1);
}
return ns;
}

Expand Down Expand Up @@ -109,7 +113,7 @@ static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
if (new_nsp->mnt_ns)
put_mnt_ns(new_nsp->mnt_ns);
out_ns:
kfree(new_nsp);
kmem_cache_free(nsproxy_cachep, new_nsp);
return ERR_PTR(err);
}

Expand Down Expand Up @@ -160,7 +164,7 @@ void free_nsproxy(struct nsproxy *ns)
put_pid_ns(ns->pid_ns);
if (ns->user_ns)
put_user_ns(ns->user_ns);
kfree(ns);
kmem_cache_free(nsproxy_cachep, ns);
}

/*
Expand All @@ -185,3 +189,12 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
err = PTR_ERR(*new_nsp);
return err;
}

static int __init nsproxy_cache_init(void)
{
nsproxy_cachep = kmem_cache_create("nsproxy", sizeof(struct nsproxy),
0, SLAB_PANIC, NULL, NULL);
return 0;
}

module_init(nsproxy_cache_init);

0 comments on commit 98c0d07

Please sign in to comment.