Commit 1c2d479a authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Linus Torvalds

mm/memcontrol.c: convert mem_cgroup_id::ref to refcount_t type

This will allow to use generic refcount_t interfaces to check counters
overflow instead of currently existing VM_BUG_ON().  The only difference
after the patch is VM_BUG_ON() may cause BUG(), while refcount_t fires
with WARN().  But this seems not to be significant here, since such the
problems are usually caught by syzbot with panic-on-warn enabled.

Link: http://lkml.kernel.org/r/153910718919.7006.13400779039257185427.stgit@localhost.localdomainSigned-off-by: default avatarKirill Tkhai <ktkhai@virtuozzo.com>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Andrea Parri <andrea.parri@amarulasolutions.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4a222127
...@@ -78,7 +78,7 @@ struct mem_cgroup_reclaim_cookie { ...@@ -78,7 +78,7 @@ struct mem_cgroup_reclaim_cookie {
struct mem_cgroup_id { struct mem_cgroup_id {
int id; int id;
atomic_t ref; refcount_t ref;
}; };
/* /*
......
...@@ -4299,14 +4299,12 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg) ...@@ -4299,14 +4299,12 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg)
static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n) static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
{ {
VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0); refcount_add(n, &memcg->id.ref);
atomic_add(n, &memcg->id.ref);
} }
static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n) static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n)
{ {
VM_BUG_ON(atomic_read(&memcg->id.ref) < n); if (refcount_sub_and_test(n, &memcg->id.ref)) {
if (atomic_sub_and_test(n, &memcg->id.ref)) {
mem_cgroup_id_remove(memcg); mem_cgroup_id_remove(memcg);
/* Memcg ID pins CSS */ /* Memcg ID pins CSS */
...@@ -4523,7 +4521,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) ...@@ -4523,7 +4521,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
} }
/* Online state pins memcg ID, memcg ID pins CSS */ /* Online state pins memcg ID, memcg ID pins CSS */
atomic_set(&memcg->id.ref, 1); refcount_set(&memcg->id.ref, 1);
css_get(css); css_get(css);
return 0; return 0;
} }
...@@ -6357,7 +6355,7 @@ subsys_initcall(mem_cgroup_init); ...@@ -6357,7 +6355,7 @@ subsys_initcall(mem_cgroup_init);
#ifdef CONFIG_MEMCG_SWAP #ifdef CONFIG_MEMCG_SWAP
static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg) static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
{ {
while (!atomic_inc_not_zero(&memcg->id.ref)) { while (!refcount_inc_not_zero(&memcg->id.ref)) {
/* /*
* The root cgroup cannot be destroyed, so it's refcount must * The root cgroup cannot be destroyed, so it's refcount must
* always be >= 1. * always be >= 1.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment