oom: don't try to kill oom_unkillable child
Subsystems (3)
PATCH 1/9 oom: don't try to kill oom_unkillable child
Now, badness() doesn't care neigher CPUSET nor mempolicy. Then if the victim child process have disjoint nodemask, __out_of_memory() can makes kernel hang eventually.
This patch fixes it.
--- mm/oom_kill.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
mm/oom_kill.c +9 -7
@@ -429,7 +429,7 @@ static int oom_kill_task(struct task_struct *p)static int oom_kill_process (struct task_struct *p,gfp_t gfp_mask,int order,unsigned long points,struct mem_cgroup *mem, -const char *message) +nodemask_t *nodemask,const char *message) {struct task_struct *victim = p;struct task_struct *child;
@@ -469,6 +469,8 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,continue ;if (mem && !task_in_mem_cgroup (child, mem))continue ; +if (!has_intersects_mems_allowed (child, nodemask)) +continue ;/* badness() returns 0 if the thread is unkillable */ child_points =badness (child, uptime.tv_sec);
@@ -519,7 +521,7 @@ retry:if (!p ||PTR_ERR (p) ==-1UL ) goto out; -if (oom_kill_process (p, gfp_mask,0 , points, mem, +if (oom_kill_process (p, gfp_mask,0 , points, mem,NULL ,"Memory cgroup out of memory" )) goto retry; out:
@@ -669,6 +671,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,*/ if (zonelist) constraint =constrained_alloc (zonelist, gfp_mask, nodemask); +if (constraint !=CONSTRAINT_MEMORY_POLICY ) + nodemask =NULL ;check_panic_on_oom (constraint, gfp_mask, order);read_lock (&tasklist_lock);
@@ -678,15 +682,13 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,* non-zero, current could not be killed so we must fallback to * the tasklist scan. */ -if (!oom_kill_process (current, gfp_mask, order,0 ,NULL , +if (!oom_kill_process (current, gfp_mask, order,0 ,NULL , nodemask,"Out of memory (oom_kill_allocating_task)" ))return ; } retry: - p =select_bad_process (&points,NULL , - constraint ==CONSTRAINT_MEMORY_POLICY ? nodemask : -NULL ); + p =select_bad_process (&points,NULL , nodemask);if (PTR_ERR (p) ==-1UL )return ;
@@ -697,7 +699,7 @@ retry:panic ("Out of memory and no killable processes...\n" ); } -if (oom_kill_process (p, gfp_mask, order, points,NULL , +if (oom_kill_process (p, gfp_mask, order, points,NULL , nodemask,"Out of memory" )) goto retry;read_unlock (&tasklist_lock);
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/9 oom: rename badness() to oom_badness()
badness() is wrong name because it's too generic name. rename it.
--- fs/proc/base.c | 4 +--- include/linux/oom.h | 3 +++ mm/oom_kill.c | 13 ++++++------- 3 files changed, 10 insertions(+), 10 deletions(-)
fs/proc/base.c +1 -3
@@ -427,8 +427,6 @@ static const struct file_operations proc_lstats_operations = {#endif -/* The badness from the OOM killer */ -unsigned long badness (struct task_struct *p,unsigned long uptime);static int proc_oom_score (struct task_struct *task,char *buffer) {unsigned long points =0 ;
@@ -437,7 +435,7 @@ static int proc_oom_score(struct task_struct *task, char *buffer)do_posix_clock_monotonic_gettime (&uptime);read_lock (&tasklist_lock);if (pid_alive (task)) - points =badness (task, uptime.tv_sec); + points =oom_badness (task, uptime.tv_sec);read_unlock (&tasklist_lock);return sprintf (buffer,"%lu\n" , points); }
include/linux/oom.h +3 -0
@@ -14,6 +14,7 @@struct zonelist ;struct notifier_block ; +struct task_struct ;/* * Types of limitations to the nodes from which allocations may occur
@@ -25,6 +26,8 @@ enum oom_constraint { CONSTRAINT_MEMCG, }; + +extern unsigned long oom_badness (struct task_struct *p,unsigned long uptime);extern int try_set_zonelist_oom (struct zonelist *zonelist,gfp_t gfp_flags);extern void clear_zonelist_oom (struct zonelist *zonelist,gfp_t gfp_flags);
mm/oom_kill.c +6 -7
@@ -102,7 +102,7 @@ static struct task_struct *find_lock_task_mm(struct task_struct *p) }/** -* badness - calculate a numeric value for how bad this task has been +* oom_badness - calculate a numeric value for how bad this task has been * @p: task struct of which task we should calculate * @uptime: current uptime in seconds *
@@ -119,8 +119,7 @@ static struct task_struct *find_lock_task_mm(struct task_struct *p)* algorithm has been meticulously tuned to meet the principle * of least surprise ... (be careful when you change it) */ - -unsigned long badness (struct task_struct *p,unsigned long uptime) +unsigned long oom_badness (struct task_struct *p,unsigned long uptime) {unsigned long points, cpu_time, run_time;struct task_struct *child;
@@ -336,7 +335,7 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,if (p->signal->oom_adj ==OOM_DISABLE )continue ; - points =badness (p, uptime.tv_sec); + points =oom_badness (p, uptime.tv_sec);if (points > *ppoints || !chosen) { chosen = p; *ppoints = points;
@@ -456,7 +455,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,/* * If any of p's children has a different mm and is eligible for kill, -* the one with the highest badness() score is sacrificed for its +* the one with the highest oom_badness() score is sacrificed for its * parent. This attempts to lose the minimal amount of work done while * still freeing memory. */
@@ -472,8 +471,8 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,if (!has_intersects_mems_allowed (child, nodemask))continue ; -/* badness() returns 0 if the thread is unkillable */ - child_points =badness (child, uptime.tv_sec); +/* oom_badness() returns 0 if the thread is unkillable */ + child_points =oom_badness (child, uptime.tv_sec);if (child_points > victim_points) { victim = child; victim_points = child_points;
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/9 oom: oom_kill_process() doesn't select kthread child
In reply to KOSAKI MotohiroNow, select_bad_process() have PF_KTHREAD check, but oom_kill_process doesn't. It mean oom_kill_process() may choose wrong task, especially, when the child are using use_mm().
--- mm/oom_kill.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
mm/oom_kill.c +2 -0
@@ -466,6 +466,8 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,if (child->mm == p->mm)continue ; +if (child->flags &PF_KTHREAD ) +continue ;if (mem && !task_in_mem_cgroup (child, mem))continue ;if (!has_intersects_mems_allowed (child, nodemask))
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/9 oom: oom_kill_process() need to check p is unkillable
In reply to KOSAKI MotohiroWhen oom_kill_allocating_task is enabled, an argument of oom_kill_process is not selected by select_bad_process(), but just out_of_memory() caller task. It mean the task can be unkillable. check it first.
--- mm/oom_kill.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
mm/oom_kill.c +11 -0
@@ -436,6 +436,17 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,unsigned long victim_points =0 ;struct timespec uptime; +/* +* When oom_kill_allocating_task is enabled, p can be +* unkillable. check it first. +*/ +if (is_global_init (p) || (p->flags &PF_KTHREAD )) +return 1 ; +if (mem && !task_in_mem_cgroup (p, mem)) +return 1 ; +if (!has_intersects_mems_allowed (p, nodemask)) +return 1 ; +if (printk_ratelimit ())dump_header (p, gfp_mask, order, mem);
Signature · 1 line
1.6.5.2
PATCH 5/9 oom: make oom_unkillable_task() helper function
In reply to KOSAKI MotohiroNow, we have the same task check in three places. Unify it.
--- mm/oom_kill.c | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-)
mm/oom_kill.c +23 -16
@@ -276,6 +276,26 @@ static enum oom_constraint constrained_alloc(struct zonelist *zonelist, }#endif +/* return true if the task is not adequate as candidate victim task. */ +static bool oom_unkillable_task (struct task_struct *p,struct mem_cgroup *mem, +const nodemask_t *nodemask) +{ +if (is_global_init (p)) +return true; +if (p->flags &PF_KTHREAD ) +return true; + +/* When mem_cgroup_out_of_memory() and p is not member of the group */ +if (mem && !task_in_mem_cgroup (p, mem)) +return true; + +/* p may not have freeable memory in nodemask */ +if (!has_intersects_mems_allowed (p, nodemask)) +return true; + +return false; +} +/* * Simple selection loop. We chose the process with the highest * number of 'points'. We expect the caller will lock the tasklist.
@@ -294,12 +314,7 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,for_each_process (p) {unsigned long points; -/* skip the init task and kthreads */ -if (is_global_init (p) || (p->flags &PF_KTHREAD )) -continue ; -if (mem && !task_in_mem_cgroup (p, mem)) -continue ; -if (!has_intersects_mems_allowed (p, nodemask)) +if (oom_unkillable_task (p, mem, nodemask))continue ;/*
@@ -440,11 +455,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,* When oom_kill_allocating_task is enabled, p can be * unkillable. check it first. */ -if (is_global_init (p) || (p->flags &PF_KTHREAD )) -return 1 ; -if (mem && !task_in_mem_cgroup (p, mem)) -return 1 ; -if (!has_intersects_mems_allowed (p, nodemask)) +if (oom_unkillable_task (p, mem, nodemask))return 1 ;if (printk_ratelimit ())
@@ -477,11 +488,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,if (child->mm == p->mm)continue ; -if (child->flags &PF_KTHREAD ) -continue ; -if (mem && !task_in_mem_cgroup (child, mem)) -continue ; -if (!has_intersects_mems_allowed (child, nodemask)) +if (oom_unkillable_task (child, mem, nodemask))continue ;/* oom_badness() returns 0 if the thread is unkillable */
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/9 oom: use same_thread_group instead comparing ->mm
In reply to KOSAKI MotohiroNow, oom are using "child->mm != p->mm" check to distinguish subthread. But It's incorrect. vfork() child also have the same ->mm.
This patch change to use same_thread_group() instead.
--- mm/oom_kill.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
mm/oom_kill.c +2 -2
@@ -161,7 +161,7 @@ unsigned long oom_badness(struct task_struct *p, unsigned long uptime)list_for_each_entry (c, &t->children, sibling) { child =find_lock_task_mm (c);if (child) { -if (child->mm != p->mm) +if (same_thread_group (p, child)) points += child->mm->total_vm/2 +1 ;task_unlock (child); }
@@ -486,7 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,list_for_each_entry (child, &t->children, sibling) {unsigned long child_points; -if (child->mm == p->mm) +if (same_thread_group (p, child))continue ;if (oom_unkillable_task (child, mem, nodemask))continue ;
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/9 oom: unify CAP_SYS_RAWIO check into other superuser check
In reply to KOSAKI MotohiroNow, CAP_SYS_RAWIO check is very strange. if the user have both CAP_SYS_ADMIN and CAP_SYS_RAWIO, points will makes 1/16.
Superuser's 1/4 bonus worthness is quite a bit dubious, but considerable. However 1/16 is obviously insane.
--- mm/oom_kill.c | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-)
mm/oom_kill.c +6 -11
@@ -198,19 +198,14 @@ unsigned long oom_badness(struct task_struct *p, unsigned long uptime)/* * Superuser processes are usually more important, so we make it -* less likely that we kill those. +* less likely that we kill those. And we don't want to kill a +* process with direct hardware access. Not only could that mess +* up the hardware, but usually users tend to only have this +* flag set on applications they think of as important. */ if (has_capability_noaudit (p,CAP_SYS_ADMIN ) || -has_capability_noaudit (p,CAP_SYS_RESOURCE )) - points /=4 ; - -/* -* We don't want to kill a process with direct hardware access. -* Not only could that mess up the hardware, but usually users -* tend to only have this flag set on applications they think -* of as important. -*/ -if (has_capability_noaudit (p,CAP_SYS_RAWIO )) +has_capability_noaudit (p,CAP_SYS_RESOURCE ) || +has_capability_noaudit (p,CAP_SYS_RAWIO )) points /=4 ;/*
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/9 oom: cleanup has_intersects_mems_allowed()
In reply to KOSAKI MotohiroNow has_intersects_mems_allowed() has own thread iterate logic, but it should use while_each_thread().
It slightly improve the code readability.
--- mm/oom_kill.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
mm/oom_kill.c +4 -4
@@ -46,10 +46,10 @@ static DEFINE_SPINLOCK(zone_scan_lock);* shares the same mempolicy nodes as current if it is bound by such a policy * and whether or not it has the same set of allowed cpuset nodes. */ -static bool has_intersects_mems_allowed (struct task_struct *tsk, +static bool has_intersects_mems_allowed (struct task_struct *p,const nodemask_t *mask) { -struct task_struct *start = tsk; +struct task_struct *tsk = p; do { if (mask) {
@@ -69,8 +69,8 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,if (cpuset_mems_allowed_intersects (current, tsk)) return true; } - tsk =next_thread (tsk); - }while (tsk != start); + }while_each_thread (p, tsk); +return false; }#else
Signature · 1 line
1.6.5.2
PATCH 9/9 oom: give the dying task a higher priority
In reply to KOSAKI MotohiroFrom: Luis Claudio R. Goncalves <[email protected]>
In a system under heavy load it was observed that even after the oom-killer selects a task to die, the task may take a long time to die.
Right after sending a SIGKILL to the task selected by the oom-killer this task has it's priority increased so that it can exit() exit soon, freeing memory. That is accomplished by:
/*
* We give our sacrificial lamb high priority and access to
* all the memory it needs. That way it should be able to
* exit() and clear out its resources quickly... */
p->rt.time_slice = HZ;
set_tsk_thread_flag(p, TIF_MEMDIE);
It sounds plausible giving the dying task an even higher priority to be sure it will be scheduled sooner and free the desired memory. It was suggested on LKML using SCHED_FIFO:1, the lowest RT priority so that this task won't interfere with any running RT task.
If the dying task is already an RT task, leave it untouched. Another good suggestion, implemented here, was to avoid boosting the dying task priority in case of mem_cgroup OOM.
--- mm/oom_kill.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-)
mm/oom_kill.c +35 -3
@@ -82,6 +82,28 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,#endif /* CONFIG_NUMA */ /* +* If this is a system OOM (not a memcg OOM) and the task selected to be +* killed is not already running at high (RT) priorities, speed up the +* recovery by boosting the dying task to the lowest FIFO priority. +* That helps with the recovery and avoids interfering with RT tasks. +*/ +static void boost_dying_task_prio (struct task_struct *p, +struct mem_cgroup *mem) +{ +struct sched_param param = { .sched_priority =1 }; + +if (mem) +return ; + +if (rt_task (p)) { + p->rt.time_slice =HZ ; +return ; + } + +sched_setscheduler_nocheck (p,SCHED_FIFO , ¶m); +} + +/* * 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
@@ -416,7 +438,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order, }#define K (x) ((x) << (PAGE_SHIFT-10)) -static int oom_kill_task (struct task_struct *p) +static int oom_kill_task (struct task_struct *p,struct mem_cgroup *mem) { p =find_lock_task_mm (p);if (!p || p->signal->oom_adj ==OOM_DISABLE ) {
@@ -429,9 +451,17 @@ static int oom_kill_task(struct task_struct *p) K(get_mm_counter(p->mm, MM_FILEPAGES)));task_unlock (p); - p->rt.time_slice =HZ ; +set_tsk_thread_flag (p,TIF_MEMDIE );force_sig (SIGKILL , p); + +/* +* We give our sacrificial lamb high priority and access to +* all the memory it needs. That way it should be able to +* exit() and clear out its resources quickly... +*/ +boost_dying_task_prio (p, mem); +return 0 ; }#undef K
@@ -462,6 +492,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,*/ if (p->flags &PF_EXITING ) {set_tsk_thread_flag (p,TIF_MEMDIE ); +boost_dying_task_prio (p, mem);return 0 ; }
@@ -495,7 +526,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, } }while_each_thread (p, t); -return oom_kill_task (victim); +return oom_kill_task (victim, mem); }/*
@@ -676,6 +707,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,*/ if (fatal_signal_pending (current)) {set_thread_flag (TIF_MEMDIE ); +boost_dying_task_prio (current,NULL );return ; }
Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 6/9] oom: use same_thread_group instead comparing ->mm
In reply to KOSAKI MotohiroQuoted 2 lines · KOSAKI Motohiro
Now, oom are using "
child->mm!=p->mm" check to distinguish subthread.
Heh. is it true??? I never undestood what oom_kill_process()->list_for_each_entry() is supposed to do.
Quoted 1 line
But It's incorrect.
vfork()child also have the same ->mm.
Yes.
Quoted 1 line
This patch change to use
same_thread_group()instead.
I don't think we need same_thread_group(). Please note that any children must be from the different thread_group.
So,
Quoted 12 lines
mm/oom_kill.c +1
-1@@ -161,7 +161,7 @@ unsigned long oom_badness(struct task_struct *p, unsigned long uptime)list_for_each_entry (c, &t->children, sibling) { child =find_lock_task_mm (c);if (child) { -if (child->mm != p->mm) +if (same_thread_group (p, child)) points += child->mm->total_vm/2 +1 ;task_unlock (child); }
mm/oom_kill.c static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, · line 490
Quoted 6 lines
mm/oom_kill.c +1
-1@@ -486,7 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,list_for_each_entry (child, &t->children, sibling) {unsigned long child_points; -if (child->mm == p->mm) +if (same_thread_group (p, child))continue ;
In both cases same_thread_group() must be false.
This means that the change in oom_badness() doesn't look right, "child->mm != p->mm" is the correct check to decide whether we should account child->mm.
The change in oom_kill_process() merely removes this "continue". Could someone please explain what this code _should_ do?
Oleg.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · KOSAKI Motohiro
Now,
badness()doesn't care neigher CPUSET nor mempolicy. Then if the victim child process have disjoint nodemask,__out_of_memory()can makes kernel hang eventually.This patch fixes it.
Signed-off-by KOSAKI Motohiro <[email protected]>
This patch inclues two things.
1. consider cpuset and mempolicy in oom_kill_process
2. Simplify mempolicy oom check with nodemask != NULL in select_bad_process.
1) change behavior but 2) is just cleanup.
It should have been in another patch to reivew easily. :)
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/9] oom: rename badness() to oom_badness()
In reply to KOSAKI MotohiroQuoted 4 lines · KOSAKI Motohiro
badness()is wrong name because it's too generic name. rename it.Signed-off-by KOSAKI Motohiro <[email protected]>
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/9] oom: oom_kill_process() doesn't select kthread child
In reply to KOSAKI MotohiroQuoted 3 lines · KOSAKI Motohiro
Now,
select_bad_process()havePF_KTHREADcheck, butoom_kill_processdoesn't. It meanoom_kill_process()may choose wrong task, especially, when the child are usinguse_mm().
Now oom_kill_process is called by three place.
1. mem_cgroup_out_of_memory
2. out_of_memory with sysctl_oom_kill_allocating_task
3. out_of_memory with non-sysctl_oom_kill_allocating_task
I think it's no problem in 1 and 3 since select_bad_process already checks PF_KTHREAD. The problem in in 2.
So How about put the check before calling oom_kill_process in case of sysctl_oom_kill_allocating task?
if (sysctl_oom_kill_allocating_task) {
if (!current->flags & PF_KTHREAD)
oom_kill_process();It can remove duplicated PF_KTHREAD check in select_bad_process and oom_kill_process.
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH 4/9] oom: oom_kill_process() need to check p is unkillable
In reply to KOSAKI MotohiroQuoted 19 lines · KOSAKI Motohiro
When
oom_kill_allocating_taskis enabled, an argument ofoom_kill_processis not selected byselect_bad_process(), but justout_of_memory()caller task. It mean the task can be unkillable. check it first.Signed-off-by KOSAKI Motohiro <[email protected]>--- mm/oom_kill.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)mm/oom_kill.c +1
-0@@ -436,6 +436,17 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,unsigned long victim_points =0 ;struct timespec uptime; +/*
mm/oom_kill.c static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, · line 449
Quoted 10 lines
mm/oom_kill.c +10
-0+* When oom_kill_allocating_task is enabled, p can be +* unkillable. check it first. +*/ +if (is_global_init (p) || (p->flags &PF_KTHREAD )) +return 1 ; +if (mem && !task_in_mem_cgroup (p, mem)) +return 1 ; +if (!has_intersects_mems_allowed (p, nodemask)) +return 1 ; +
I think this check could be done before oom_kill_proces in case of sysctl_oom_kill_allocating_task, too.
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 5/9] oom: make oom_unkillable_task() helper function
In reply to KOSAKI MotohiroQuoted 4 lines · KOSAKI Motohiro
Now, we have the same task check in three places. Unify it.
Signed-off-by KOSAKI Motohiro <[email protected]>
But please consider my previous comment. If I am not wrong, we need change this patch, too.
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 6/9] oom: use same_thread_group instead comparing ->mm
In reply to KOSAKI MotohiroQuoted 4 lines · KOSAKI Motohiro
Now, oom are using "
child->mm!=p->mm" check to distinguish subthread. But It's incorrect.vfork()child also have the same ->mm.This patch change to use
same_thread_group()instead.
Hmm. I think we don't use it to distinguish subthread. We use it for finding child process which is not vforked.
I can't understand your point.
Quoted 39 lines
Cc Oleg Nesterov <[email protected]>Signed-off-by KOSAKI Motohiro <[email protected]>--- mm/oom_kill.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)mm/oom_kill.c +2
-2@@ -161,7 +161,7 @@ unsigned long oom_badness(struct task_struct *p, unsigned long uptime)list_for_each_entry (c, &t->children, sibling) { child =find_lock_task_mm (c);if (child) { -if (child->mm != p->mm) +if (same_thread_group (p, child)) points += child->mm->total_vm/2 +1 ;task_unlock (child); }@@ -486,7 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,list_for_each_entry (child, &t->children, sibling) {unsigned long child_points; -if (child->mm == p->mm) +if (same_thread_group (p, child))continue ;if (oom_unkillable_task (child, mem, nodemask))continue ;Signature · 9 lines
1.6.5.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 8/9] oom: cleanup has_intersects_mems_allowed()
In reply to KOSAKI MotohiroQuoted 7 lines · KOSAKI Motohiro
Now
has_intersects_mems_allowed()has own thread iterate logic, but it should usewhile_each_thread().It slightly improve the code readability.
Signed-off-by KOSAKI Motohiro <[email protected]>
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH 9/9] oom: give the dying task a higher priority
In reply to KOSAKI MotohiroQuoted 48 lines · KOSAKI Motohiro
From: Luis Claudio R. Goncalves <[email protected]>
In a system under heavy load it was observed that even after the oom-killer selects a task to die, the task may take a long time to die.
Right after sending a SIGKILL to the task selected by the oom-killer this task has it's priority increased so that it can
exit()exit soon, freeing memory. That is accomplished by:/*
* We give our sacrificial lamb high priority and access to
* all the memory it needs. That way it should be able to
*exit()and clear out its resources quickly... */(quoted diff) +0
-0p->rt.time_slice = HZ; set_tsk_thread_flag(p, TIF_MEMDIE);It sounds plausible giving the dying task an even higher priority to be sure it will be scheduled sooner and free the desired memory. It was suggested on LKML using SCHED_FIFO:1, the lowest RT priority so that this task won't interfere with any running RT task.
If the dying task is already an RT task, leave it untouched. Another good suggestion, implemented here, was to avoid boosting the dying task priority in case of
mem_cgroupOOM.Signed-off-by Luis Claudio R. Goncalves <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by KOSAKI Motohiro <[email protected]>--- mm/oom_kill.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-)mm/oom_kill.c +6
-0@@ -82,6 +82,28 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,#endif /* CONFIG_NUMA */ /* +* If this is a system OOM (not a memcg OOM) and the task selected to be +* killed is not already running at high (RT) priorities, speed up the +* recovery by boosting the dying task to the lowest FIFO priority. +* That helps with the recovery and avoids interfering with RT tasks. +*/ +static void boost_dying_task_prio(struct task_struct *p,
mm/oom_kill.c static bool has_intersects_mems_allowed(struct task_struct *tsk, · line 100
Quoted 10 lines
mm/oom_kill.c +10
-0+ struct mem_cgroup *mem) +{ +struct sched_param param = { .sched_priority =1 }; + +if (mem) +return ; + +if (rt_task (p)) { + p->rt.time_slice =HZ ; +return ;
I have a question from long time ago.
If we change rt.time_slice _without_ setscheduler, is it effective? I mean scheduler pick up the task faster than other normal task?
Quoted 6 lines
mm/oom_kill.c +6
-0+ } + +sched_setscheduler_nocheck (p,SCHED_FIFO , ¶m); +} + +/*
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 9/9] oom: give the dying task a higher priority
On Thu, Jun 17, 2010 at 12:31:20AM +0900, Minchan Kim wrote:
| > /*
| > * We give our sacrificial lamb high priority and access to
| > * all the memory it needs. That way it should be able to
| > * exit() and clear out its resources quickly...
| > */
| > p->rt.time_slice = HZ;
| > set_tsk_thread_flag(p, TIF_MEMDIE);
...
| > + if (rt_task(p)) {
| > + p->rt.time_slice = HZ;
| > + return;I am not sure the code above will have any real effect for an RT task. Kosaki-san, was this change motivated by test results or was it just a code cleanup? I ask that out of curiosity.
| I have a question from long time ago. | If we change rt.time_slice _without_ setscheduler, is it effective? | I mean scheduler pick up the task faster than other normal task?
$ git log --pretty=oneline -Stime_slice mm/oom_kill.c 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2
This code ("time_slice = HZ;") is around for quite a while and probably comes from a time where having a big time slice was enough to be sure you would be the next on the line. I would say sched_setscheduler is indeed necessary.
Regards,
Luis
Signature · 8 lines
[ Luis Claudio R. Goncalves Red Hat - Realtime Team ] [ Fingerprint: 4FDD B8C4 3C59 34BD 8BE9 2696 7203 D980 A448 C8F8 ] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
David Rientjes
reviewerRe: [PATCH 2/9] oom: rename badness() to oom_badness()
In reply to KOSAKI MotohiroQuoted 3 lines · KOSAKI Motohiro
badness()is wrong name because it's too generic name. rename it.
This is already done in my badness heuristic rewrite, can we please focus on its review?
Re: [PATCH 4/9] oom: oom_kill_process() need to check p is unkillable
In reply to Minchan KimQuoted 19 lines · KOSAKI Motohiro
Quoted 18 lines
When
oom_kill_allocating_taskis enabled, an argument ofoom_kill_processis not selected byselect_bad_process(), but justout_of_memory()caller task. It mean the task can be unkillable. check it first.Signed-off-by KOSAKI Motohiro <[email protected]>--- mm/oom_kill.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)mm/oom_kill.c +0
-0@@ -436,6 +436,17 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,unsigned long victim_points =0 ;struct timespec uptime;
Quoted 14 lines
mm/oom_kill.c static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, · line 449
Quoted 11 lines
mm/oom_kill.c +11
-0+/* +* When oom_kill_allocating_task is enabled, p can be +* unkillable. check it first. +*/ +if (is_global_init (p) || (p->flags &PF_KTHREAD )) +return 1 ; +if (mem && !task_in_mem_cgroup (p, mem)) +return 1 ; +if (!has_intersects_mems_allowed (p, nodemask)) +return 1 ; +I think this check could be done before
oom_kill_procesin case ofsysctl_oom_kill_allocating_task, too.
ok.
Re: [PATCH 3/9] oom: oom_kill_process() doesn't select kthread child
In reply to Minchan KimQuoted 15 lines · KOSAKI Motohiro
Quoted 3 lines
Now,
select_bad_process()havePF_KTHREADcheck, butoom_kill_processdoesn't. It meanoom_kill_process()may choose wrong task, especially, when the child are usinguse_mm().Now
oom_kill_processis called by three place.1.
mem_cgroup_out_of_memory
2.out_of_memorywithsysctl_oom_kill_allocating_task
3.out_of_memorywith non-sysctl_oom_kill_allocating_taskI think it's no problem in 1 and 3 since
select_bad_processalready checksPF_KTHREAD. The problem in in 2.
So How about put the check before callingoom_kill_processin case ofsysctl_oom_kill_allocatingtask?
Quoted 6 lines
if (sysctl_oom_kill_allocating_task) { if (!current->flags & PF_KTHREAD) oom_kill_process();It can remove duplicated
PF_KTHREADcheck inselect_bad_processandoom_kill_process.
This patch changed child selection logic. select_bad_process() doesn't check victim's child. IOW, this is necessary when all 1-3.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/9] oom: rename badness() to oom_badness()
In reply to David RientjesQuoted 8 lines · KOSAKI Motohiro
Quoted 4 lines
badness()is wrong name because it's too generic name. rename it.This is already done in my badness heuristic rewrite, can we please focus on its review?
Please resend that as individual patches.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 6/9] oom: use same_thread_group instead comparing ->mm
In reply to Minchan KimQuoted 10 lines · KOSAKI Motohiro
Quoted 4 lines
Now, oom are using "
child->mm!=p->mm" check to distinguish subthread. But It's incorrect.vfork()child also have the same ->mm.This patch change to use
same_thread_group()instead.Hmm. I think we don't use it to distinguish subthread. We use it for finding child process which is not vforked.
I can't understand your point.
Thank you. my fault. respin.
Re: [PATCH 9/9] oom: give the dying task a higher priority
In reply to Luis Claudio R. GoncalvesQuoted 13 lines · Minchan Kim
| > /*
| > * We give our sacrificial lamb high priority and access to
| > * all the memory it needs. That way it should be able to
| > * exit() and clear out its resources quickly...
| > */
| > p->rt.time_slice = HZ;
| > set_tsk_thread_flag(p, TIF_MEMDIE);
...
| > + if (rt_task(p)) {
| > + p->rt.time_slice = HZ;
| > + return;Quoted 3 lines
I am not sure the code above will have any real effect for an RT task. Kosaki-san, was this change motivated by test results or was it just a code cleanup? I ask that out of curiosity.
just cleanup.
ok, I remove this dubious code.
Quoted 5 lines
| I have a question from long time ago. | If we change rt.time_slice _without_ setscheduler, is it effective? | I mean scheduler pick up the task faster than other normal task?
Quoted 7 lines
$ git log --pretty=oneline -Stime_slice mm/oom_kill.c 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2This code ("
time_slice= HZ;") is around for quite a while and probably comes from a time where having a big time slice was enough to be sure you would be the next on the line. I would saysched_setscheduleris indeed necessary.
ok
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines
Now,
badness()doesn't care neigher CPUSET nor mempolicy. Then if the victim child process have disjoint nodemask,__out_of_memory()can makes kernel hang eventually.This patch fixes it.
Signed-off-by KOSAKI Motohiro <[email protected]>Reviewed-by Minchan Kim <[email protected]>
Quoted 8 lines
This patch inclues two things.
1. consider cpuset and mempolicy in
oom_kill_process
2. Simplify mempolicy oom check with nodemask != NULL inselect_bad_process.1) change behavior but 2) is just cleanup.
It should have been in another patch to reivew easily. :)
Thank you. removed (2).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 9/9] oom: give the dying task a higher priority
In reply to Minchan KimQuoted 4 lines
Quoted 4 lines
mm/oom_kill.c +4
-0+struct sched_param param = { .sched_priority =1 }; + +if (mem) +return ;
Quoted 8 lines
mm/oom_kill.c static bool has_intersects_mems_allowed(struct task_struct *tsk, · line 100
Quoted 4 lines
mm/oom_kill.c +4
-0+ +if (rt_task (p)) { + p->rt.time_slice =HZ ; +return ;I have a question from long time ago.
If we change rt.time_slice _without_ setscheduler, is it effective? I mean scheduler pick up the task faster than other normal task?
if p is SCHED_OTHER, no effective. if my understand is correct, that's only meaningfull if p is SCHED_RR. that's the reason why I moved this check into "if (rt_task())".
but honestly I haven't observed this works effectively. so, I agree this can be removed as Luis mentioned.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 6/9] oom: use same_thread_group instead comparing ->mm
In reply to Oleg NesterovQuoted 6 lines · KOSAKI Motohiro
Quoted 2 lines
Now, oom are using "
child->mm!=p->mm" check to distinguish subthread.Heh. is it true??? I never undestood what oom_kill_process()->list_for_each_entry() is supposed to do.
I guessed. true history was gone long time ago ;) ok, I'll remove dubious guess.
Quoted 8 lines
Quoted 1 line
But It's incorrect.
vfork()child also have the same ->mm.Yes.
Quoted 1 line
This patch change to use
same_thread_group()instead.I don't think we need
same_thread_group(). Please note that any children must be from the differentthread_group.
Agghh. I see.
ok, probably, I've got correct original author intention now. To be honest, andrea's ancient patch is very hard to understand for me ;)
Quoted 24 lines
So,
Quoted 12 lines
mm/oom_kill.c +1
-1@@ -161,7 +161,7 @@ unsigned long oom_badness(struct task_struct *p, unsigned long uptime)list_for_each_entry (c, &t->children, sibling) { child =find_lock_task_mm (c);if (child) { -if (child->mm != p->mm) +if (same_thread_group (p, child)) points += child->mm->total_vm/2 +1 ;task_unlock (child); }mm/oom_kill.c static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, · line 490
Quoted 6 lines
mm/oom_kill.c +1
-1@@ -486,7 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,list_for_each_entry (child, &t->children, sibling) {unsigned long child_points; -if (child->mm == p->mm) +if (same_thread_group (p, child))continue ;In both cases
same_thread_group()must be false.
Quoted 6 lines
This means that the change in
oom_badness()doesn't look right, "child->mm!=p->mm" is the correct check to decide whether we should accountchild->mm.The change in
oom_kill_process()merely removes this "continue". Could someone please explain what this code _should_ do?
I think you are right.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>