aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slab_common.c
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@parallels.com>2014-10-09 18:28:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:25:59 -0400
commit6f817f4cda68b09621312ec5ba84217bc5e37b3d (patch)
tree3c91b99f42ee347dfc4106f7c04786d0d46f0694 /mm/slab_common.c
parentf3bb3043a092368a255bca5d1c6f4352c96a3b2d (diff)
memcg: move memcg_update_cache_size() to slab_common.c
`While growing per memcg caches arrays, we jump between memcontrol.c and slab_common.c in a weird way: memcg_alloc_cache_id - memcontrol.c memcg_update_all_caches - slab_common.c memcg_update_cache_size - memcontrol.c There's absolutely no reason why memcg_update_cache_size can't live on the slab's side though. So let's move it there and settle it comfortably amid per-memcg cache allocation functions. Besides, this patch cleans this function up a bit, removing all the useless comments from it, and renames it to memcg_update_cache_params to conform to memcg_alloc/free_cache_params, which we already have in slab_common.c. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: Christoph Lameter <cl@linux.com> Cc: Glauber Costa <glommer@gmail.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: David Rientjes <rientjes@google.com> Cc: Pekka Enberg <penberg@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/slab_common.c')
-rw-r--r--mm/slab_common.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c
index c2a8661f8b81..3a6e0cfdf03a 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -148,6 +148,33 @@ static void memcg_free_cache_params(struct kmem_cache *s)
148 kfree(s->memcg_params); 148 kfree(s->memcg_params);
149} 149}
150 150
151static int memcg_update_cache_params(struct kmem_cache *s, int num_memcgs)
152{
153 int size;
154 struct memcg_cache_params *new_params, *cur_params;
155
156 BUG_ON(!is_root_cache(s));
157
158 size = offsetof(struct memcg_cache_params, memcg_caches);
159 size += num_memcgs * sizeof(void *);
160
161 new_params = kzalloc(size, GFP_KERNEL);
162 if (!new_params)
163 return -ENOMEM;
164
165 cur_params = s->memcg_params;
166 memcpy(new_params->memcg_caches, cur_params->memcg_caches,
167 memcg_limited_groups_array_size * sizeof(void *));
168
169 new_params->is_root_cache = true;
170
171 rcu_assign_pointer(s->memcg_params, new_params);
172 if (cur_params)
173 kfree_rcu(cur_params, rcu_head);
174
175 return 0;
176}
177
151int memcg_update_all_caches(int num_memcgs) 178int memcg_update_all_caches(int num_memcgs)
152{ 179{
153 struct kmem_cache *s; 180 struct kmem_cache *s;
@@ -158,9 +185,8 @@ int memcg_update_all_caches(int num_memcgs)
158 if (!is_root_cache(s)) 185 if (!is_root_cache(s))
159 continue; 186 continue;
160 187
161 ret = memcg_update_cache_size(s, num_memcgs); 188 ret = memcg_update_cache_params(s, num_memcgs);
162 /* 189 /*
163 * See comment in memcontrol.c, memcg_update_cache_size:
164 * Instead of freeing the memory, we'll just leave the caches 190 * Instead of freeing the memory, we'll just leave the caches
165 * up to this point in an updated state. 191 * up to this point in an updated state.
166 */ 192 */