Re: + memcg-use-for_each_mem_cgroup.patch added to -mm tree

From: KAMEZAWA Hiroyuki
Date: Thu Sep 23 2010 - 20:45:41 EST


On Tue, 21 Sep 2010 12:36:35 -0700
akpm@xxxxxxxxxxxxxxxxxxxx wrote:

>
> The patch titled
> memcg: use for_each_mem_cgroup
> has been added to the -mm tree. Its filename is
> memcg-use-for_each_mem_cgroup.patch
>

This is a bug fix for this patch. Wrote onto mmotm-0922.
I'm sorry that test was not enough.

==
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>

memcg-use-for_each_mem_cgroup.patch's function mem_cgroup_start_loop() is
wrong because it always scan IDs larger than ROOT of sub-tree.
(This works well in small test..)

css_get_next() scans IDs larger than given number. Then...

Assume a tree like this.

Root(id=1)--A(id=2)
|
--B(id=3)--C(id=4)
|
--D(id=5)

In above case, searching all cgroup under "B" works well because
all IDs larger than B will be visited. (3->4->5)

Here, rmdir "A" and mkdir "E" under "B".

Root(id=1)--B(id=3)--C(id=4)
|
--D(id=5)
|
--E(id=2) /* reuse freed ID */

E's ID is smaller than B's. But, the function just visits (3->4->5)

All scan should be started from 1. Fixed routine will visit (2->3->4->5).

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
---
mm/memcontrol.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

Index: mmotm-0922/mm/memcontrol.c
===================================================================
--- mmotm-0922.orig/mm/memcontrol.c
+++ mmotm-0922/mm/memcontrol.c
@@ -697,12 +697,28 @@ static struct mem_cgroup *try_get_mem_cg
/* The caller has to guarantee "mem" exists before calling this */
static struct mem_cgroup *mem_cgroup_start_loop(struct mem_cgroup *mem)
{
- if (mem && css_tryget(&mem->css))
- return mem;
- if (!mem)
- return root_mem_cgroup; /*css_put/get against root is ignored*/
+ struct cgroup_subsys_state *css;
+ int found;

- return NULL;
+ if (!mem) /* ROOT cgroup has the smallest ID */
+ return root_mem_cgroup; /*css_put/get against root is ignored*/
+ if (!mem->use_hierarchy) {
+ if (css_tryget(&mem->css))
+ return mem;
+ return NULL;
+ }
+ rcu_read_lock();
+ /*
+ * searching a memory cgroup which has the smallest ID under given
+ * ROOT cgroup. (ID >= 1)
+ */
+ css = css_get_next(&mem_cgroup_subsys, 1, mem, &found);
+ if (css && css_tryget(&css))
+ mem = container_of(css, struct mem_cgroup, css);
+ else
+ mem = NULL;
+ rcu_read_unlock();
+ return mem;
}

static struct mem_cgroup *mem_cgroup_get_next(struct mem_cgroup *iter,

--
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/