linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm, oom: don't invoke oom killer if current has been reapered
@ 2020-07-11  3:18 Yafang Shao
  2020-07-11  5:37 ` Yafang Shao
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Yafang Shao @ 2020-07-11  3:18 UTC (permalink / raw)
  To: mhocko, rientjes, akpm; +Cc: linux-mm, Yafang Shao

If the current's MMF_OOM_SKIP is set, it means that the current is exiting
or dying and likely to realease its address space. So we don't need to
invoke the oom killer again. Otherwise that may cause some unexpected
issues, for example, bellow is the issue found in our production
environment.

There're many threads of a multi-threaded task parallel running in a
container on many cpus. Then many threads triggered OOM at the same time,

CPU-1	        CPU-2         ...        CPU-n
thread-1        thread-2      ...        thread-n

wait oom_lock   wait oom_lock ...        hold oom_lock

                                         (sigkill received)

                                         select current as victim
                                         and wakeup oom reaper

                                         release oom_lock

                                         (MMF_OOM_SKIP set by oom reaper)

                                         (lots of pages are freed)
hold oom_lock

because MMF_OOM_SKIP
is set, kill others

The thread running on CPU-n received sigkill and it will select current as
the victim and wakeup the oom reaper. Then oom reaper will reap its rss and
free lots of pages, as a result, there will be many free pages.
Although the multi-threaded task is exiting, the other threads will
continue to kill others because of the check of MMF_OOM_SKIP in
task_will_free_mem().

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 mm/oom_kill.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 6e94962..a8a155a 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -825,13 +825,6 @@ static bool task_will_free_mem(struct task_struct *task)
 	if (!__task_will_free_mem(task))
 		return false;
 
-	/*
-	 * This task has already been drained by the oom reaper so there are
-	 * only small chances it will free some more
-	 */
-	if (test_bit(MMF_OOM_SKIP, &mm->flags))
-		return false;
-
 	if (atomic_read(&mm->mm_users) <= 1)
 		return true;
 
@@ -963,7 +956,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
 	 * so it can die quickly
 	 */
 	task_lock(victim);
-	if (task_will_free_mem(victim)) {
+	if (!test_bit(MMF_OOM_SKIP, &victim->mm->flags) &&
+	    task_will_free_mem(victim)) {
 		mark_oom_victim(victim);
 		wake_oom_reaper(victim);
 		task_unlock(victim);
@@ -1056,6 +1050,10 @@ bool out_of_memory(struct oom_control *oc)
 			return true;
 	}
 
+	/* current has been already reapered */
+	if (test_bit(MMF_OOM_SKIP, &current->mm->flags))
+		return true;
+
 	/*
 	 * If current has a pending SIGKILL or is exiting, then automatically
 	 * select it.  The goal is to allow it to allocate so that it may
-- 
1.8.3.1



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

end of thread, other threads:[~2020-07-14  9:31 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11  3:18 [PATCH] mm, oom: don't invoke oom killer if current has been reapered Yafang Shao
2020-07-11  5:37 ` Yafang Shao
2020-07-13  6:01 ` Michal Hocko
2020-07-13  6:21   ` Michal Hocko
2020-07-13 12:24     ` Yafang Shao
2020-07-13 12:45       ` Michal Hocko
2020-07-13 13:11         ` Yafang Shao
2020-07-13 19:05           ` Michal Hocko
2020-07-14  0:15             ` Tetsuo Handa
2020-07-14  0:18               ` Tetsuo Handa
2020-07-14  2:09             ` Yafang Shao
2020-07-13 23:50 ` Tetsuo Handa
2020-07-14  2:13   ` Yafang Shao
2020-07-14  2:42     ` Tetsuo Handa
2020-07-14  2:58       ` Yafang Shao
2020-07-14  4:06         ` Tetsuo Handa
2020-07-14  5:03           ` Yafang Shao
2020-07-14  6:51           ` Michal Hocko
2020-07-14  6:43   ` Michal Hocko
2020-07-14  9:30     ` Yafang Shao

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