From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
balbir@linux.vnet.ibm.com, lizf@cn.fujitsu.com,
menage@google.com
Subject: Re: [RFC][PATCH 3/4] memcg: fix for mem_cgroup_hierarchical_reclaim
Date: Fri, 9 Jan 2009 10:08:30 +0900 [thread overview]
Message-ID: <20090109100830.3e9c90e0.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <39822.10.75.179.62.1231412881.squirrel@webmail-b.css.fujitsu.com>
On Thu, 8 Jan 2009 20:08:01 +0900 (JST)
"KAMEZAWA Hiroyuki" <kamezawa.hiroyu@jp.fujitsu.com> wrote:
> Daisuke Nishimura said:
> > If root_mem has no children, last_scaned_child is set to root_mem itself.
> > But after some children added to root_mem, mem_cgroup_get_next_node can
> > mem_cgroup_put the root_mem although root_mem has not been mem_cgroup_get.
> >
> > This patch fixes this behavior by:
> > - Set last_scanned_child to NULL if root_mem has no children or DFS search
> > has returned to root_mem itself(root_mem is not a "child" of root_mem).
> > Make mem_cgroup_get_first_node return root_mem in this case.
> > There are no mem_cgroup_get/put for root_mem.
> > - Rename mem_cgroup_get_next_node to __mem_cgroup_get_next_node, and
> > mem_cgroup_get_first_node to mem_cgroup_get_next_node.
> > Make mem_cgroup_hierarchical_reclaim call only new
> > mem_cgroup_get_next_node.
> >
> >
> > Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
>
> Hmm, seems necessary fix. Then, it's better to rebase my patch on to this.
>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>
> Maybe simpler one can be written but my patch remove all this out later....
>
How about this ? (just an exmaple and not tested, sorry)
---
mm/memcontrol.c | 52 ++++++++++++++++++++++------------------------------
1 file changed, 22 insertions(+), 30 deletions(-)
Index: mmotm-2.6.28-Jan7/mm/memcontrol.c
===================================================================
--- mmotm-2.6.28-Jan7.orig/mm/memcontrol.c
+++ mmotm-2.6.28-Jan7/mm/memcontrol.c
@@ -621,6 +621,7 @@ static struct mem_cgroup *
mem_cgroup_get_next_node(struct mem_cgroup *curr, struct mem_cgroup *root_mem)
{
struct cgroup *cgroup, *curr_cgroup, *root_cgroup;
+ struct mem_cgroup *orig = root_mem->last_scanned_child;
curr_cgroup = curr->css.cgroup;
root_cgroup = root_mem->css.cgroup;
@@ -629,19 +630,15 @@ mem_cgroup_get_next_node(struct mem_cgro
/*
* Walk down to children
*/
- mem_cgroup_put(curr);
cgroup = list_entry(curr_cgroup->children.next,
struct cgroup, sibling);
curr = mem_cgroup_from_cont(cgroup);
- mem_cgroup_get(curr);
goto done;
}
visit_parent:
if (curr_cgroup == root_cgroup) {
- mem_cgroup_put(curr);
curr = root_mem;
- mem_cgroup_get(curr);
goto done;
}
@@ -649,11 +646,9 @@ visit_parent:
* Goto next sibling
*/
if (curr_cgroup->sibling.next != &curr_cgroup->parent->children) {
- mem_cgroup_put(curr);
cgroup = list_entry(curr_cgroup->sibling.next, struct cgroup,
sibling);
curr = mem_cgroup_from_cont(cgroup);
- mem_cgroup_get(curr);
goto done;
}
@@ -664,7 +659,10 @@ visit_parent:
goto visit_parent;
done:
+ if (orig)
+ mem_cgroup_put(orig);
root_mem->last_scanned_child = curr;
+ mem_cgroup_get(curr);
return curr;
}
@@ -677,35 +675,25 @@ static struct mem_cgroup *
mem_cgroup_get_first_node(struct mem_cgroup *root_mem)
{
struct cgroup *cgroup;
- struct mem_cgroup *ret;
- bool obsolete;
+ struct mem_cgroup *ret, *orig;
- obsolete = mem_cgroup_is_obsolete(root_mem->last_scanned_child);
-
- /*
- * Scan all children under the mem_cgroup mem
- */
mutex_lock(&mem_cgroup_subsys.hierarchy_mutex);
- if (list_empty(&root_mem->css.cgroup->children)) {
- ret = root_mem;
- goto done;
- }
-
- if (!root_mem->last_scanned_child || obsolete) {
-
- if (obsolete && root_mem->last_scanned_child)
- mem_cgroup_put(root_mem->last_scanned_child);
+ orig = root_mem->last_scanned_child;
- cgroup = list_first_entry(&root_mem->css.cgroup->children,
- struct cgroup, sibling);
- ret = mem_cgroup_from_cont(cgroup);
+ if (!orig) {
+ if (list_empty(&root_mem->css.cgroup->children)) {
+ ret = root_mem;
+ } else {
+ cgroup =
+ list_first_entry(&root_mem->css.cgroup->children,
+ struct cgroup, sibling);
+ ret = mem_cgroup_from_cont(cgroup);
+ }
+ root_mem->last_scanned_child = ret;
mem_cgroup_get(ret);
- } else
+ } else /* get_next_node will manage refcnt */
ret = mem_cgroup_get_next_node(root_mem->last_scanned_child,
root_mem);
-
-done:
- root_mem->last_scanned_child = ret;
mutex_unlock(&mem_cgroup_subsys.hierarchy_mutex);
return ret;
}
@@ -2232,7 +2220,11 @@ static void mem_cgroup_pre_destroy(struc
static void mem_cgroup_destroy(struct cgroup_subsys *ss,
struct cgroup *cont)
{
- mem_cgroup_put(mem_cgroup_from_cont(cont));
+ struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
+
+ if (mem->last_scanned_child == mem)
+ mem_cgroup_put(mem);
+ mem_cgroup_put(mem);
}
static int mem_cgroup_populate(struct cgroup_subsys *ss,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-01-09 1:09 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-08 10:08 [RFC][PATCH 0/4] some memcg fixes Daisuke Nishimura
2009-01-08 10:14 ` [RFC][PATCH 1/4] memcg: fix for mem_cgroup_get_reclaim_stat_from_page Daisuke Nishimura
2009-01-08 10:59 ` [RFC][PATCH 1/4] memcg: fix formem_cgroup_get_reclaim_stat_from_page KAMEZAWA Hiroyuki
2009-01-09 0:57 ` [RFC][PATCH 1/4] memcg: fix for mem_cgroup_get_reclaim_stat_from_page Li Zefan
2009-01-09 1:05 ` KAMEZAWA Hiroyuki
2009-01-09 2:34 ` Daisuke Nishimura
2009-01-09 2:41 ` KAMEZAWA Hiroyuki
2009-01-09 4:32 ` Balbir Singh
2009-01-09 4:47 ` KAMEZAWA Hiroyuki
2009-01-15 11:08 ` [PATCH] mark_page_accessed() in do_swap_page() move latter than memcg charge KOSAKI Motohiro
2009-01-15 11:12 ` KAMEZAWA Hiroyuki
2009-01-15 11:30 ` Balbir Singh
2009-01-15 12:07 ` Hugh Dickins
2009-01-15 12:28 ` KAMEZAWA Hiroyuki
2009-01-15 13:34 ` KOSAKI Motohiro
2009-01-15 13:43 ` KOSAKI Motohiro
2009-01-08 10:14 ` [RFC][PATCH 2/4] memcg: fix error path of mem_cgroup_move_parent Daisuke Nishimura
2009-01-08 11:00 ` KAMEZAWA Hiroyuki
2009-01-09 5:15 ` Balbir Singh
2009-01-09 5:33 ` Daisuke Nishimura
2009-01-09 6:01 ` Balbir Singh
2009-01-08 10:15 ` [RFC][PATCH 3/4] memcg: fix for mem_cgroup_hierarchical_reclaim Daisuke Nishimura
2009-01-08 11:08 ` KAMEZAWA Hiroyuki
2009-01-09 1:08 ` KAMEZAWA Hiroyuki [this message]
2009-01-09 2:51 ` Daisuke Nishimura
2009-01-09 3:09 ` KAMEZAWA Hiroyuki
2009-01-09 5:34 ` Balbir Singh
2009-01-09 5:33 ` Balbir Singh
2009-01-09 6:01 ` Daisuke Nishimura
2009-01-09 9:01 ` Daisuke Nishimura
2009-01-08 10:15 ` [RFC][PATCH 4/4] memcg: make oom less frequently Daisuke Nishimura
2009-01-08 11:19 ` KAMEZAWA Hiroyuki
2009-01-09 1:44 ` Daisuke Nishimura
2009-01-09 2:03 ` KAMEZAWA Hiroyuki
2009-01-09 2:29 ` Daisuke Nishimura
2009-01-09 2:39 ` KAMEZAWA Hiroyuki
2009-01-09 5:58 ` Balbir Singh
2009-01-09 8:52 ` Daisuke Nishimura
2009-01-09 9:03 ` Balbir Singh
2009-01-09 9:37 ` KAMEZAWA Hiroyuki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090109100830.3e9c90e0.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=balbir@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizf@cn.fujitsu.com \
--cc=menage@google.com \
--cc=nishimura@mxp.nes.nec.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox