cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.cz>
To: David Rientjes <rientjes@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	cgroups@vger.kernel.org
Subject: Re: [patch 1/2] mm, memcg: avoid oom notification when current needs access to memory reserves
Date: Thu, 12 Dec 2013 13:11:40 +0100	[thread overview]
Message-ID: <20131212121140.GD2630@dhcp22.suse.cz> (raw)
In-Reply-To: <20131212103159.GB2630@dhcp22.suse.cz>

On Thu 12-12-13 11:31:59, Michal Hocko wrote:
[...]
> The semantic would be as simple as "notification is sent only when
> an action is due". It will be still racy as nothing prevents a task
> which is not under OOM to exit and release some memory but there is no
> sensible way to address that. On the other hand such a semantic would be
> sensible for oom_control listeners because they will know that an action
> has to be or will be taken (the line was drawn).
> 
> Can we agree on this, Johannes? Or you see the line drawn when
> mem_cgroup_oom_synchronize has been reached already no matter whether
> the action is to be done or not?

Something like the following:

From 5d9c01e2814a7ade49db7945ad3890f4f138855e Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.cz>
Date: Thu, 12 Dec 2013 11:50:17 +0100
Subject: [PATCH] memcg: notify userspace about OOM when and action is due

Userspace is currently notified about OOM condition after fails
to reclaim any memory after MEM_CGROUP_RECLAIM_RETRIES rounds.
This usually means that the memcg is really in troubles and an
OOM action (either done by userspace or kernel) has to be taken.
The kernel OOM killer however bails out and doesn't kill anything
if it sees an already dying/exiting task in a good hope a memory
will be released and OOM situation will be resolved.

Therefore it makes sense to notify userspace only after really all
measures have been taken and an userspace action is required or
the kernel kills a task.

This patch also removes fatal_signal_pending and PF_EXITING check from
mem_cgroup_oom_synchronize because __mem_cgroup_try_charge already
checks for both and bypasses charge so we cannot end up in the oom path.

Signed-off-by: Michal Hocko <mhocko@suse.cz>
---
 mm/memcontrol.c | 17 ++++-------------
 mm/oom_kill.c   |  5 +++++
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 98900c070045..af7148c77bac 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2235,16 +2235,6 @@ bool mem_cgroup_oom_synchronize(bool handle)
 	if (!handle)
 		goto cleanup;
 
-	/*
-	 * 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
-	 * quickly exit and free its memory.
-	 */
-	if (fatal_signal_pending(current) || current->flags & PF_EXITING) {
-		set_thread_flag(TIF_MEMDIE);
-		goto cleanup;
-	}
-
 	owait.memcg = memcg;
 	owait.wait.flags = 0;
 	owait.wait.func = memcg_oom_wake_function;
@@ -2256,15 +2246,16 @@ bool mem_cgroup_oom_synchronize(bool handle)
 
 	locked = mem_cgroup_oom_trylock(memcg);
 
-	if (locked)
-		mem_cgroup_oom_notify(memcg);
-
 	if (locked && !memcg->oom_kill_disable) {
 		mem_cgroup_unmark_under_oom(memcg);
 		finish_wait(&memcg_oom_waitq, &owait.wait);
+		/* calls mem_cgroup_oom_notify if there is a task to kill */
 		mem_cgroup_out_of_memory(memcg, current->memcg_oom.gfp_mask,
 					 current->memcg_oom.order);
 	} else {
+		if (locked && memcg->oom_kill_disable)
+			mem_cgroup_oom_notify(memcg);
+
 		schedule();
 		mem_cgroup_unmark_under_oom(memcg);
 		finish_wait(&memcg_oom_waitq, &owait.wait);
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 1e4a600a6163..47c9de8da36d 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -394,6 +394,8 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 		dump_tasks(memcg, nodemask);
 }
 
+extern void mem_cgroup_oom_notify(struct mem_cgroup *memcg);
+
 #define K(x) ((x) << (PAGE_SHIFT-10))
 /*
  * Must be called while holding a reference to p, which will be released upon
@@ -470,6 +472,9 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 		victim = p;
 	}
 
+	if (memcg)
+		mem_cgroup_oom_notify(memcg);
+
 	/* mm cannot safely be dereferenced after task_unlock(victim) */
 	mm = victim->mm;
 	pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
-- 
1.8.4.4

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

  parent reply	other threads:[~2013-12-12 12:11 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-31  1:39 [patch] mm, memcg: add memory.oom_control notification for system oom David Rientjes
     [not found] ` <alpine.DEB.2.02.1310301838300.13556-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-10-31  5:49   ` Johannes Weiner
     [not found]     ` <20131031054942.GA26301-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-11-13 22:19       ` David Rientjes
     [not found]         ` <alpine.DEB.2.02.1311131416460.23211-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-11-13 23:34           ` Johannes Weiner
2013-11-14  0:56             ` David Rientjes
2013-11-14  3:25               ` Johannes Weiner
     [not found]                 ` <20131114032508.GL707-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-11-14 22:57                   ` David Rientjes
2013-11-14 23:26                     ` [patch 1/2] mm, memcg: avoid oom notification when current needs access to memory reserves David Rientjes
2013-11-14 23:26                       ` [patch 2/2] mm, memcg: add memory.oom_control notification for system oom David Rientjes
2013-11-18 18:52                         ` Michal Hocko
     [not found]                           ` <20131118185213.GA12923-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-11-19  1:25                             ` David Rientjes
     [not found]                               ` <alpine.DEB.2.02.1311181722380.4292-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-11-19 12:41                                 ` Michal Hocko
     [not found]                       ` <alpine.DEB.2.02.1311141525440.30112-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-11-18 12:52                         ` [patch 1/2] mm, memcg: avoid oom notification when current needs access to memory reserves Michal Hocko
     [not found]                           ` <20131118125240.GC32623-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-11-18 12:55                             ` Michal Hocko
2013-11-19  1:19                               ` David Rientjes
2013-11-18 15:41                         ` Johannes Weiner
     [not found]                           ` <20131118154115.GA3556-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-11-18 16:51                             ` Michal Hocko
2013-11-19  1:22                               ` David Rientjes
     [not found]                               ` <20131118165110.GE32623-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-11-22 16:51                                 ` Johannes Weiner
     [not found]                                   ` <20131122165100.GN3556-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-11-27  0:53                                     ` David Rientjes
     [not found]                                       ` <alpine.DEB.2.02.1311261648570.21003-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-11-27 16:34                                         ` Johannes Weiner
     [not found]                                           ` <20131127163435.GA3556-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-11-27 21:51                                             ` David Rientjes
2013-11-27 23:19                                               ` Johannes Weiner
2013-11-28  0:22                                                 ` David Rientjes
2013-11-28  2:28                                                   ` Johannes Weiner
     [not found]                                                     ` <20131128022804.GJ3556-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-11-28  2:52                                                       ` David Rientjes
     [not found]                                                         ` <alpine.DEB.2.02.1311271839290.5120-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-11-28  3:16                                                           ` Johannes Weiner
2013-12-02 20:02                                           ` Michal Hocko
     [not found]                                             ` <20131202200221.GC5524-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-12-02 21:25                                               ` Johannes Weiner
2013-12-03 12:04                                                 ` Michal Hocko
     [not found]                                                   ` <20131203120454.GA12758-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-12-03 20:17                                                     ` Johannes Weiner
2013-12-03 21:00                                                       ` Michal Hocko
2013-12-03 21:23                                                         ` Johannes Weiner
2013-12-03 23:50                                                   ` David Rientjes
2013-12-04  3:34                                                     ` Johannes Weiner
     [not found]                                                     ` <alpine.DEB.2.02.1312031544530.5946-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-12-04 11:13                                                       ` Michal Hocko
2013-12-05  0:23                                                         ` David Rientjes
     [not found]                                                           ` <alpine.DEB.2.02.1312041606260.6329-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-12-09 12:48                                                             ` Michal Hocko
2013-12-09 21:46                                                               ` David Rientjes
2013-12-09 23:05                                                                 ` Johannes Weiner
2014-01-10  0:34                                                                   ` David Rientjes
     [not found]                                                                 ` <alpine.DEB.2.02.1312091328550.11026-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-12-09 22:51                                                                   ` Johannes Weiner
2013-12-10 10:38                                                                   ` Michal Hocko
     [not found]                                                                     ` <20131210103827.GB20242-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-12-11  1:03                                                                       ` David Rientjes
2013-12-11  9:55                                                                         ` Michal Hocko
2013-12-11 22:40                                                                           ` David Rientjes
2013-12-12 10:31                                                                             ` Michal Hocko
2013-12-12 10:50                                                                               ` Michal Hocko
2013-12-12 12:11                                                                               ` Michal Hocko [this message]
2013-12-12 12:37                                                                                 ` Michal Hocko
2013-12-13 23:55                                                                               ` David Rientjes
2013-12-17 16:23                                                                                 ` Michal Hocko
2013-12-17 20:50                                                                                   ` David Rientjes
     [not found]                                                                                     ` <alpine.DEB.2.02.1312171240541.21640-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-12-18 20:04                                                                                       ` Michal Hocko
2013-12-19  6:09                                                                                         ` David Rientjes
2013-12-19 14:41                                                                                           ` Michal Hocko
     [not found]                                                                                             ` <20131219144134.GH10855-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2014-01-08  0:25                                                                                               ` Andrew Morton
     [not found]                                                                                                 ` <20140107162503.f751e880410f61a109cdcc2b-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2014-01-08 10:33                                                                                                   ` Michal Hocko
2014-01-09 14:30                                                                                                     ` [PATCH] memcg: Do not hang on OOM when killed by userspace OOM " Michal Hocko
2014-01-09 21:40                                                                                                       ` David Rientjes
2014-01-10  8:23                                                                                                         ` Michal Hocko
2014-01-10 21:33                                                                                                           ` David Rientjes
2014-01-15 14:26                                                                                                             ` Michal Hocko
2014-01-15 21:19                                                                                                               ` David Rientjes
     [not found]                                                                                                                 ` <alpine.DEB.2.02.1401151304430.10727-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2014-01-16 10:12                                                                                                                   ` Michal Hocko
2014-01-21  6:13                                                                                                                     ` David Rientjes
     [not found]                                                                                                                       ` <alpine.DEB.2.02.1401202158411.21729-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2014-01-21 13:21                                                                                                                         ` Michal Hocko
2014-01-09 21:34                                                                                                 ` [patch 1/2] mm, memcg: avoid oom notification when current needs " David Rientjes
     [not found]                                                                                                   ` <alpine.DEB.2.02.1401091324120.31538-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2014-01-09 22:47                                                                                                     ` Andrew Morton
2014-01-10  0:01                                                                                                       ` David Rientjes
2014-01-10  0:12                                                                                                         ` Andrew Morton
2014-01-10  0:23                                                                                                           ` David Rientjes
2014-01-10  0:35                                                                                                             ` David Rientjes
     [not found]                                                                                                             ` <alpine.DEB.2.02.1401091613560.22649-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2014-01-10 22:14                                                                                                               ` Johannes Weiner
2014-01-12 22:10                                                                                                                 ` David Rientjes
2014-01-15 14:34                                                                                                                   ` Michal Hocko
2014-01-15 21:23                                                                                                                     ` David Rientjes
     [not found]                                                                                                                       ` <alpine.DEB.2.02.1401151319580.10727-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2014-01-16  9:32                                                                                                                         ` Michal Hocko
2014-01-21  5:58                                                                                                                           ` David Rientjes
     [not found]                                                                                                                             ` <alpine.DEB.2.02.1401202155410.21729-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2014-01-21  6:04                                                                                                                               ` Greg Kroah-Hartmann
     [not found]                                                                                                                                 ` <20140121060428.GA19037-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2014-01-21  6:08                                                                                                                                   ` David Rientjes
2014-01-10  8:30                                                                                                         ` Michal Hocko
2014-01-10 21:38                                                                                                           ` David Rientjes
2014-01-10 22:34                                                                                                             ` Johannes Weiner
2014-01-12 22:14                                                                                                               ` David Rientjes
     [not found]                     ` <alpine.DEB.2.02.1311141447160.21413-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-11-18 15:54                       ` [patch] mm, memcg: add memory.oom_control notification for system oom Johannes Weiner
2013-11-18 23:15                         ` One Thousand Gnomes

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=20131212121140.GD2630@dhcp22.suse.cz \
    --to=mhocko@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.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;
as well as URLs for NNTP newsgroup(s).