From: Michal Hocko <mhocko@kernel.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: linux-mm@kvack.org, rientjes@google.com, oleg@redhat.com,
vdavydov@parallels.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] mm, oom: do not loop over all tasks if there are no external tasks sharing mm
Date: Fri, 27 May 2016 10:03:20 +0200 [thread overview]
Message-ID: <20160527080319.GD27686@dhcp22.suse.cz> (raw)
In-Reply-To: <20160527071507.GC27686@dhcp22.suse.cz>
On Fri 27-05-16 09:15:07, Michal Hocko wrote:
> On Fri 27-05-16 08:45:10, Michal Hocko wrote:
> [...]
> > It is still an operation which is not needed for 99% of situations. So
> > if we do not need it for correctness then I do not think this is worth
> > bothering.
>
> Since you have pointed out exit_mm vs. __exit_signal race yesterday I
> was thinking how to make the check reliable. Even
> atomic_read(mm->mm_users) > get_nr_threads() is not reliable and we can
> miss other tasks just because the current thread group is mostly past
> exit_mm. So far I couldn't find a way to tweak this around though.
Just for the record I was playing with the following yesterday but I
couldn't convince myself that this is safe and reasonable in the first
place (I do not like it to be honest).
---
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 1685890d424e..db027eca8be5 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -123,6 +123,35 @@ struct task_struct *find_lock_task_mm(struct task_struct *p)
return t;
}
+bool task_has_external_users(struct task_struct *p)
+{
+ struct mm_struct *mm = NULL;
+ struct task_struct *t;
+ int active_threads = 0;
+ bool ret = true; /* be pessimistic */
+
+ rcu_read_lock();
+ for_each_thread(p, t) {
+ task_lock(t);
+ if (likely(t->mm)) {
+ active_threads++;
+ if (!mm) {
+ mm = t->mm;
+ atomic_inc(&mm->mm_count);
+ }
+ }
+ task_unlock(t);
+ }
+ rcu_read_unlock();
+
+ if (mm) {
+ if (atomic_read(&mm->mm_users) <= active_threads)
+ ret = false;
+ mmdrop(mm);
+ }
+ return ret;
+}
+
/*
* order == -1 means the oom kill is required by sysrq, otherwise only
* for display purposes.
--
Michal Hocko
SUSE Labs
--
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:[~2016-05-27 8:03 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-26 12:40 [PATCH 0/5] Handle oom bypass more gracefully Michal Hocko
2016-05-26 12:40 ` [PATCH 1/6] mm, oom: do not loop over all tasks if there are no external tasks sharing mm Michal Hocko
2016-05-26 14:30 ` Tetsuo Handa
2016-05-26 14:59 ` Michal Hocko
2016-05-26 15:25 ` [PATCH 1/6] mm, oom: do not loop over all tasks if there are noexternal " Tetsuo Handa
2016-05-26 15:35 ` Michal Hocko
2016-05-26 16:14 ` [PATCH 1/6] mm, oom: do not loop over all tasks if there are no external " Tetsuo Handa
2016-05-27 6:45 ` Michal Hocko
2016-05-27 7:15 ` Michal Hocko
2016-05-27 8:03 ` Michal Hocko [this message]
2016-05-27 10:15 ` Tetsuo Handa
2016-05-26 12:40 ` [PATCH 2/6] proc, oom_adj: extract oom_score_adj setting into a helper Michal Hocko
2016-05-26 12:40 ` [PATCH 3/6] mm, oom_adj: make sure processes sharing mm have same view of oom_score_adj Michal Hocko
2016-05-27 11:18 ` Michal Hocko
2016-05-27 16:18 ` Vladimir Davydov
2016-05-30 7:07 ` Michal Hocko
2016-05-30 8:47 ` Vladimir Davydov
2016-05-30 9:39 ` Michal Hocko
2016-05-30 10:26 ` Vladimir Davydov
2016-05-30 11:11 ` Michal Hocko
2016-05-30 12:19 ` Vladimir Davydov
2016-05-30 12:28 ` Michal Hocko
2016-05-26 12:40 ` [PATCH 4/6] mm, oom: skip over vforked tasks Michal Hocko
2016-05-27 16:48 ` Vladimir Davydov
2016-05-30 7:13 ` Michal Hocko
2016-05-30 9:52 ` Michal Hocko
2016-05-30 10:40 ` Vladimir Davydov
2016-05-30 10:53 ` Michal Hocko
2016-05-30 12:03 ` Michal Hocko
2016-05-26 12:40 ` [PATCH 5/6] mm, oom: kill all tasks sharing the mm Michal Hocko
2016-05-26 12:40 ` [PATCH 6/6] mm, oom: fortify task_will_free_mem Michal Hocko
[not found] ` <201605262311.FFF64092.FFQVtOLOOMJSFH@I-love.SAKURA.ne.jp>
[not found] ` <20160526142317.GC23675@dhcp22.suse.cz>
2016-05-26 14:41 ` Tetsuo Handa
2016-05-26 14:56 ` Michal Hocko
2016-05-27 11:07 ` Michal Hocko
2016-05-27 16:00 ` [PATCH 0/5] Handle oom bypass more gracefully Michal Hocko
2016-05-28 14:04 ` Tetsuo Handa
2016-05-30 7:21 ` Michal Hocko
2016-05-30 11:10 ` Tetsuo Handa
2016-05-30 11:35 ` Michal Hocko
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=20160527080319.GD27686@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oleg@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rientjes@google.com \
--cc=vdavydov@parallels.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