From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>,
"menage@google.com" <menage@google.com>,
"kosaki.motohiro@jp.fujitsu.com" <kosaki.motohiro@jp.fujitsu.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH 6/6] fix oom under hierarchy
Date: Tue, 9 Dec 2008 20:12:25 +0900 [thread overview]
Message-ID: <20081209201225.710e9f0b.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20081209200213.0e2128c1.kamezawa.hiroyu@jp.fujitsu.com>
From: KAMEZAWA Hiroyki <kamezawa.hiroyu@jp.fujitsu.com>
Current memcg's code other than memcontrol.c cannot handle hierarchy
in correct way.
In following,
/opt/cgroup/01 limit=1G
/opt/cgroup/01/A limit = unlimited
/opt/cgroup/01/B limit = unlimited
searching tasks under '01' and cannot find bad process in 01/A and 01/B
After this.
- OOM Killer check hierarchy and can Kill badprocess under hierarchy.
Changelog:
- adjusted to the base kernel.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
include/linux/memcontrol.h | 6 +++-
mm/memcontrol.c | 57 ++++++++++++++++++++++++++++++++++++++++++---
mm/oom_kill.c | 2 -
3 files changed, 59 insertions(+), 6 deletions(-)
Index: mmotm-2.6.28-Dec08/mm/memcontrol.c
===================================================================
--- mmotm-2.6.28-Dec08.orig/mm/memcontrol.c
+++ mmotm-2.6.28-Dec08/mm/memcontrol.c
@@ -403,12 +403,36 @@ void mem_cgroup_move_lists(struct page *
mem_cgroup_add_lru_list(page, to);
}
-int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
+static int mm_under_cgroup(struct mm_struct *mm, struct mem_cgroup *mcg)
+{
+ struct cgroup *cg, *check;
+ int ret = 0;
+
+ if (!mm)
+ return 0;
+
+ rcu_read_lock();
+
+ cg = task_cgroup(rcu_dereference(mm->owner), mem_cgroup_subsys_id);
+ check = mcg->css.cgroup;
+
+ if (!mcg->use_hierarchy)
+ ret = (cg == check);
+ else
+ ret = cgroup_is_ancestor(cg, check);
+ rcu_read_unlock();
+
+ return ret;
+}
+
+
+int task_in_mem_cgroup(struct task_struct *task,
+ struct mem_cgroup *mem)
{
int ret;
task_lock(task);
- ret = task->mm && mm_match_cgroup(task->mm, mem);
+ ret = mm_under_cgroup(task->mm, mem);
task_unlock(task);
return ret;
}
@@ -662,6 +686,33 @@ static int mem_cgroup_hierarchical_recla
return ret;
}
+void update_oom_jiffies(struct mem_cgroup *mem)
+{
+ struct cgroup *cgroup, *rootcg;
+ struct mem_cgroup *tmp;
+ int rootid, nextid, depth, found;
+
+ if (!mem->use_hierarchy) {
+ mem->last_oom_jiffies = jiffies;
+ return;
+ }
+ rootcg = mem->css.cgroup;
+ rootid = cgroup_id(rootcg);
+ depth = cgroup_depth(rootcg);
+ nextid = 0;
+ rcu_read_lock();
+ while (1) {
+ cgroup = cgroup_get_next(nextid, rootid, depth, &found);
+
+ if (!cgroup)
+ break;
+ tmp = mem_cgroup_from_cont(cgroup);
+ tmp->last_oom_jiffies = jiffies;
+ nextid = found + 1;
+ }
+ rcu_read_unlock();
+}
+
bool mem_cgroup_oom_called(struct task_struct *task)
{
bool ret = false;
@@ -764,7 +815,7 @@ static int __mem_cgroup_try_charge(struc
mutex_lock(&memcg_tasklist);
mem_cgroup_out_of_memory(mem_over_limit, gfp_mask);
mutex_unlock(&memcg_tasklist);
- mem_over_limit->last_oom_jiffies = jiffies;
+ update_oom_jiffies(mem_over_limit);
}
goto nomem;
}
Index: mmotm-2.6.28-Dec08/mm/oom_kill.c
===================================================================
--- mmotm-2.6.28-Dec08.orig/mm/oom_kill.c
+++ mmotm-2.6.28-Dec08/mm/oom_kill.c
@@ -279,7 +279,7 @@ static struct task_struct *select_bad_pr
*
* Call with tasklist_lock read-locked.
*/
-static void dump_tasks(const struct mem_cgroup *mem)
+static void dump_tasks(struct mem_cgroup *mem)
{
struct task_struct *g, *p;
Index: mmotm-2.6.28-Dec08/include/linux/memcontrol.h
===================================================================
--- mmotm-2.6.28-Dec08.orig/include/linux/memcontrol.h
+++ mmotm-2.6.28-Dec08/include/linux/memcontrol.h
@@ -65,7 +65,9 @@ extern unsigned long mem_cgroup_isolate_
struct mem_cgroup *mem_cont,
int active, int file);
extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
-int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
+
+int task_in_mem_cgroup(struct task_struct *task, struct mem_cgroup *mem);
+
extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
@@ -191,7 +193,7 @@ static inline int mm_match_cgroup(struct
}
static inline int task_in_mem_cgroup(struct task_struct *task,
- const struct mem_cgroup *mem)
+ struct mem_cgroup *mem)
{
return 1;
}
--
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>
prev parent reply other threads:[~2008-12-09 11:13 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-09 11:02 [RFC][PATCH 0/6] cgroup id and mix fixes (2008/12/09) KAMEZAWA Hiroyuki
2008-12-09 11:04 ` [RFC][PATCH 1/6] memcg: Documentation for internal implementation KAMEZAWA Hiroyuki
2008-12-10 0:27 ` KAMEZAWA Hiroyuki
2008-12-10 1:02 ` Li Zefan
2008-12-10 1:07 ` KAMEZAWA Hiroyuki
2008-12-09 11:06 ` [RFC][PATCH 1/6] memcg: fix pre_destory handler KAMEZAWA Hiroyuki
2008-12-10 2:08 ` KAMEZAWA Hiroyuki
2008-12-10 2:19 ` Li Zefan
2008-12-10 2:23 ` KAMEZAWA Hiroyuki
2008-12-10 2:28 ` Daisuke Nishimura
2008-12-10 2:58 ` KAMEZAWA Hiroyuki
2008-12-10 3:03 ` Daisuke Nishimura
2008-12-10 4:17 ` KAMEZAWA Hiroyuki
2008-12-10 10:40 ` Paul Menage
2008-12-10 11:29 ` KAMEZAWA Hiroyuki
2008-12-10 13:25 ` Balbir Singh
2008-12-10 13:47 ` Daisuke Nishimura
2008-12-10 18:26 ` Paul Menage
2008-12-10 18:25 ` Paul Menage
2008-12-10 18:35 ` Paul Menage
2008-12-10 19:00 ` Paul Menage
2008-12-11 0:21 ` KAMEZAWA Hiroyuki
2008-12-11 0:24 ` Paul Menage
2008-12-11 1:06 ` KAMEZAWA Hiroyuki
2008-12-11 12:43 ` KAMEZAWA Hiroyuki
2008-12-11 0:25 ` KAMEZAWA Hiroyuki
2008-12-11 0:28 ` Paul Menage
2008-12-11 1:09 ` KAMEZAWA Hiroyuki
2008-12-09 11:08 ` [RFC][PATCH 2/6] cgroup id KAMEZAWA Hiroyuki
2008-12-09 11:09 ` [RFC][PATCH 4/6] Flat hierarchical reclaim by ID KAMEZAWA Hiroyuki
2008-12-09 12:27 ` Balbir Singh
2008-12-09 14:28 ` KAMEZAWA Hiroyuki
2008-12-09 15:46 ` Balbir Singh
2008-12-09 16:34 ` KAMEZAWA Hiroyuki
2008-12-10 2:49 ` Balbir Singh
2008-12-10 3:03 ` KAMEZAWA Hiroyuki
2008-12-09 11:10 ` [RFC][PATCH 5/6] fix inactive_ratio under hierarchy KAMEZAWA Hiroyuki
2008-12-11 3:14 ` KOSAKI Motohiro
2008-12-11 3:19 ` KAMEZAWA Hiroyuki
2008-12-09 11:12 ` KAMEZAWA Hiroyuki [this message]
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=20081209201225.710e9f0b.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=balbir@linux.vnet.ibm.com \
--cc=kosaki.motohiro@jp.fujitsu.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