diff options
author | Glauber Costa <glommer@parallels.com> | 2012-12-18 17:22:48 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-18 18:02:14 -0500 |
commit | d79923fad95b0cdf7770e024677180c734cb7148 (patch) | |
tree | e7cf6e9fb151d3c0d5c773fa1ba723a71b1e9329 /mm | |
parent | b9ce5ef49f00daf2254c6953c8d31f79aabccd34 (diff) |
sl[au]b: allocate objects from memcg cache
We are able to match a cache allocation to a particular memcg. If the
task doesn't change groups during the allocation itself - a rare event,
this will give us a good picture about who is the first group to touch a
cache page.
This patch uses the now available infrastructure by calling
memcg_kmem_get_cache() before all the cache allocations.
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')
-rw-r--r-- | mm/memcontrol.c | 3 | ||||
-rw-r--r-- | mm/slab.c | 6 | ||||
-rw-r--r-- | mm/slub.c | 7 |
3 files changed, 12 insertions, 4 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 65302a083d2f..cc13797d0fbc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -3086,6 +3086,9 @@ static struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, | |||
3086 | new = kmem_cache_create_memcg(memcg, name, s->object_size, s->align, | 3086 | new = kmem_cache_create_memcg(memcg, name, s->object_size, s->align, |
3087 | (s->flags & ~SLAB_PANIC), s->ctor); | 3087 | (s->flags & ~SLAB_PANIC), s->ctor); |
3088 | 3088 | ||
3089 | if (new) | ||
3090 | new->allocflags |= __GFP_KMEMCG; | ||
3091 | |||
3089 | kfree(name); | 3092 | kfree(name); |
3090 | return new; | 3093 | return new; |
3091 | } | 3094 | } |
@@ -1933,7 +1933,7 @@ static void kmem_freepages(struct kmem_cache *cachep, void *addr) | |||
1933 | } | 1933 | } |
1934 | if (current->reclaim_state) | 1934 | if (current->reclaim_state) |
1935 | current->reclaim_state->reclaimed_slab += nr_freed; | 1935 | current->reclaim_state->reclaimed_slab += nr_freed; |
1936 | free_pages((unsigned long)addr, cachep->gfporder); | 1936 | free_memcg_kmem_pages((unsigned long)addr, cachep->gfporder); |
1937 | } | 1937 | } |
1938 | 1938 | ||
1939 | static void kmem_rcu_free(struct rcu_head *head) | 1939 | static void kmem_rcu_free(struct rcu_head *head) |
@@ -3486,6 +3486,8 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | |||
3486 | if (slab_should_failslab(cachep, flags)) | 3486 | if (slab_should_failslab(cachep, flags)) |
3487 | return NULL; | 3487 | return NULL; |
3488 | 3488 | ||
3489 | cachep = memcg_kmem_get_cache(cachep, flags); | ||
3490 | |||
3489 | cache_alloc_debugcheck_before(cachep, flags); | 3491 | cache_alloc_debugcheck_before(cachep, flags); |
3490 | local_irq_save(save_flags); | 3492 | local_irq_save(save_flags); |
3491 | 3493 | ||
@@ -3571,6 +3573,8 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller) | |||
3571 | if (slab_should_failslab(cachep, flags)) | 3573 | if (slab_should_failslab(cachep, flags)) |
3572 | return NULL; | 3574 | return NULL; |
3573 | 3575 | ||
3576 | cachep = memcg_kmem_get_cache(cachep, flags); | ||
3577 | |||
3574 | cache_alloc_debugcheck_before(cachep, flags); | 3578 | cache_alloc_debugcheck_before(cachep, flags); |
3575 | local_irq_save(save_flags); | 3579 | local_irq_save(save_flags); |
3576 | objp = __do_cache_alloc(cachep, flags); | 3580 | objp = __do_cache_alloc(cachep, flags); |
@@ -1405,7 +1405,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page) | |||
1405 | reset_page_mapcount(page); | 1405 | reset_page_mapcount(page); |
1406 | if (current->reclaim_state) | 1406 | if (current->reclaim_state) |
1407 | current->reclaim_state->reclaimed_slab += pages; | 1407 | current->reclaim_state->reclaimed_slab += pages; |
1408 | __free_pages(page, order); | 1408 | __free_memcg_kmem_pages(page, order); |
1409 | } | 1409 | } |
1410 | 1410 | ||
1411 | #define need_reserve_slab_rcu \ | 1411 | #define need_reserve_slab_rcu \ |
@@ -2323,6 +2323,7 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, | |||
2323 | if (slab_pre_alloc_hook(s, gfpflags)) | 2323 | if (slab_pre_alloc_hook(s, gfpflags)) |
2324 | return NULL; | 2324 | return NULL; |
2325 | 2325 | ||
2326 | s = memcg_kmem_get_cache(s, gfpflags); | ||
2326 | redo: | 2327 | redo: |
2327 | 2328 | ||
2328 | /* | 2329 | /* |
@@ -3284,7 +3285,7 @@ static void *kmalloc_large_node(size_t size, gfp_t flags, int node) | |||
3284 | struct page *page; | 3285 | struct page *page; |
3285 | void *ptr = NULL; | 3286 | void *ptr = NULL; |
3286 | 3287 | ||
3287 | flags |= __GFP_COMP | __GFP_NOTRACK; | 3288 | flags |= __GFP_COMP | __GFP_NOTRACK | __GFP_KMEMCG; |
3288 | page = alloc_pages_node(node, flags, get_order(size)); | 3289 | page = alloc_pages_node(node, flags, get_order(size)); |
3289 | if (page) | 3290 | if (page) |
3290 | ptr = page_address(page); | 3291 | ptr = page_address(page); |
@@ -3390,7 +3391,7 @@ void kfree(const void *x) | |||
3390 | if (unlikely(!PageSlab(page))) { | 3391 | if (unlikely(!PageSlab(page))) { |
3391 | BUG_ON(!PageCompound(page)); | 3392 | BUG_ON(!PageCompound(page)); |
3392 | kmemleak_free(x); | 3393 | kmemleak_free(x); |
3393 | __free_pages(page, compound_order(page)); | 3394 | __free_memcg_kmem_pages(page, compound_order(page)); |
3394 | return; | 3395 | return; |
3395 | } | 3396 | } |
3396 | slab_free(page->slab_cache, page, object, _RET_IP_); | 3397 | slab_free(page->slab_cache, page, object, _RET_IP_); |