aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.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/memcontrol.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/memcontrol.c')
-rw-r--r--mm/memcontrol.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e16694d5e11..3eafe6cf6ca 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -341,6 +341,14 @@ struct mem_cgroup {
341#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_INET) 341#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_INET)
342 struct tcp_memcontrol tcp_mem; 342 struct tcp_memcontrol tcp_mem;
343#endif 343#endif
344#if defined(CONFIG_MEMCG_KMEM)
345 /* analogous to slab_common's slab_caches list. per-memcg */
346 struct list_head memcg_slab_caches;
347 /* Not a spinlock, we can take a lot of time walking the list */
348 struct mutex slab_caches_mutex;
349 /* Index in the kmem_cache->memcg_params->memcg_caches array */
350 int kmemcg_id;
351#endif
344}; 352};
345 353
346/* internal only representation about the status of kmem accounting. */ 354/* internal only representation about the status of kmem accounting. */
@@ -2785,6 +2793,47 @@ static void memcg_uncharge_kmem(struct mem_cgroup *memcg, u64 size)
2785 mem_cgroup_put(memcg); 2793 mem_cgroup_put(memcg);
2786} 2794}
2787 2795
2796void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep)
2797{
2798 if (!memcg)
2799 return;
2800
2801 mutex_lock(&memcg->slab_caches_mutex);
2802 list_add(&cachep->memcg_params->list, &memcg->memcg_slab_caches);
2803 mutex_unlock(&memcg->slab_caches_mutex);
2804}
2805
2806/*
2807 * helper for acessing a memcg's index. It will be used as an index in the
2808 * child cache array in kmem_cache, and also to derive its name. This function
2809 * will return -1 when this is not a kmem-limited memcg.
2810 */
2811int memcg_cache_id(struct mem_cgroup *memcg)
2812{
2813 return memcg ? memcg->kmemcg_id : -1;
2814}
2815
2816int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s)
2817{
2818 size_t size = sizeof(struct memcg_cache_params);
2819
2820 if (!memcg_kmem_enabled())
2821 return 0;
2822
2823 s->memcg_params = kzalloc(size, GFP_KERNEL);
2824 if (!s->memcg_params)
2825 return -ENOMEM;
2826
2827 if (memcg)
2828 s->memcg_params->memcg = memcg;
2829 return 0;
2830}
2831
2832void memcg_release_cache(struct kmem_cache *s)
2833{
2834 kfree(s->memcg_params);
2835}
2836
2788/* 2837/*
2789 * We need to verify if the allocation against current->mm->owner's memcg is 2838 * We need to verify if the allocation against current->mm->owner's memcg is
2790 * possible for the given order. But the page is not allocated yet, so we'll 2839 * possible for the given order. But the page is not allocated yet, so we'll
@@ -5026,7 +5075,9 @@ static int mem_cgroup_oom_control_write(struct cgroup *cgrp,
5026#ifdef CONFIG_MEMCG_KMEM 5075#ifdef CONFIG_MEMCG_KMEM
5027static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss) 5076static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
5028{ 5077{
5078 memcg->kmemcg_id = -1;
5029 memcg_propagate_kmem(memcg); 5079 memcg_propagate_kmem(memcg);
5080
5030 return mem_cgroup_sockets_init(memcg, ss); 5081 return mem_cgroup_sockets_init(memcg, ss);
5031}; 5082};
5032 5083