Merge tag 'gpio-v3.15-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[cascardo/linux.git] / mm / memcontrol.c
index 32c7342..29501f0 100644 (file)
@@ -3140,6 +3140,7 @@ int memcg_alloc_cache_params(struct mem_cgroup *memcg, struct kmem_cache *s,
                s->memcg_params->root_cache = root_cache;
                INIT_WORK(&s->memcg_params->destroy,
                                kmem_cache_destroy_work_func);
+               css_get(&memcg->css);
        } else
                s->memcg_params->is_root_cache = true;
 
@@ -3148,6 +3149,10 @@ int memcg_alloc_cache_params(struct mem_cgroup *memcg, struct kmem_cache *s,
 
 void memcg_free_cache_params(struct kmem_cache *s)
 {
+       if (!s->memcg_params)
+               return;
+       if (!s->memcg_params->is_root_cache)
+               css_put(&s->memcg_params->memcg->css);
        kfree(s->memcg_params);
 }
 
@@ -3170,9 +3175,6 @@ void memcg_register_cache(struct kmem_cache *s)
        memcg = s->memcg_params->memcg;
        id = memcg_cache_id(memcg);
 
-       css_get(&memcg->css);
-
-
        /*
         * Since readers won't lock (see cache_from_memcg_idx()), we need a
         * barrier here to ensure nobody will see the kmem_cache partially
@@ -3221,10 +3223,8 @@ void memcg_unregister_cache(struct kmem_cache *s)
         * after removing it from the memcg_slab_caches list, otherwise we can
         * fail to convert memcg_params_to_cache() while traversing the list.
         */
-       VM_BUG_ON(!root->memcg_params->memcg_caches[id]);
+       VM_BUG_ON(root->memcg_params->memcg_caches[id] != s);
        root->memcg_params->memcg_caches[id] = NULL;
-
-       css_put(&memcg->css);
 }
 
 /*
@@ -3321,15 +3321,10 @@ void mem_cgroup_destroy_cache(struct kmem_cache *cachep)
        schedule_work(&cachep->memcg_params->destroy);
 }
 
-void kmem_cache_destroy_memcg_children(struct kmem_cache *s)
+int __kmem_cache_destroy_memcg_children(struct kmem_cache *s)
 {
        struct kmem_cache *c;
-       int i;
-
-       if (!s->memcg_params)
-               return;
-       if (!s->memcg_params->is_root_cache)
-               return;
+       int i, failed = 0;
 
        /*
         * 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)
                c->memcg_params->dead = false;
                cancel_work_sync(&c->memcg_params->destroy);
                kmem_cache_destroy(c);
+
+               if (cache_from_memcg_idx(s, i))
+                       failed++;
        }
        mutex_unlock(&activate_kmem_mutex);
+       return failed;
 }
 
 static void mem_cgroup_destroy_all_caches(struct mem_cgroup *memcg)
@@ -3395,13 +3394,8 @@ static void memcg_create_cache_work_func(struct work_struct *w)
        struct create_work *cw = container_of(w, struct create_work, work);
        struct mem_cgroup *memcg = cw->memcg;
        struct kmem_cache *cachep = cw->cachep;
-       struct kmem_cache *new;
 
-       new = kmem_cache_create_memcg(memcg, cachep->name,
-                       cachep->object_size, cachep->align,
-                       cachep->flags & ~SLAB_PANIC, cachep->ctor, cachep);
-       if (new)
-               new->allocflags |= __GFP_KMEMCG;
+       kmem_cache_create_memcg(memcg, cachep);
        css_put(&memcg->css);
        kfree(cw);
 }