Re: [PATCH -mmotm 7/8] memcg: avoid oom during recharge at task move

KAMEZAWA Hiroyuki
2009-11-06T06:42:00Z

On Fri, 6 Nov 2009 14:15:32 +0900
Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> wrote:

> This recharge-at-task-move feature has extra charges(pre-charges) on "to"
> mem_cgroup during recharging. This means unnecessary oom can happen.
>
> This patch tries to avoid such oom.
>
> Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
> ---
> mm/memcontrol.c | 27 +++++++++++++++++++++++++++
> 1 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index f4b7116..7e96f3b 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -248,6 +248,7 @@ struct recharge_struct {
> struct mem_cgroup *from;
> struct mem_cgroup *to;
> struct task_struct *target; /* the target task being moved */
> + struct task_struct *working; /* a task moving the target task */
> unsigned long precharge;
> };
> static struct recharge_struct recharge;
> @@ -1493,6 +1494,30 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
> if (mem_cgroup_check_under_limit(mem_over_limit))
> continue;
>
> + /* try to avoid oom while someone is recharging */
> + if (recharge.working && current != recharge.working) {
> + struct mem_cgroup *dest;
> + bool do_continue = false;
> + /*
> + * There is a small race that "dest" can be freed by
> + * rmdir, so we use css_tryget().
> + */
> + rcu_read_lock();
> + dest = recharge.to;
> + if (dest && css_tryget(&dest->css)) {
> + if (dest->use_hierarchy)
> + do_continue = css_is_ancestor(
> + &dest->css,
> + &mem_over_limit->css);
> + else
> + do_continue = (dest == mem_over_limit);
> + css_put(&dest->css);
> + }
> + rcu_read_unlock();
> + if (do_continue)
> + continue;
> + }

I think it's better to do this here, rather than continue.

==
if (do_continue) {
mutex_lock(&memcg_tasklist_lock);
mutex_unlock(&memcg_tasklist_lock);
contiue;
}
==

Thanks,
-Kame