All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm
@ 2011-07-26  0:12 David Rientjes
  2011-07-26 15:27 ` Michal Hocko
  2011-07-27  0:35 ` KOSAKI Motohiro
  0 siblings, 2 replies; 5+ messages in thread
From: David Rientjes @ 2011-07-26  0:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: KAMEZAWA Hiroyuki, KOSAKI Motohiro, linux-mm

After selecting a task to kill, the oom killer iterates all processes and
kills all other threads that share the same mm_struct in different thread
groups.  It would not otherwise be helpful to kill a thread if its memory
would not be subsequently freed.

A kernel thread, however, may assume a user thread's mm by using
use_mm().  This is only temporary and should not result in sending a
SIGKILL to that kthread.

This patch ensures that only user threads and not kthreads are sent a
SIGKILL if they share the same mm_struct as the oom killed task.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/oom_kill.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -433,7 +433,7 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 	task_unlock(p);
 
 	/*
-	 * Kill all processes sharing p->mm in other thread groups, if any.
+	 * Kill all user processes sharing p->mm in other thread groups, if any.
 	 * They don't get access to memory reserves or a higher scheduler
 	 * priority, though, to avoid depletion of all memory or task
 	 * starvation.  This prevents mm->mmap_sem livelock when an oom killed
@@ -443,7 +443,8 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 	 * signal.
 	 */
 	for_each_process(q)
-		if (q->mm == mm && !same_thread_group(q, p)) {
+		if (q->mm == mm && !same_thread_group(q, p) &&
+		    !(q->flags & PF_KTHREAD)) {
 			task_lock(q);	/* Protect ->comm from prctl() */
 			pr_err("Kill process %d (%s) sharing same memory\n",
 				task_pid_nr(q), q->comm);

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm
  2011-07-26  0:12 [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm David Rientjes
@ 2011-07-26 15:27 ` Michal Hocko
  2011-07-26 22:05   ` David Rientjes
  2011-07-27  0:35 ` KOSAKI Motohiro
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2011-07-26 15:27 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, KAMEZAWA Hiroyuki, KOSAKI Motohiro, linux-mm

On Mon 25-07-11 17:12:37, David Rientjes wrote:
> After selecting a task to kill, the oom killer iterates all processes and
> kills all other threads that share the same mm_struct in different thread
> groups.  It would not otherwise be helpful to kill a thread if its memory
> would not be subsequently freed.
> 
> A kernel thread, however, may assume a user thread's mm by using
> use_mm().  This is only temporary and should not result in sending a
> SIGKILL to that kthread.

Good catch. Have you ever seen this happening?

> 
> This patch ensures that only user threads and not kthreads are sent a
> SIGKILL if they share the same mm_struct as the oom killed task.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Reviewed-by: Michal Hocko <mhocko@suse.cz>
> ---
>  mm/oom_kill.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -433,7 +433,7 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
>  	task_unlock(p);
>  
>  	/*
> -	 * Kill all processes sharing p->mm in other thread groups, if any.
> +	 * Kill all user processes sharing p->mm in other thread groups, if any.
>  	 * They don't get access to memory reserves or a higher scheduler
>  	 * priority, though, to avoid depletion of all memory or task
>  	 * starvation.  This prevents mm->mmap_sem livelock when an oom killed
> @@ -443,7 +443,8 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
>  	 * signal.
>  	 */
>  	for_each_process(q)
> -		if (q->mm == mm && !same_thread_group(q, p)) {
> +		if (q->mm == mm && !same_thread_group(q, p) &&
> +		    !(q->flags & PF_KTHREAD)) {
>  			task_lock(q);	/* Protect ->comm from prctl() */
>  			pr_err("Kill process %d (%s) sharing same memory\n",
>  				task_pid_nr(q), q->comm);
> 

-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm
  2011-07-26 15:27 ` Michal Hocko
@ 2011-07-26 22:05   ` David Rientjes
  2011-07-27  7:59     ` Michal Hocko
  0 siblings, 1 reply; 5+ messages in thread
From: David Rientjes @ 2011-07-26 22:05 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Andrew Morton, KAMEZAWA Hiroyuki, KOSAKI Motohiro, linux-mm

On Tue, 26 Jul 2011, Michal Hocko wrote:

> > After selecting a task to kill, the oom killer iterates all processes and
> > kills all other threads that share the same mm_struct in different thread
> > groups.  It would not otherwise be helpful to kill a thread if its memory
> > would not be subsequently freed.
> > 
> > A kernel thread, however, may assume a user thread's mm by using
> > use_mm().  This is only temporary and should not result in sending a
> > SIGKILL to that kthread.
> 
> Good catch. Have you ever seen this happening?
> 

No, this is just another patch to make the kernel more use_mm()-friendly.  
Before that capability was introduced, it was possible to assume that a 
kthread would always have a NULL mm pointer, so it wasn't previously 
required for this code.

> > This patch ensures that only user threads and not kthreads are sent a
> > SIGKILL if they share the same mm_struct as the oom killed task.
> > 
> > Signed-off-by: David Rientjes <rientjes@google.com>
> 
> Reviewed-by: Michal Hocko <mhocko@suse.cz>

Thanks!

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm
  2011-07-26  0:12 [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm David Rientjes
  2011-07-26 15:27 ` Michal Hocko
@ 2011-07-27  0:35 ` KOSAKI Motohiro
  1 sibling, 0 replies; 5+ messages in thread
From: KOSAKI Motohiro @ 2011-07-27  0:35 UTC (permalink / raw)
  To: rientjes; +Cc: akpm, kamezawa.hiroyu, linux-mm

(2011/07/26 9:12), David Rientjes wrote:
> After selecting a task to kill, the oom killer iterates all processes and
> kills all other threads that share the same mm_struct in different thread
> groups.  It would not otherwise be helpful to kill a thread if its memory
> would not be subsequently freed.
> 
> A kernel thread, however, may assume a user thread's mm by using
> use_mm().  This is only temporary and should not result in sending a
> SIGKILL to that kthread.
> 
> This patch ensures that only user threads and not kthreads are sent a
> SIGKILL if they share the same mm_struct as the oom killed task.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Looks good.
	Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>


--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm
  2011-07-26 22:05   ` David Rientjes
@ 2011-07-27  7:59     ` Michal Hocko
  0 siblings, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2011-07-27  7:59 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, KAMEZAWA Hiroyuki, KOSAKI Motohiro, linux-mm

On Tue 26-07-11 15:05:23, David Rientjes wrote:
> On Tue, 26 Jul 2011, Michal Hocko wrote:
> 
> > > After selecting a task to kill, the oom killer iterates all processes and
> > > kills all other threads that share the same mm_struct in different thread
> > > groups.  It would not otherwise be helpful to kill a thread if its memory
> > > would not be subsequently freed.
> > > 
> > > A kernel thread, however, may assume a user thread's mm by using
> > > use_mm().  This is only temporary and should not result in sending a
> > > SIGKILL to that kthread.
> > 
> > Good catch. Have you ever seen this happening?
> > 
> 
> No, this is just another patch to make the kernel more use_mm()-friendly.  
> Before that capability was introduced, it was possible to assume that a 
> kthread would always have a NULL mm pointer, so it wasn't previously 
> required for this code.

OK

Thanks
-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-27  7:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-26  0:12 [patch] oom: avoid killing kthreads if they assume the oom killed thread's mm David Rientjes
2011-07-26 15:27 ` Michal Hocko
2011-07-26 22:05   ` David Rientjes
2011-07-27  7:59     ` Michal Hocko
2011-07-27  0:35 ` KOSAKI Motohiro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.