From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946009Ab2EKRvM (ORCPT ); Fri, 11 May 2012 13:51:12 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:19874 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1945930Ab2EKRvG (ORCPT ); Fri, 11 May 2012 13:51:06 -0400 From: Glauber Costa To: Cc: , , , Tejun Heo , Li Zefan , Greg Thelen , Suleiman Souhlal , Michal Hocko , Johannes Weiner , , Glauber Costa , Christoph Lameter , Pekka Enberg Subject: [PATCH v2 16/29] slub: create duplicate cache Date: Fri, 11 May 2012 14:44:18 -0300 Message-Id: <1336758272-24284-17-git-send-email-glommer@parallels.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1336758272-24284-1-git-send-email-glommer@parallels.com> References: <1336758272-24284-1-git-send-email-glommer@parallels.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch provides kmem_cache_dup(), that duplicates a cache for a memcg, preserving its creation properties. Object size, alignment and flags are all respected. When a duplicate cache is created, the parent cache cannot be destructed during the child lifetime. To assure this, its reference count is increased if the cache creation succeeds. Signed-off-by: Glauber Costa CC: Christoph Lameter CC: Pekka Enberg CC: Michal Hocko CC: Kamezawa Hiroyuki CC: Johannes Weiner CC: Suleiman Souhlal --- include/linux/memcontrol.h | 2 ++ include/linux/slab.h | 2 ++ mm/memcontrol.c | 17 +++++++++++++++++ mm/slub.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 0 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 99e14b9..f93021a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -445,6 +445,8 @@ int memcg_css_id(struct mem_cgroup *memcg); void mem_cgroup_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s); void mem_cgroup_release_cache(struct kmem_cache *cachep); +extern char *mem_cgroup_cache_name(struct mem_cgroup *memcg, + struct kmem_cache *cachep); #else static inline void mem_cgroup_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s) diff --git a/include/linux/slab.h b/include/linux/slab.h index 1386650..e73ef71 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -322,6 +322,8 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long); #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM #define MAX_KMEM_CACHE_TYPES 400 +extern struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, + struct kmem_cache *cachep); #else #define MAX_KMEM_CACHE_TYPES 0 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9327996..a8171cb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -467,6 +467,23 @@ struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) EXPORT_SYMBOL(tcp_proto_cgroup); #endif /* CONFIG_INET */ +char *mem_cgroup_cache_name(struct mem_cgroup *memcg, struct kmem_cache *cachep) +{ + char *name; + struct dentry *dentry; + + rcu_read_lock(); + dentry = rcu_dereference(memcg->css.cgroup->dentry); + rcu_read_unlock(); + + BUG_ON(dentry == NULL); + + name = kasprintf(GFP_KERNEL, "%s(%d:%s)", + cachep->name, css_id(&memcg->css), dentry->d_name.name); + + return name; +} + struct ida cache_types; void mem_cgroup_register_cache(struct mem_cgroup *memcg, diff --git a/mm/slub.c b/mm/slub.c index 1698371..9b21b38 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4034,6 +4034,37 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, } EXPORT_SYMBOL(kmem_cache_create); +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, + struct kmem_cache *s) +{ + char *name; + struct kmem_cache *new; + + name = mem_cgroup_cache_name(memcg, s); + if (!name) + return NULL; + + new = kmem_cache_create_memcg(memcg, name, s->objsize, s->align, + (s->allocflags & ~SLAB_PANIC), s->ctor); + + /* + * We increase the reference counter in the parent cache, to + * prevent it from being deleted. If kmem_cache_destroy() is + * called for the root cache before we call it for a child cache, + * it will be queued for destruction when we finally drop the + * reference on the child cache. + */ + if (new) { + down_write(&slub_lock); + s->refcount++; + up_write(&slub_lock); + } + kfree(name); + return new; +} +#endif + #ifdef CONFIG_SMP /* * Use the cpu notifier to insure that the cpu slabs are flushed when -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx130.postini.com [74.125.245.130]) by kanga.kvack.org (Postfix) with SMTP id 4161E8D0017 for ; Fri, 11 May 2012 13:49:57 -0400 (EDT) From: Glauber Costa Subject: [PATCH v2 16/29] slub: create duplicate cache Date: Fri, 11 May 2012 14:44:18 -0300 Message-Id: <1336758272-24284-17-git-send-email-glommer@parallels.com> In-Reply-To: <1336758272-24284-1-git-send-email-glommer@parallels.com> References: <1336758272-24284-1-git-send-email-glommer@parallels.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, kamezawa.hiroyu@jp.fujitsu.com, Tejun Heo , Li Zefan , Greg Thelen , Suleiman Souhlal , Michal Hocko , Johannes Weiner , devel@openvz.org, Glauber Costa , Christoph Lameter , Pekka Enberg This patch provides kmem_cache_dup(), that duplicates a cache for a memcg, preserving its creation properties. Object size, alignment and flags are all respected. When a duplicate cache is created, the parent cache cannot be destructed during the child lifetime. To assure this, its reference count is increased if the cache creation succeeds. Signed-off-by: Glauber Costa CC: Christoph Lameter CC: Pekka Enberg CC: Michal Hocko CC: Kamezawa Hiroyuki CC: Johannes Weiner CC: Suleiman Souhlal --- include/linux/memcontrol.h | 2 ++ include/linux/slab.h | 2 ++ mm/memcontrol.c | 17 +++++++++++++++++ mm/slub.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 0 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 99e14b9..f93021a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -445,6 +445,8 @@ int memcg_css_id(struct mem_cgroup *memcg); void mem_cgroup_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s); void mem_cgroup_release_cache(struct kmem_cache *cachep); +extern char *mem_cgroup_cache_name(struct mem_cgroup *memcg, + struct kmem_cache *cachep); #else static inline void mem_cgroup_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s) diff --git a/include/linux/slab.h b/include/linux/slab.h index 1386650..e73ef71 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -322,6 +322,8 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long); #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM #define MAX_KMEM_CACHE_TYPES 400 +extern struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, + struct kmem_cache *cachep); #else #define MAX_KMEM_CACHE_TYPES 0 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9327996..a8171cb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -467,6 +467,23 @@ struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) EXPORT_SYMBOL(tcp_proto_cgroup); #endif /* CONFIG_INET */ +char *mem_cgroup_cache_name(struct mem_cgroup *memcg, struct kmem_cache *cachep) +{ + char *name; + struct dentry *dentry; + + rcu_read_lock(); + dentry = rcu_dereference(memcg->css.cgroup->dentry); + rcu_read_unlock(); + + BUG_ON(dentry == NULL); + + name = kasprintf(GFP_KERNEL, "%s(%d:%s)", + cachep->name, css_id(&memcg->css), dentry->d_name.name); + + return name; +} + struct ida cache_types; void mem_cgroup_register_cache(struct mem_cgroup *memcg, diff --git a/mm/slub.c b/mm/slub.c index 1698371..9b21b38 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4034,6 +4034,37 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, } EXPORT_SYMBOL(kmem_cache_create); +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, + struct kmem_cache *s) +{ + char *name; + struct kmem_cache *new; + + name = mem_cgroup_cache_name(memcg, s); + if (!name) + return NULL; + + new = kmem_cache_create_memcg(memcg, name, s->objsize, s->align, + (s->allocflags & ~SLAB_PANIC), s->ctor); + + /* + * We increase the reference counter in the parent cache, to + * prevent it from being deleted. If kmem_cache_destroy() is + * called for the root cache before we call it for a child cache, + * it will be queued for destruction when we finally drop the + * reference on the child cache. + */ + if (new) { + down_write(&slub_lock); + s->refcount++; + up_write(&slub_lock); + } + kfree(name); + return new; +} +#endif + #ifdef CONFIG_SMP /* * Use the cpu notifier to insure that the cpu slabs are flushed when -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Glauber Costa Subject: [PATCH v2 16/29] slub: create duplicate cache Date: Fri, 11 May 2012 14:44:18 -0300 Message-ID: <1336758272-24284-17-git-send-email-glommer@parallels.com> References: <1336758272-24284-1-git-send-email-glommer@parallels.com> Return-path: In-Reply-To: <1336758272-24284-1-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org, Tejun Heo , Li Zefan , Greg Thelen , Suleiman Souhlal , Michal Hocko , Johannes Weiner , devel-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org, Glauber Costa , Christoph Lameter , Pekka Enberg This patch provides kmem_cache_dup(), that duplicates a cache for a memcg, preserving its creation properties. Object size, alignment and flags are all respected. When a duplicate cache is created, the parent cache cannot be destructed during the child lifetime. To assure this, its reference count is increased if the cache creation succeeds. Signed-off-by: Glauber Costa CC: Christoph Lameter CC: Pekka Enberg CC: Michal Hocko CC: Kamezawa Hiroyuki CC: Johannes Weiner CC: Suleiman Souhlal --- include/linux/memcontrol.h | 2 ++ include/linux/slab.h | 2 ++ mm/memcontrol.c | 17 +++++++++++++++++ mm/slub.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 0 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 99e14b9..f93021a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -445,6 +445,8 @@ int memcg_css_id(struct mem_cgroup *memcg); void mem_cgroup_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s); void mem_cgroup_release_cache(struct kmem_cache *cachep); +extern char *mem_cgroup_cache_name(struct mem_cgroup *memcg, + struct kmem_cache *cachep); #else static inline void mem_cgroup_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s) diff --git a/include/linux/slab.h b/include/linux/slab.h index 1386650..e73ef71 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -322,6 +322,8 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long); #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM #define MAX_KMEM_CACHE_TYPES 400 +extern struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, + struct kmem_cache *cachep); #else #define MAX_KMEM_CACHE_TYPES 0 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9327996..a8171cb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -467,6 +467,23 @@ struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) EXPORT_SYMBOL(tcp_proto_cgroup); #endif /* CONFIG_INET */ +char *mem_cgroup_cache_name(struct mem_cgroup *memcg, struct kmem_cache *cachep) +{ + char *name; + struct dentry *dentry; + + rcu_read_lock(); + dentry = rcu_dereference(memcg->css.cgroup->dentry); + rcu_read_unlock(); + + BUG_ON(dentry == NULL); + + name = kasprintf(GFP_KERNEL, "%s(%d:%s)", + cachep->name, css_id(&memcg->css), dentry->d_name.name); + + return name; +} + struct ida cache_types; void mem_cgroup_register_cache(struct mem_cgroup *memcg, diff --git a/mm/slub.c b/mm/slub.c index 1698371..9b21b38 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4034,6 +4034,37 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, } EXPORT_SYMBOL(kmem_cache_create); +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, + struct kmem_cache *s) +{ + char *name; + struct kmem_cache *new; + + name = mem_cgroup_cache_name(memcg, s); + if (!name) + return NULL; + + new = kmem_cache_create_memcg(memcg, name, s->objsize, s->align, + (s->allocflags & ~SLAB_PANIC), s->ctor); + + /* + * We increase the reference counter in the parent cache, to + * prevent it from being deleted. If kmem_cache_destroy() is + * called for the root cache before we call it for a child cache, + * it will be queued for destruction when we finally drop the + * reference on the child cache. + */ + if (new) { + down_write(&slub_lock); + s->refcount++; + up_write(&slub_lock); + } + kfree(name); + return new; +} +#endif + #ifdef CONFIG_SMP /* * Use the cpu notifier to insure that the cpu slabs are flushed when -- 1.7.7.6