diff options
author | Vladimir Davydov <vdavydov@parallels.com> | 2014-01-23 18:53:03 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-23 19:36:51 -0500 |
commit | 842e2873697e023d140a8905a41fcf39d4e546f1 (patch) | |
tree | 5ba705288c9cc5cee0e22a3c55166e8982c994db /mm/memcontrol.c | |
parent | 2edefe1155b3ad3dc92065f6e1018d363525296e (diff) |
memcg: get rid of kmem_cache_dup()
kmem_cache_dup() is only called from memcg_create_kmem_cache(). The
latter, in fact, does nothing besides this, so let's fold
kmem_cache_dup() into memcg_create_kmem_cache().
This patch also makes the memcg_cache_mutex private to
memcg_create_kmem_cache(), because it is not used anywhere else.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
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.c | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d2da65c4cd84..80197e544764 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -3427,27 +3427,16 @@ void mem_cgroup_destroy_cache(struct kmem_cache *cachep) | |||
3427 | schedule_work(&cachep->memcg_params->destroy); | 3427 | schedule_work(&cachep->memcg_params->destroy); |
3428 | } | 3428 | } |
3429 | 3429 | ||
3430 | /* | 3430 | static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg, |
3431 | * This lock protects updaters, not readers. We want readers to be as fast as | 3431 | struct kmem_cache *s) |
3432 | * they can, and they will either see NULL or a valid cache value. Our model | ||
3433 | * allow them to see NULL, in which case the root memcg will be selected. | ||
3434 | * | ||
3435 | * We need this lock because multiple allocations to the same cache from a non | ||
3436 | * will span more than one worker. Only one of them can create the cache. | ||
3437 | */ | ||
3438 | static DEFINE_MUTEX(memcg_cache_mutex); | ||
3439 | |||
3440 | /* | ||
3441 | * Called with memcg_cache_mutex held | ||
3442 | */ | ||
3443 | static struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, | ||
3444 | struct kmem_cache *s) | ||
3445 | { | 3432 | { |
3446 | struct kmem_cache *new; | 3433 | struct kmem_cache *new; |
3447 | static char *tmp_name = NULL; | 3434 | static char *tmp_name = NULL; |
3435 | static DEFINE_MUTEX(mutex); /* protects tmp_name */ | ||
3448 | 3436 | ||
3449 | lockdep_assert_held(&memcg_cache_mutex); | 3437 | BUG_ON(!memcg_can_account_kmem(memcg)); |
3450 | 3438 | ||
3439 | mutex_lock(&mutex); | ||
3451 | /* | 3440 | /* |
3452 | * kmem_cache_create_memcg duplicates the given name and | 3441 | * kmem_cache_create_memcg duplicates the given name and |
3453 | * cgroup_name for this name requires RCU context. | 3442 | * cgroup_name for this name requires RCU context. |
@@ -3470,25 +3459,13 @@ static struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg, | |||
3470 | 3459 | ||
3471 | if (new) | 3460 | if (new) |
3472 | new->allocflags |= __GFP_KMEMCG; | 3461 | new->allocflags |= __GFP_KMEMCG; |
3462 | else | ||
3463 | new = s; | ||
3473 | 3464 | ||
3465 | mutex_unlock(&mutex); | ||
3474 | return new; | 3466 | return new; |
3475 | } | 3467 | } |
3476 | 3468 | ||
3477 | static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg, | ||
3478 | struct kmem_cache *cachep) | ||
3479 | { | ||
3480 | struct kmem_cache *new_cachep; | ||
3481 | |||
3482 | BUG_ON(!memcg_can_account_kmem(memcg)); | ||
3483 | |||
3484 | mutex_lock(&memcg_cache_mutex); | ||
3485 | new_cachep = kmem_cache_dup(memcg, cachep); | ||
3486 | if (new_cachep == NULL) | ||
3487 | new_cachep = cachep; | ||
3488 | mutex_unlock(&memcg_cache_mutex); | ||
3489 | return new_cachep; | ||
3490 | } | ||
3491 | |||
3492 | void kmem_cache_destroy_memcg_children(struct kmem_cache *s) | 3469 | void kmem_cache_destroy_memcg_children(struct kmem_cache *s) |
3493 | { | 3470 | { |
3494 | struct kmem_cache *c; | 3471 | struct kmem_cache *c; |