linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	linux-mm@kvack.org
Subject: Re: [patch 2/3] mm, oom: fold oom_kill_task into oom_kill_process
Date: Thu, 12 Jan 2012 13:48:14 +0900	[thread overview]
Message-ID: <20120112134814.a24fda31.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1201111923490.3982@chino.kir.corp.google.com>

On Wed, 11 Jan 2012 19:24:24 -0800 (PST)
David Rientjes <rientjes@google.com> wrote:

> oom_kill_task() has a single caller, so fold it into its parent function,
> oom_kill_process().  Slightly reduces the number of lines in the oom
> killer.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>


> ---
>  mm/oom_kill.c |   87 ++++++++++++++++++++++++++------------------------------
>  1 files changed, 40 insertions(+), 47 deletions(-)
> 
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -434,52 +434,6 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
>  }
>  
>  #define K(x) ((x) << (PAGE_SHIFT-10))
> -static void oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
> -{
> -	struct task_struct *q;
> -	struct mm_struct *mm;
> -
> -	p = find_lock_task_mm(p);
> -	if (!p)
> -		return;
> -
> -	/* mm cannot be safely dereferenced after task_unlock(p) */
> -	mm = p->mm;
> -
> -	pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
> -		task_pid_nr(p), p->comm, K(p->mm->total_vm),
> -		K(get_mm_counter(p->mm, MM_ANONPAGES)),
> -		K(get_mm_counter(p->mm, MM_FILEPAGES)));
> -	task_unlock(p);
> -
> -	/*
> -	 * 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
> -	 * task cannot exit because it requires the semaphore and its contended
> -	 * by another thread trying to allocate memory itself.  That thread will
> -	 * now get access to memory reserves since it has a pending fatal
> -	 * signal.
> -	 */
> -	for_each_process(q)
> -		if (q->mm == mm && !same_thread_group(q, p) &&
> -		    !(q->flags & PF_KTHREAD)) {
> -			if (q->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
> -				continue;
> -
> -			task_lock(q);	/* Protect ->comm from prctl() */
> -			pr_err("Kill process %d (%s) sharing same memory\n",
> -				task_pid_nr(q), q->comm);
> -			task_unlock(q);
> -			force_sig(SIGKILL, q);
> -		}
> -
> -	set_tsk_thread_flag(p, TIF_MEMDIE);
> -	force_sig(SIGKILL, p);
> -}
> -#undef K
> -
>  static void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
>  			     unsigned int points, unsigned long totalpages,
>  			     struct mem_cgroup *mem, nodemask_t *nodemask,
> @@ -488,6 +442,7 @@ static void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
>  	struct task_struct *victim = p;
>  	struct task_struct *child;
>  	struct task_struct *t = p;
> +	struct mm_struct *mm;
>  	unsigned int victim_points = 0;
>  
>  	if (printk_ratelimit())
> @@ -531,8 +486,46 @@ static void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
>  		}
>  	} while_each_thread(p, t);
>  
> -	oom_kill_task(victim, mem);
> +	victim = find_lock_task_mm(victim);
> +	if (!victim)
> +		return;
> +
> +	/* mm cannot be safely dereferenced after task_unlock(p) */
> +	mm = victim->mm;
> +
> +	pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
> +		task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
> +		K(get_mm_counter(victim->mm, MM_ANONPAGES)),
> +		K(get_mm_counter(victim->mm, MM_FILEPAGES)));
> +	task_unlock(victim);
> +
> +	/*
> +	 * Kill all user processes sharing victim->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
> +	 * task cannot exit because it requires the semaphore and its contended
> +	 * by another thread trying to allocate memory itself.  That thread will
> +	 * now get access to memory reserves since it has a pending fatal
> +	 * signal.
> +	 */
> +	for_each_process(p)
> +		if (p->mm == mm && !same_thread_group(p, victim) &&
> +		    !(p->flags & PF_KTHREAD)) {
> +			if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
> +				continue;
> +
> +			task_lock(p);	/* Protect ->comm from prctl() */
> +			pr_err("Kill process %d (%s) sharing same memory\n",
> +				task_pid_nr(p), p->comm);
> +			task_unlock(p);
> +			force_sig(SIGKILL, p);
> +		}
> +
> +	set_tsk_thread_flag(victim, TIF_MEMDIE);
> +	force_sig(SIGKILL, victim);
>  }
> +#undef K
>  
>  /*
>   * Determines whether the kernel must panic because of the panic_on_oom sysctl.
> 

--
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>

  parent reply	other threads:[~2012-01-12  4:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-12  3:24 [patch 1/3] mm, oom: avoid looping when chosen thread detaches its mm David Rientjes
2012-01-12  3:24 ` [patch 2/3] mm, oom: fold oom_kill_task into oom_kill_process David Rientjes
2012-01-12  3:48   ` KOSAKI Motohiro
2012-01-12  4:48   ` KAMEZAWA Hiroyuki [this message]
2012-01-12  3:24 ` [patch 3/3] mm, oom: do not emit oom killer warning if chosen thread is already exiting David Rientjes
2012-01-12  3:48   ` KOSAKI Motohiro
2012-01-12  4:49   ` KAMEZAWA Hiroyuki
2012-01-12 14:44   ` Michal Hocko
2012-01-12  4:47 ` [patch 1/3] mm, oom: avoid looping when chosen thread detaches its mm KAMEZAWA Hiroyuki
2012-01-12 14:26 ` Michal Hocko
2012-01-14  0:39 ` [patch -mm " David Rientjes
2012-01-14  0:39   ` [patch -mm 2/3] mm, oom: fold oom_kill_task into oom_kill_process David Rientjes
2012-01-14  0:39   ` [patch -mm 3/3] mm, oom: do not emit oom killer warning if chosen thread is already exiting David Rientjes

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=20120112134814.a24fda31.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    /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