[PATCH v2 2/2] memcg: consolidate callers of memcg_cache_id

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Each caller of memcg_cache_id ends up sanitizing its parameters in its own way.
Now that the memcg_cache_id itself is more robust, we can consolidate this.

There are callers that really cannot handle anything other than a valid memcg
being passed to the function, otherwise something is seriously wrong.  In those
cases, we at least VM_BUG_ON explicitly before using the value any further

Signed-off-by: Glauber Costa <glommer@xxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxx>
Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
---
 mm/memcontrol.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 359a53b..adbc09b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2975,10 +2975,14 @@ static inline bool memcg_can_account_kmem(struct mem_cgroup *memcg)
 static struct kmem_cache *memcg_params_to_cache(struct memcg_cache_params *p)
 {
 	struct kmem_cache *cachep;
+	int idx;
 
 	VM_BUG_ON(p->is_root_cache);
 	cachep = p->root_cache;
-	return cachep->memcg_params->memcg_caches[memcg_cache_id(p->memcg)];
+
+	idx = memcg_cache_id(p->memcg);
+	VM_BUG_ON(idx < 0);
+	return cachep->memcg_params->memcg_caches[idx];
 }
 
 #ifdef CONFIG_SLABINFO
@@ -3246,6 +3250,7 @@ void memcg_release_cache(struct kmem_cache *s)
 
 	memcg = s->memcg_params->memcg;
 	id  = memcg_cache_id(memcg);
+	VM_BUG_ON(id < 0);
 
 	root = s->memcg_params->root_cache;
 	root->memcg_params->memcg_caches[id] = NULL;
@@ -3408,9 +3413,8 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
 	struct kmem_cache *new_cachep;
 	int idx;
 
-	BUG_ON(!memcg_can_account_kmem(memcg));
-
 	idx = memcg_cache_id(memcg);
+	BUG_ON(!idx < 0);
 
 	mutex_lock(&memcg_cache_mutex);
 	new_cachep = cachep->memcg_params->memcg_caches[idx];
@@ -3583,10 +3587,9 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep,
 	rcu_read_lock();
 	memcg = mem_cgroup_from_task(rcu_dereference(current->mm->owner));
 
-	if (!memcg_can_account_kmem(memcg))
-		goto out;
-
 	idx = memcg_cache_id(memcg);
+	if (idx < 0)
+		return cachep;
 
 	/*
 	 * barrier to mare sure we're always seeing the up to date value.  The
-- 
1.8.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]