aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c13
-rw-r--r--mm/slab_common.c75
2 files changed, 56 insertions, 32 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c22d8bf42d9a..29501f040568 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3321,15 +3321,10 @@ void mem_cgroup_destroy_cache(struct kmem_cache *cachep)
3321 schedule_work(&cachep->memcg_params->destroy); 3321 schedule_work(&cachep->memcg_params->destroy);
3322} 3322}
3323 3323
3324void kmem_cache_destroy_memcg_children(struct kmem_cache *s) 3324int __kmem_cache_destroy_memcg_children(struct kmem_cache *s)
3325{ 3325{
3326 struct kmem_cache *c; 3326 struct kmem_cache *c;
3327 int i; 3327 int i, failed = 0;
3328
3329 if (!s->memcg_params)
3330 return;
3331 if (!s->memcg_params->is_root_cache)
3332 return;
3333 3328
3334 /* 3329 /*
3335 * If the cache is being destroyed, we trust that there is no one else 3330 * If the cache is being destroyed, we trust that there is no one else
@@ -3363,8 +3358,12 @@ void kmem_cache_destroy_memcg_children(struct kmem_cache *s)
3363 c->memcg_params->dead = false; 3358 c->memcg_params->dead = false;
3364 cancel_work_sync(&c->memcg_params->destroy); 3359 cancel_work_sync(&c->memcg_params->destroy);
3365 kmem_cache_destroy(c); 3360 kmem_cache_destroy(c);
3361
3362 if (cache_from_memcg_idx(s, i))
3363 failed++;
3366 } 3364 }
3367 mutex_unlock(&activate_kmem_mutex); 3365 mutex_unlock(&activate_kmem_mutex);
3366 return failed;
3368} 3367}
3369 3368
3370static void mem_cgroup_destroy_all_caches(struct mem_cgroup *memcg) 3369static void mem_cgroup_destroy_all_caches(struct mem_cgroup *memcg)
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 0c2879ff414c..f3cfccf76dda 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -301,39 +301,64 @@ out_unlock:
301 mutex_unlock(&slab_mutex); 301 mutex_unlock(&slab_mutex);
302 put_online_cpus(); 302 put_online_cpus();
303} 303}
304
305static int kmem_cache_destroy_memcg_children(struct kmem_cache *s)
306{
307 int rc;
308
309 if (!s->memcg_params ||
310 !s->memcg_params->is_root_cache)
311 return 0;
312
313 mutex_unlock(&slab_mutex);
314 rc = __kmem_cache_destroy_memcg_children(s);
315 mutex_lock(&slab_mutex);
316
317 return rc;
318}
319#else
320static int kmem_cache_destroy_memcg_children(struct kmem_cache *s)
321{
322 return 0;
323}
304#endif /* CONFIG_MEMCG_KMEM */ 324#endif /* CONFIG_MEMCG_KMEM */
305 325
306void kmem_cache_destroy(struct kmem_cache *s) 326void kmem_cache_destroy(struct kmem_cache *s)
307{ 327{
308 /* Destroy all the children caches if we aren't a memcg cache */
309 kmem_cache_destroy_memcg_children(s);
310
311 get_online_cpus(); 328 get_online_cpus();
312 mutex_lock(&slab_mutex); 329 mutex_lock(&slab_mutex);
330
313 s->refcount--; 331 s->refcount--;
314 if (!s->refcount) { 332 if (s->refcount)
315 list_del(&s->list); 333 goto out_unlock;
316 memcg_unregister_cache(s); 334
317 335 if (kmem_cache_destroy_memcg_children(s) != 0)
318 if (!__kmem_cache_shutdown(s)) { 336 goto out_unlock;
319 mutex_unlock(&slab_mutex); 337
320 if (s->flags & SLAB_DESTROY_BY_RCU) 338 list_del(&s->list);
321 rcu_barrier(); 339 memcg_unregister_cache(s);
322 340
323 memcg_free_cache_params(s); 341 if (__kmem_cache_shutdown(s) != 0) {
324 kfree(s->name); 342 list_add(&s->list, &slab_caches);
325 kmem_cache_free(kmem_cache, s); 343 memcg_register_cache(s);
326 } else { 344 printk(KERN_ERR "kmem_cache_destroy %s: "
327 list_add(&s->list, &slab_caches); 345 "Slab cache still has objects\n", s->name);
328 memcg_register_cache(s); 346 dump_stack();
329 mutex_unlock(&slab_mutex); 347 goto out_unlock;
330 printk(KERN_ERR "kmem_cache_destroy %s: Slab cache still has objects\n",
331 s->name);
332 dump_stack();
333 }
334 } else {
335 mutex_unlock(&slab_mutex);
336 } 348 }
349
350 mutex_unlock(&slab_mutex);
351 if (s->flags & SLAB_DESTROY_BY_RCU)
352 rcu_barrier();
353
354 memcg_free_cache_params(s);
355 kfree(s->name);
356 kmem_cache_free(kmem_cache, s);
357 goto out_put_cpus;
358
359out_unlock:
360 mutex_unlock(&slab_mutex);
361out_put_cpus:
337 put_online_cpus(); 362 put_online_cpus();
338} 363}
339EXPORT_SYMBOL(kmem_cache_destroy); 364EXPORT_SYMBOL(kmem_cache_destroy);