linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Rik van Riel <riel@redhat.com>,
	linux-mm@kvack.org
Subject: Re: [patch 2/2] oom: kill all threads sharing oom killed task's mm
Date: Sun, 15 Aug 2010 17:45:31 +0200	[thread overview]
Message-ID: <20100815154531.GB3531@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1008142130260.31510@chino.kir.corp.google.com>

Again, I do not know how the code looks without the patch, but

On 08/14, David Rientjes wrote:
>
>  static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
>  {
> +	struct task_struct *g, *q;
> +	struct mm_struct *mm;
> +
>  	p = find_lock_task_mm(p);
>  	if (!p) {
>  		task_unlock(p);
>  		return 1;
>  	}
> +
> +	/* mm cannot be safely dereferenced after task_unlock(p) */

Yes. But also we can't trust this pointer, see below.

> +	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);
>
> -
>  	set_tsk_thread_flag(p, TIF_MEMDIE);
>  	force_sig(SIGKILL, p);

So, we killed this process. It is very possible it was the only user
of this ->mm. exit_mm() can free this mmemory. After that another task
execs, exec_mmap() can allocate the same memory again.

Now,

> @@ -438,6 +444,20 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
>  	 */
>  	boost_dying_task_prio(p, mem);
>
> +	/*
> +	 * Kill all threads 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.
> +	 */
> +	do_each_thread(g, q) {
> +		if (q->mm == mm && !same_thread_group(q, p))
> +			force_sig(SIGKILL, q);
> +	} while_each_thread(g, q);

We can kill the wrong task. "q->mm == mm" doesn't necessarily mean
we found the task which shares ->mm with p (see above).

This needs atomic_inc(mm_users). And please do not use do_each_thread.


David, I apologize in advance if I won't reply to your futher emails.
I don't have the time for the kernel hacking at all.

Oleg.

--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2010-08-15 15:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-15  4:30 [patch 1/2] oom: avoid killing a task if a thread sharing its mm cannot be killed David Rientjes
2010-08-15  4:31 ` [patch 2/2] oom: kill all threads sharing oom killed task's mm David Rientjes
2010-08-15 15:45   ` Oleg Nesterov [this message]
2010-08-15 21:28     ` David Rientjes
2010-08-16  6:00       ` Oleg Nesterov
2010-08-15 15:18 ` [patch 1/2] oom: avoid killing a task if a thread sharing its mm cannot be killed Oleg Nesterov
2010-08-15 21:23   ` David Rientjes
2010-08-16  5:52     ` Oleg Nesterov
2010-08-16 10:56       ` 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=20100815154531.GB3531@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=riel@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).