From: Michal Hocko <mhocko@suse.cz>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Rientjes <rientjes@google.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Mandeep Singh Baines <msb@chromium.org>,
"Ma, Xindong" <xindong.ma@intel.com>,
Sameer Nanda <snanda@chromium.org>,
Sergey Dyasly <dserrg@gmail.com>,
"Tu, Xiaobing" <xiaobing.tu@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] oom_kill: add rcu_read_lock() into find_lock_task_mm()
Date: Wed, 4 Dec 2013 16:40:27 +0100 [thread overview]
Message-ID: <20131204154027.GI8410@dhcp22.suse.cz> (raw)
In-Reply-To: <20131204130420.GA6017@redhat.com>
On Wed 04-12-13 14:04:20, Oleg Nesterov wrote:
> find_lock_task_mm() expects it is called under rcu or tasklist lock,
> but it seems that at least oom_unkillable_task()->task_in_mem_cgroup()
> and mem_cgroup_out_of_memory()->oom_badness() can call it lockless.
>
> Perhaps we could fix the callers, but this patch simply adds rcu lock
> into find_lock_task_mm(). This also allows to simplify a bit one of its
> callers, oom_kill_process().
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Thanks!
> ---
> mm/oom_kill.c | 12 ++++++++----
> 1 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 0d8ad1e..054ff47 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -102,14 +102,19 @@ struct task_struct *find_lock_task_mm(struct task_struct *p)
> {
> struct task_struct *t;
>
> + rcu_read_lock();
> +
> for_each_thread(p, t) {
> task_lock(t);
> if (likely(t->mm))
> - return t;
> + goto found;
> task_unlock(t);
> }
> + t = NULL;
> +found:
> + rcu_read_unlock();
>
> - return NULL;
> + return t;
> }
>
> /* return true if the task is not adequate as candidate victim task. */
> @@ -461,10 +466,8 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
> }
> read_unlock(&tasklist_lock);
>
> - rcu_read_lock();
> p = find_lock_task_mm(victim);
> if (!p) {
> - rcu_read_unlock();
> put_task_struct(victim);
> return;
> } else if (victim != p) {
> @@ -490,6 +493,7 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
> * That thread will now get access to memory reserves since it has a
> * pending fatal signal.
> */
> + rcu_read_lock();
> for_each_process(p)
> if (p->mm == mm && !same_thread_group(p, victim) &&
> !(p->flags & PF_KTHREAD)) {
> --
> 1.5.5.1
>
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2013-12-04 15:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-04 13:03 [PATCH v2 0/4] initial while_each_thread() fixes Oleg Nesterov
2013-12-04 13:04 ` [PATCH v2 1/4] introduce for_each_thread() to replace the buggy while_each_thread() Oleg Nesterov
2013-12-04 13:28 ` Frederic Weisbecker
2013-12-04 13:49 ` Oleg Nesterov
2013-12-04 14:17 ` Frederic Weisbecker
2013-12-04 15:27 ` Oleg Nesterov
2013-12-05 0:58 ` David Rientjes
2013-12-05 18:16 ` Oleg Nesterov
2013-12-05 23:23 ` David Rientjes
2013-12-04 13:04 ` [PATCH v2 2/4] oom_kill: change oom_kill.c to use for_each_thread() Oleg Nesterov
2013-12-04 15:37 ` Michal Hocko
2013-12-05 0:39 ` David Rientjes
2013-12-04 13:04 ` [PATCH v2 3/4] oom_kill: has_intersects_mems_allowed() needs rcu_read_lock() Oleg Nesterov
2013-12-04 15:37 ` Michal Hocko
2013-12-05 0:41 ` David Rientjes
2013-12-04 13:04 ` [PATCH v2 4/4] oom_kill: add rcu_read_lock() into find_lock_task_mm() Oleg Nesterov
2013-12-04 15:40 ` Michal Hocko [this message]
2013-12-05 0:42 ` 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=20131204154027.GI8410@dhcp22.suse.cz \
--to=mhocko@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=dserrg@gmail.com \
--cc=ebiederm@xmission.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=msb@chromium.org \
--cc=oleg@redhat.com \
--cc=rientjes@google.com \
--cc=snanda@chromium.org \
--cc=xiaobing.tu@intel.com \
--cc=xindong.ma@intel.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
all inboxes | Powered by JetHome®