linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: mhocko@kernel.org, akpm@linux-foundation.org
Cc: mgorman@suse.de, rientjes@google.com,
	torvalds@linux-foundation.org, oleg@redhat.com, hughd@google.com,
	andrea@kernel.org, riel@redhat.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] mm,oom: Always sleep before retrying.
Date: Wed, 30 Dec 2015 11:01:42 +0900	[thread overview]
Message-ID: <201512301101.GJD12974.LOVFFtFMOHOJSQ@I-love.SAKURA.ne.jp> (raw)

>From c0b5820c594343e06239f15afb35d23b4b8ac0d0 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Wed, 30 Dec 2015 10:55:59 +0900
Subject: [PATCH] mm,oom: Always sleep before retrying.

When we entered into "Reclaim has failed us, start killing things"
state, sleep function is called only when mutex_trylock(&oom_lock)
in __alloc_pages_may_oom() failed or immediately after returning from
oom_kill_process() in out_of_memory(). This may be insufficient for
giving other tasks a chance to run because mutex_trylock(&oom_lock)
will not fail under non-preemptive UP kernel.

If it is a !__GFP_FS && !__GFP_NOFAIL allocation request,
__alloc_pages_may_oom() will return without sleeping, and
__alloc_pages_slowpath() will retry without sleeping.
As a result, other tasks will never acquire a chance to run.

If it is a __GFP_FS || __GFP_NOFAIL allocation request, out_of_memory()
will be called. But if the OOM victim failed to terminate before
schedule_timeout_killable(1) returns, the victim will never acquire
a chance to run again because the task which called out_of_memory()
will not sleep again.

We should not rely on mutex_trylock(&oom_lock) for a sleep. This patch
makes sure everybody sleeps before __alloc_pages_slowpath() retries.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 mm/page_alloc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2565154..6f7f786 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2734,7 +2734,6 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
 	 */
 	if (!mutex_trylock(&oom_lock)) {
 		*did_some_progress = 1;
-		schedule_timeout_uninterruptible(1);
 		return NULL;
 	}
 
@@ -3282,6 +3281,12 @@ retry:
 	/* Retry as long as the OOM killer is making progress */
 	if (did_some_progress) {
 		no_progress_loops = 0;
+		/*
+		 * Make sure that other tasks (e.g. OOM victims, workqueue
+		 * items) are given a chance to run.
+		 */
+		if (!test_thread_flag(TIF_MEMDIE))
+			schedule_timeout_uninterruptible(1);
 		goto retry;
 	}
 
-- 
1.8.3.1

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

             reply	other threads:[~2015-12-30  2:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-30  2:01 Tetsuo Handa [this message]
2016-01-01  7:54 ` Tetsuo Handa

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=201512301101.GJD12974.LOVFFtFMOHOJSQ@I-love.SAKURA.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=akpm@linux-foundation.org \
    --cc=andrea@kernel.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@kernel.org \
    --cc=oleg@redhat.com \
    --cc=riel@redhat.com \
    --cc=rientjes@google.com \
    --cc=torvalds@linux-foundation.org \
    /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