From: Oleg Nesterov <oleg@redhat.com>
To: Michal Hocko <mhocko@suse.cz>
Cc: dserrg <dserrg@gmail.com>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
David Rientjes <rientjes@google.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Sha Zhengju <handai.szj@taobao.com>
Subject: Re: [PATCH] oom: add pending SIGKILL check for chosen victim
Date: Wed, 24 Apr 2013 16:55:14 +0200 [thread overview]
Message-ID: <20130424145514.GA24997@redhat.com> (raw)
In-Reply-To: <20130423155638.GJ8001@dhcp22.suse.cz>
On 04/23, Michal Hocko wrote:
>
> [CCing Oleg]
>
> On Tue 23-04-13 19:26:14, dserrg wrote:
> > On Mon, 22 Apr 2013 21:51:38 +0200
> >
> > Yes, we are holding tasklist_lock when iterating, but the thread can be deleted
> > from thread_group list _before_ that. In this case, while_each_thread loop exit
> > condition will never be true.
Yes, while_each_thread() should be only used if know that ->thread_group
list is valid.
For example, if you do find_task_by_vpid() under rcu_read_lock()
while_each_thread() is fine _unless_ you drop rcu lock in between.
This is the common mistake, people often forget about this.
But I can't understand how this patch can fix the problem, I think it
can't.
>From the changelog:
When SIGKILL is sent to a task, it's also sent to all tasks in the same
threadgroup. This information can be used to prevent triggering further
oom killers for this threadgroup and avoid the infinite loop.
^^^^^^^^^^^^^^^^^^^^^^^
How??
> Oleg, is there anything that would prevent from this race? Maybe we need
> to call thread_group_empty before?
You need to check, say, pid_alive(). Or PF_EXITING.
For example oom_kill_process() looks wrong. It does check PF_EXITING
before while_each_thread(), but this is racy because it should check
it under tasklist_lock.
So I think that oom_kill_process() needs something like below, but
this code really needs the cleanups.
Oleg.
--- x/mm/oom_kill.c
+++ x/mm/oom_kill.c
@@ -436,6 +436,14 @@ void oom_kill_process(struct task_struct
* parent. This attempts to lose the minimal amount of work done while
* still freeing memory.
*/
+ rcu_read_lock();
+ if (!pid_alive(p)) {
+ rcu_read_unlock();
+ set_tsk_thread_flag(p, TIF_MEMDIE);
+ put_task_struct(p);
+ return;
+ }
+
read_lock(&tasklist_lock);
do {
list_for_each_entry(child, &t->children, sibling) {
@@ -458,7 +466,6 @@ void oom_kill_process(struct task_struct
} while_each_thread(p, t);
read_unlock(&tasklist_lock);
- rcu_read_lock();
p = find_lock_task_mm(victim);
if (!p) {
rcu_read_unlock();
--
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>
next prev parent reply other threads:[~2013-04-24 14:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-22 15:06 [PATCH] oom: add pending SIGKILL check for chosen victim Sergey Dyasly
2013-04-22 19:51 ` Michal Hocko
2013-04-23 15:26 ` dserrg
2013-04-23 15:56 ` Michal Hocko
2013-04-24 14:55 ` Oleg Nesterov [this message]
2013-04-24 15:22 ` Michal Hocko
2013-04-24 15:42 ` Oleg Nesterov
2013-04-24 19:33 ` Andrew Morton
2013-04-25 14:49 ` Oleg Nesterov
2013-04-25 15:41 ` Sergey Dyasly
2013-04-25 16:22 ` Oleg Nesterov
2013-05-02 17:20 ` Oleg Nesterov
2013-05-27 15:49 ` Sergey Dyasly
2013-05-27 16:16 ` Oleg Nesterov
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=20130424145514.GA24997@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dserrg@gmail.com \
--cc=handai.szj@taobao.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--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).