Merge tag 'fixes-for-v3.18-rc2' of https://github.com/rjarzmik/linux into fixes
[cascardo/linux.git] / mm / slab_common.c
index f206cb1..3a6e0cf 100644 (file)
@@ -116,6 +116,65 @@ static inline int kmem_cache_sanity_check(const char *name, size_t size)
 #endif
 
 #ifdef CONFIG_MEMCG_KMEM
+static int memcg_alloc_cache_params(struct mem_cgroup *memcg,
+               struct kmem_cache *s, struct kmem_cache *root_cache)
+{
+       size_t size;
+
+       if (!memcg_kmem_enabled())
+               return 0;
+
+       if (!memcg) {
+               size = offsetof(struct memcg_cache_params, memcg_caches);
+               size += memcg_limited_groups_array_size * sizeof(void *);
+       } else
+               size = sizeof(struct memcg_cache_params);
+
+       s->memcg_params = kzalloc(size, GFP_KERNEL);
+       if (!s->memcg_params)
+               return -ENOMEM;
+
+       if (memcg) {
+               s->memcg_params->memcg = memcg;
+               s->memcg_params->root_cache = root_cache;
+       } else
+               s->memcg_params->is_root_cache = true;
+
+       return 0;
+}
+
+static void memcg_free_cache_params(struct kmem_cache *s)
+{
+       kfree(s->memcg_params);
+}
+
+static int memcg_update_cache_params(struct kmem_cache *s, int num_memcgs)
+{
+       int size;
+       struct memcg_cache_params *new_params, *cur_params;
+
+       BUG_ON(!is_root_cache(s));
+
+       size = offsetof(struct memcg_cache_params, memcg_caches);
+       size += num_memcgs * sizeof(void *);
+
+       new_params = kzalloc(size, GFP_KERNEL);
+       if (!new_params)
+               return -ENOMEM;
+
+       cur_params = s->memcg_params;
+       memcpy(new_params->memcg_caches, cur_params->memcg_caches,
+              memcg_limited_groups_array_size * sizeof(void *));
+
+       new_params->is_root_cache = true;
+
+       rcu_assign_pointer(s->memcg_params, new_params);
+       if (cur_params)
+               kfree_rcu(cur_params, rcu_head);
+
+       return 0;
+}
+
 int memcg_update_all_caches(int num_memcgs)
 {
        struct kmem_cache *s;
@@ -126,9 +185,8 @@ int memcg_update_all_caches(int num_memcgs)
                if (!is_root_cache(s))
                        continue;
 
-               ret = memcg_update_cache_size(s, num_memcgs);
+               ret = memcg_update_cache_params(s, num_memcgs);
                /*
-                * See comment in memcontrol.c, memcg_update_cache_size:
                 * Instead of freeing the memory, we'll just leave the caches
                 * up to this point in an updated state.
                 */
@@ -141,7 +199,17 @@ out:
        mutex_unlock(&slab_mutex);
        return ret;
 }
-#endif
+#else
+static inline int memcg_alloc_cache_params(struct mem_cgroup *memcg,
+               struct kmem_cache *s, struct kmem_cache *root_cache)
+{
+       return 0;
+}
+
+static inline void memcg_free_cache_params(struct kmem_cache *s)
+{
+}
+#endif /* CONFIG_MEMCG_KMEM */
 
 /*
  * Find a mergeable slab cache