aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 322d18dc17f0..014a4f1acf1c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3270,9 +3270,6 @@ void memcg_register_cache(struct kmem_cache *s)
3270 3270
3271 css_get(&memcg->css); 3271 css_get(&memcg->css);
3272 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 3273
3277 /* 3274 /*
3278 * Since readers won't lock (see cache_from_memcg_idx()), we need a 3275 * Since readers won't lock (see cache_from_memcg_idx()), we need a
@@ -3281,7 +3278,16 @@ void memcg_register_cache(struct kmem_cache *s)
3281 */ 3278 */
3282 smp_wmb(); 3279 smp_wmb();
3283 3280
3281 /*
3282 * Initialize the pointer to this cache in its parent's memcg_params
3283 * before adding it to the memcg_slab_caches list, otherwise we can
3284 * fail to convert memcg_params_to_cache() while traversing the list.
3285 */
3284 root->memcg_params->memcg_caches[id] = s; 3286 root->memcg_params->memcg_caches[id] = s;
3287
3288 mutex_lock(&memcg->slab_caches_mutex);
3289 list_add(&s->memcg_params->list, &memcg->memcg_slab_caches);
3290 mutex_unlock(&memcg->slab_caches_mutex);
3285} 3291}
3286 3292
3287void memcg_unregister_cache(struct kmem_cache *s) 3293void memcg_unregister_cache(struct kmem_cache *s)
@@ -3293,16 +3299,21 @@ void memcg_unregister_cache(struct kmem_cache *s)
3293 if (is_root_cache(s)) 3299 if (is_root_cache(s))
3294 return; 3300 return;
3295 3301
3296 memcg = s->memcg_params->memcg;
3297 id = memcg_cache_id(memcg);
3298
3299 root = s->memcg_params->root_cache; 3302 root = s->memcg_params->root_cache;
3300 root->memcg_params->memcg_caches[id] = NULL; 3303 memcg = s->memcg_params->memcg;
3304 id = memcg_cache_id(memcg);
3301 3305
3302 mutex_lock(&memcg->slab_caches_mutex); 3306 mutex_lock(&memcg->slab_caches_mutex);
3303 list_del(&s->memcg_params->list); 3307 list_del(&s->memcg_params->list);
3304 mutex_unlock(&memcg->slab_caches_mutex); 3308 mutex_unlock(&memcg->slab_caches_mutex);
3305 3309
3310 /*
3311 * Clear the pointer to this cache in its parent's memcg_params only
3312 * after removing it from the memcg_slab_caches list, otherwise we can
3313 * fail to convert memcg_params_to_cache() while traversing the list.
3314 */
3315 root->memcg_params->memcg_caches[id] = NULL;
3316
3306 css_put(&memcg->css); 3317 css_put(&memcg->css);
3307} 3318}
3308 3319