[PATCH] mm-memcontrol-convert-reclaim-iterator-to-simple-css-refcounting-fix

From: Michal Hocko
Date: Wed Oct 15 2014 - 10:26:22 EST


Make sure that the cached reference is always released.

Signed-off-by: Michal Hocko <mhocko@xxxxxxx>
---
mm/memcontrol.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index bdcd0416a017..42842a47b4c1 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1160,9 +1160,17 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
}

if (reclaim) {
- if (cmpxchg(&iter->position, pos, memcg) == pos && memcg)
- css_get(&memcg->css);
+ if (cmpxchg(&iter->position, pos, memcg) == pos) {
+ if (memcg)
+ css_get(&memcg->css);
+ if (pos)
+ css_put(&pos->css);
+ }

+ /*
+ * pairs with css_tryget when dereferencing iter->position
+ * above.
+ */
if (pos)
css_put(&pos->css);

--
2.1.1

--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/