aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
authorGlauber Costa <glommer@parallels.com>2012-12-18 17:22:34 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-18 18:02:13 -0500
commit2633d7a028239a738b793be5ca8fa6ac312f5793 (patch)
tree48a9f157b2c2a8218611aaade9667cacc2e018ec /mm/slub.c
parent6ccfb5bcf52bcf100fa085946f044fdbba015048 (diff)
slab/slub: consider a memcg parameter in kmem_create_cache
Allow a memcg parameter to be passed during cache creation. When the slub allocator is being used, it will only merge caches that belong to the same memcg. We'll do this by scanning the global list, and then translating the cache to a memcg-specific cache Default function is created as a wrapper, passing NULL to the memcg version. We only merge caches that belong to the same memcg. A helper is provided, memcg_css_id: because slub needs a unique cache name for sysfs. Since this is visible, but not the canonical location for slab data, the cache name is not used, the css_id should suffice. Signed-off-by: Glauber Costa <glommer@parallels.com> Cc: Christoph Lameter <cl@linux.com> Cc: David Rientjes <rientjes@google.com> Cc: Frederic Weisbecker <fweisbec@redhat.com> Cc: Greg Thelen <gthelen@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: JoonSoo Kim <js1304@gmail.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: Michal Hocko <mhocko@suse.cz> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Cc: Rik van Riel <riel@redhat.com> Cc: Suleiman Souhlal <suleiman@google.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/mm/slub.c b/mm/slub.c
index 87f9f32bf0cd..985332b38852 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -31,6 +31,7 @@
31#include <linux/fault-inject.h> 31#include <linux/fault-inject.h>
32#include <linux/stacktrace.h> 32#include <linux/stacktrace.h>
33#include <linux/prefetch.h> 33#include <linux/prefetch.h>
34#include <linux/memcontrol.h>
34 35
35#include <trace/events/kmem.h> 36#include <trace/events/kmem.h>
36 37
@@ -3786,7 +3787,7 @@ static int slab_unmergeable(struct kmem_cache *s)
3786 return 0; 3787 return 0;
3787} 3788}
3788 3789
3789static struct kmem_cache *find_mergeable(size_t size, 3790static struct kmem_cache *find_mergeable(struct mem_cgroup *memcg, size_t size,
3790 size_t align, unsigned long flags, const char *name, 3791 size_t align, unsigned long flags, const char *name,
3791 void (*ctor)(void *)) 3792 void (*ctor)(void *))
3792{ 3793{
@@ -3822,17 +3823,21 @@ static struct kmem_cache *find_mergeable(size_t size,
3822 if (s->size - size >= sizeof(void *)) 3823 if (s->size - size >= sizeof(void *))
3823 continue; 3824 continue;
3824 3825
3826 if (!cache_match_memcg(s, memcg))
3827 continue;
3828
3825 return s; 3829 return s;
3826 } 3830 }
3827 return NULL; 3831 return NULL;
3828} 3832}
3829 3833
3830struct kmem_cache *__kmem_cache_alias(const char *name, size_t size, 3834struct kmem_cache *
3831 size_t align, unsigned long flags, void (*ctor)(void *)) 3835__kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
3836 size_t align, unsigned long flags, void (*ctor)(void *))
3832{ 3837{
3833 struct kmem_cache *s; 3838 struct kmem_cache *s;
3834 3839
3835 s = find_mergeable(size, align, flags, name, ctor); 3840 s = find_mergeable(memcg, size, align, flags, name, ctor);
3836 if (s) { 3841 if (s) {
3837 s->refcount++; 3842 s->refcount++;
3838 /* 3843 /*
@@ -5156,6 +5161,12 @@ static char *create_unique_id(struct kmem_cache *s)
5156 if (p != name + 1) 5161 if (p != name + 1)
5157 *p++ = '-'; 5162 *p++ = '-';
5158 p += sprintf(p, "%07d", s->size); 5163 p += sprintf(p, "%07d", s->size);
5164
5165#ifdef CONFIG_MEMCG_KMEM
5166 if (!is_root_cache(s))
5167 p += sprintf(p, "-%08d", memcg_cache_id(s->memcg_params->memcg));
5168#endif
5169
5159 BUG_ON(p > name + ID_STR_LENGTH - 1); 5170 BUG_ON(p > name + ID_STR_LENGTH - 1);
5160 return name; 5171 return name;
5161} 5172}