Re: [PATCH] use find_lock_task_mm in memory cgroups oom

From: Minchan Kim
Date: Tue Jun 15 2010 - 05:59:31 EST


Hi, Kame.

On Tue, Jun 15, 2010 at 3:24 PM, KAMEZAWA Hiroyuki
<kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
>
> based on Âoom-introduce-find_lock_task_mm-to-fix-mm-false-positives.patch
> tested on mm-of-the-moment snapshot 2010-06-11-16-40.
>
> ==
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
>
> When the OOM killer scans task, it check a task is under memcg or
> not when it's called via memcg's context.
>
> But, as Oleg pointed out, a thread group leader may have NULL ->mm
> and task_in_mem_cgroup() may do wrong decision. We have to use
> find_lock_task_mm() in memcg as generic OOM-Killer does.
>
> Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
> Cc: Daisuke Nishimura <nishimura@xxxxxxxxxxxxxxxxx>
> Cc: Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
Reviewed-by: Minchan Kim <minchan.kim@xxxxxxxxx>

I have a trivial comment below.

> ---
> Âinclude/linux/oom.h | Â Â2 ++
> Âmm/memcontrol.c   |  10 +++++++---
> Âmm/oom_kill.c    |  Â8 ++++++--
> Â3 files changed, 15 insertions(+), 5 deletions(-)
>
> Index: mmotm-2.6.35-0611/include/linux/oom.h
> ===================================================================
> --- mmotm-2.6.35-0611.orig/include/linux/oom.h
> +++ mmotm-2.6.35-0611/include/linux/oom.h
> @@ -45,6 +45,8 @@ static inline void oom_killer_enable(voi
> Â Â Â Âoom_killer_disabled = false;
> Â}
>
> +extern struct task_struct *find_lock_task_mm(struct task_struct *p);
> +
> Â/* sysctls */
> Âextern int sysctl_oom_dump_tasks;
> Âextern int sysctl_oom_kill_allocating_task;
> Index: mmotm-2.6.35-0611/mm/memcontrol.c
> ===================================================================
> --- mmotm-2.6.35-0611.orig/mm/memcontrol.c
> +++ mmotm-2.6.35-0611/mm/memcontrol.c
> @@ -47,6 +47,7 @@
> Â#include <linux/mm_inline.h>
> Â#include <linux/page_cgroup.h>
> Â#include <linux/cpu.h>
> +#include <linux/oom.h>
> Â#include "internal.h"
>
> Â#include <asm/uaccess.h>
> @@ -838,10 +839,13 @@ int task_in_mem_cgroup(struct task_struc
> Â{
> Â Â Â Âint ret;
> Â Â Â Âstruct mem_cgroup *curr = NULL;
> + Â Â Â struct task_struct *p;
>
> - Â Â Â task_lock(task);
> - Â Â Â curr = try_get_mem_cgroup_from_mm(task->mm);
> - Â Â Â task_unlock(task);
> + Â Â Â p = find_lock_task_mm(task);
> + Â Â Â if (!p)
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â curr = try_get_mem_cgroup_from_mm(p->mm);
> + Â Â Â task_unlock(p);
> Â Â Â Âif (!curr)
> Â Â Â Â Â Â Â Âreturn 0;
> Â Â Â Â/*
> Index: mmotm-2.6.35-0611/mm/oom_kill.c
> ===================================================================
> --- mmotm-2.6.35-0611.orig/mm/oom_kill.c
> +++ mmotm-2.6.35-0611/mm/oom_kill.c
> @@ -81,13 +81,17 @@ static bool has_intersects_mems_allowed(
> Â}
> Â#endif /* CONFIG_NUMA */
>
> -/*
> +/**
> + * find_lock_task_mm - Checking a process which a task belongs to has valid mm
> + * and return a locked task which has a valid pointer to mm.
> + *

This comment should have been another patch.
BTW, below comment uses "subthread" word.
Personally it's easy to understand function's goal to me. :)

How about following as?
Checking a process which has any subthread with vaild mm
....


> + * @p: the task of a process to be checked.
> Â* The process p may have detached its own ->mm while exiting or through
> Â* use_mm(), but one or more of its subthreads may still have a valid
> Â* pointer. ÂReturn p, or any of its subthreads with a valid ->mm, with
> Â* task_lock() held.
> Â*/
> -static struct task_struct *find_lock_task_mm(struct task_struct *p)
> +struct task_struct *find_lock_task_mm(struct task_struct *p)
> Â{
> Â Â Â Âstruct task_struct *t = p;
>
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@xxxxxxxxxx ÂFor more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>
>



--
Kind regards,
Minchan Kim
--
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/