]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.4.65/mm-memcg-give-exiting-processes-access-to-memory-reserves.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.4.65 / mm-memcg-give-exiting-processes-access-to-memory-reserves.patch
1 From h.huangqiang@huawei.com Wed Oct 2 19:36:01 2013
2 From: David Rientjes <rientjes@google.com>
3 Date: Fri, 27 Sep 2013 17:08:49 +0800
4 Subject: mm, memcg: give exiting processes access to memory reserves
5 To: <gregkh@linuxfoundation.org>
6 Cc: Andrew Morton <akpm@linux-foundation.org>, Michal Hocko <mhocko@suse.cz>, <stable@vger.kernel.org>, Li Zefan <lizefan@huawei.com>
7 Message-ID: <52454B21.3010207@huawei.com>
8
9
10 From: David Rientjes <rientjes@google.com>
11
12 commit 465adcf1ea7b2e49b2e0899366624f5532b64012
13
14 A memcg may livelock when oom if the process that grabs the hierarchy's
15 oom lock is never the first process with PF_EXITING set in the memcg's
16 task iteration.
17
18 The oom killer, both global and memcg, will defer if it finds an
19 eligible process that is in the process of exiting and it is not being
20 ptraced. The idea is to allow it to exit without using memory reserves
21 before needlessly killing another process.
22
23 This normally works fine except in the memcg case with a large number of
24 threads attached to the oom memcg. In this case, the memcg oom killer
25 only gets called for the process that grabs the hierarchy's oom lock;
26 all others end up blocked on the memcg's oom waitqueue. Thus, if the
27 process that grabs the hierarchy's oom lock is never the first
28 PF_EXITING process in the memcg's task iteration, the oom killer is
29 constantly deferred without anything making progress.
30
31 The fix is to give PF_EXITING processes access to memory reserves so
32 that we've marked them as oom killed without any iteration. This allows
33 __mem_cgroup_try_charge() to succeed so that the process may exit. This
34 makes the memcg oom killer exemption for TIF_MEMDIE tasks, now
35 immediately granted for processes with pending SIGKILLs and those in the
36 exit path, to be equivalent to what is done for the global oom killer.
37
38 Signed-off-by: David Rientjes <rientjes@google.com>
39 Acked-by: Michal Hocko <mhocko@suse.cz>
40 Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
41 Acked-by: Johannes Weiner <hannes@cmpxchg.org>
42 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
43 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
44 [Qiang: backported to 3.4:
45 - move the changes from memcontrol.c to oom_kill.c]
46 Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
47 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
48 ---
49 mm/oom_kill.c | 8 ++++----
50 1 file changed, 4 insertions(+), 4 deletions(-)
51
52 --- a/mm/oom_kill.c
53 +++ b/mm/oom_kill.c
54 @@ -562,11 +562,11 @@ void mem_cgroup_out_of_memory(struct mem
55 struct task_struct *p;
56
57 /*
58 - * If current has a pending SIGKILL, then automatically select it. The
59 - * goal is to allow it to allocate so that it may quickly exit and free
60 - * its memory.
61 + * If current has a pending SIGKILL or is exiting, then automatically
62 + * select it. The goal is to allow it to allocate so that it may
63 + * quickly exit and free its memory.
64 */
65 - if (fatal_signal_pending(current)) {
66 + if (fatal_signal_pending(current) || current->flags & PF_EXITING) {
67 set_thread_flag(TIF_MEMDIE);
68 return;
69 }