aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/memcontrol.h9
-rw-r--r--mm/memcontrol.c64
-rw-r--r--mm/slab_common.c5
3 files changed, 37 insertions, 41 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 284daff507fb..abd0113b6620 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -500,8 +500,8 @@ int memcg_cache_id(struct mem_cgroup *memcg);
500int memcg_alloc_cache_params(struct mem_cgroup *memcg, struct kmem_cache *s, 500int memcg_alloc_cache_params(struct mem_cgroup *memcg, struct kmem_cache *s,
501 struct kmem_cache *root_cache); 501 struct kmem_cache *root_cache);
502void memcg_free_cache_params(struct kmem_cache *s); 502void memcg_free_cache_params(struct kmem_cache *s);
503void memcg_release_cache(struct kmem_cache *cachep); 503void memcg_register_cache(struct kmem_cache *s);
504void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep); 504void memcg_unregister_cache(struct kmem_cache *s);
505 505
506int memcg_update_cache_size(struct kmem_cache *s, int num_groups); 506int memcg_update_cache_size(struct kmem_cache *s, int num_groups);
507void memcg_update_array_size(int num_groups); 507void memcg_update_array_size(int num_groups);
@@ -651,12 +651,11 @@ static inline void memcg_free_cache_params(struct kmem_cache *s)
651{ 651{
652} 652}
653 653
654static inline void memcg_release_cache(struct kmem_cache *cachep) 654static inline void memcg_register_cache(struct kmem_cache *s)
655{ 655{
656} 656}
657 657
658static inline void memcg_cache_list_add(struct mem_cgroup *memcg, 658static inline void memcg_unregister_cache(struct kmem_cache *s)
659 struct kmem_cache *s)
660{ 659{
661} 660}
662 661
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b8ebe71f872d..739383cd3f70 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3095,16 +3095,6 @@ static void memcg_uncharge_kmem(struct mem_cgroup *memcg, u64 size)
3095 css_put(&memcg->css); 3095 css_put(&memcg->css);
3096} 3096}
3097 3097
3098void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep)
3099{
3100 if (!memcg)
3101 return;
3102
3103 mutex_lock(&memcg->slab_caches_mutex);
3104 list_add(&cachep->memcg_params->list, &memcg->memcg_slab_caches);
3105 mutex_unlock(&memcg->slab_caches_mutex);
3106}
3107
3108/* 3098/*
3109 * helper for acessing a memcg's index. It will be used as an index in the 3099 * helper for acessing a memcg's index. It will be used as an index in the
3110 * child cache array in kmem_cache, and also to derive its name. This function 3100 * child cache array in kmem_cache, and also to derive its name. This function
@@ -3265,21 +3255,41 @@ void memcg_free_cache_params(struct kmem_cache *s)
3265 kfree(s->memcg_params); 3255 kfree(s->memcg_params);
3266} 3256}
3267 3257
3268void memcg_release_cache(struct kmem_cache *s) 3258void memcg_register_cache(struct kmem_cache *s)
3269{ 3259{
3270 struct kmem_cache *root; 3260 struct kmem_cache *root;
3271 struct mem_cgroup *memcg; 3261 struct mem_cgroup *memcg;
3272 int id; 3262 int id;
3273 3263
3264 if (is_root_cache(s))
3265 return;
3266
3267 root = s->memcg_params->root_cache;
3268 memcg = s->memcg_params->memcg;
3269 id = memcg_cache_id(memcg);
3270
3271 css_get(&memcg->css);
3272
3273 mutex_lock(&memcg->slab_caches_mutex);
3274 list_add(&s->memcg_params->list, &memcg->memcg_slab_caches);
3275 mutex_unlock(&memcg->slab_caches_mutex);
3276
3277 root->memcg_params->memcg_caches[id] = s;
3274 /* 3278 /*
3275 * This happens, for instance, when a root cache goes away before we 3279 * the readers won't lock, make sure everybody sees the updated value,
3276 * add any memcg. 3280 * so they won't put stuff in the queue again for no reason
3277 */ 3281 */
3278 if (!s->memcg_params) 3282 wmb();
3279 return; 3283}
3280 3284
3281 if (s->memcg_params->is_root_cache) 3285void memcg_unregister_cache(struct kmem_cache *s)
3282 goto out; 3286{
3287 struct kmem_cache *root;
3288 struct mem_cgroup *memcg;
3289 int id;
3290
3291 if (is_root_cache(s))
3292 return;
3283 3293
3284 memcg = s->memcg_params->memcg; 3294 memcg = s->memcg_params->memcg;
3285 id = memcg_cache_id(memcg); 3295 id = memcg_cache_id(memcg);
@@ -3292,8 +3302,6 @@ void memcg_release_cache(struct kmem_cache *s)
3292 mutex_unlock(&memcg->slab_caches_mutex); 3302 mutex_unlock(&memcg->slab_caches_mutex);
3293 3303
3294 css_put(&memcg->css); 3304 css_put(&memcg->css);
3295out:
3296 memcg_free_cache_params(s);
3297} 3305}
3298 3306
3299/* 3307/*
@@ -3451,26 +3459,13 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
3451 3459
3452 mutex_lock(&memcg_cache_mutex); 3460 mutex_lock(&memcg_cache_mutex);
3453 new_cachep = cache_from_memcg_idx(cachep, idx); 3461 new_cachep = cache_from_memcg_idx(cachep, idx);
3454 if (new_cachep) { 3462 if (new_cachep)
3455 css_put(&memcg->css);
3456 goto out; 3463 goto out;
3457 }
3458 3464
3459 new_cachep = kmem_cache_dup(memcg, cachep); 3465 new_cachep = kmem_cache_dup(memcg, cachep);
3460 if (new_cachep == NULL) { 3466 if (new_cachep == NULL)
3461 new_cachep = cachep; 3467 new_cachep = cachep;
3462 css_put(&memcg->css);
3463 goto out;
3464 }
3465
3466 atomic_set(&new_cachep->memcg_params->nr_pages , 0);
3467 3468
3468 cachep->memcg_params->memcg_caches[idx] = new_cachep;
3469 /*
3470 * the readers won't lock, make sure everybody sees the updated value,
3471 * so they won't put stuff in the queue again for no reason
3472 */
3473 wmb();
3474out: 3469out:
3475 mutex_unlock(&memcg_cache_mutex); 3470 mutex_unlock(&memcg_cache_mutex);
3476 return new_cachep; 3471 return new_cachep;
@@ -3550,6 +3545,7 @@ static void memcg_create_cache_work_func(struct work_struct *w)
3550 3545
3551 cw = container_of(w, struct create_work, work); 3546 cw = container_of(w, struct create_work, work);
3552 memcg_create_kmem_cache(cw->memcg, cw->cachep); 3547 memcg_create_kmem_cache(cw->memcg, cw->cachep);
3548 css_put(&cw->memcg->css);
3553 kfree(cw); 3549 kfree(cw);
3554} 3550}
3555 3551
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 70f9e249ac30..db24ec48b946 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -215,7 +215,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
215 215
216 s->refcount = 1; 216 s->refcount = 1;
217 list_add(&s->list, &slab_caches); 217 list_add(&s->list, &slab_caches);
218 memcg_cache_list_add(memcg, s); 218 memcg_register_cache(s);
219 219
220out_unlock: 220out_unlock:
221 mutex_unlock(&slab_mutex); 221 mutex_unlock(&slab_mutex);
@@ -265,7 +265,8 @@ void kmem_cache_destroy(struct kmem_cache *s)
265 if (s->flags & SLAB_DESTROY_BY_RCU) 265 if (s->flags & SLAB_DESTROY_BY_RCU)
266 rcu_barrier(); 266 rcu_barrier();
267 267
268 memcg_release_cache(s); 268 memcg_unregister_cache(s);
269 memcg_free_cache_params(s);
269 kfree(s->name); 270 kfree(s->name);
270 kmem_cache_free(kmem_cache, s); 271 kmem_cache_free(kmem_cache, s);
271 } else { 272 } else {