linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: mempolicy: don't select exited threads as OOM victims
@ 2019-06-29 11:24 Tetsuo Handa
  2019-07-01 11:17 ` Michal Hocko
  0 siblings, 1 reply; 13+ messages in thread
From: Tetsuo Handa @ 2019-06-29 11:24 UTC (permalink / raw)
  To: Michal Hocko, Shakeel Butt; +Cc: linux-mm, Tetsuo Handa

Since mpol_put_task_policy() in do_exit() sets mempolicy = NULL,
mempolicy_nodemask_intersects() considers exited threads (e.g. a process
with dying leader and live threads) as eligible. But it is possible that
all of live threads are still ineligible.

Since has_intersects_mems_allowed() returns true as soon as one of threads
is considered eligible, mempolicy_nodemask_intersects() needs to consider
exited threads as ineligible. Since exit_mm() in do_exit() sets mm = NULL
before mpol_put_task_policy() sets mempolicy = NULL, we can exclude exited
threads by checking whether mm is NULL.

While at it, since mempolicy_nodemask_intersects() is called by only
has_intersects_mems_allowed(), it is guaranteed that mask != NULL.

BTW, are there processes where some of threads use MPOL_{BIND,INTERLEAVE}
and the rest do not use MPOL_{BIND,INTERLEAVE} ? If no, we can use
find_lock_task_mm() instead of for_each_thread() for mask != NULL case
in has_intersects_mems_allowed().

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 mm/mempolicy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 01600d8..938f0a0 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1974,11 +1974,10 @@ bool mempolicy_nodemask_intersects(struct task_struct *tsk,
 					const nodemask_t *mask)
 {
 	struct mempolicy *mempolicy;
-	bool ret = true;
+	bool ret;
 
-	if (!mask)
-		return ret;
 	task_lock(tsk);
+	ret = tsk->mm;
 	mempolicy = tsk->mempolicy;
 	if (!mempolicy)
 		goto out;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-07-03  7:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-29 11:24 [PATCH] mm: mempolicy: don't select exited threads as OOM victims Tetsuo Handa
2019-07-01 11:17 ` Michal Hocko
2019-07-01 13:04   ` Tetsuo Handa
2019-07-01 13:17     ` Michal Hocko
2019-07-01 13:38       ` Tetsuo Handa
2019-07-01 13:48         ` Michal Hocko
2019-07-01 13:56           ` Tetsuo Handa
2019-07-01 14:04             ` Michal Hocko
2019-07-01 14:16               ` Michal Hocko
2019-07-02 13:19                 ` Tetsuo Handa
2019-07-02 13:51                   ` Michal Hocko
2019-07-02 21:26                     ` Tetsuo Handa
2019-07-03  7:06                       ` Michal Hocko

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