]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.6.8/memcg-oom-fix-totalpages-calculation-for-memory.swappiness-0.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 3.6.8 / memcg-oom-fix-totalpages-calculation-for-memory.swappiness-0.patch
1 From 9a5a8f19b43430752067ecaee62fc59e11e88fa6 Mon Sep 17 00:00:00 2001
2 From: Michal Hocko <mhocko@suse.cz>
3 Date: Fri, 16 Nov 2012 14:14:49 -0800
4 Subject: memcg: oom: fix totalpages calculation for memory.swappiness==0
5
6 From: Michal Hocko <mhocko@suse.cz>
7
8 commit 9a5a8f19b43430752067ecaee62fc59e11e88fa6 upstream.
9
10 oom_badness() takes a totalpages argument which says how many pages are
11 available and it uses it as a base for the score calculation. The value
12 is calculated by mem_cgroup_get_limit which considers both limit and
13 total_swap_pages (resp. memsw portion of it).
14
15 This is usually correct but since fe35004fbf9e ("mm: avoid swapping out
16 with swappiness==0") we do not swap when swappiness is 0 which means
17 that we cannot really use up all the totalpages pages. This in turn
18 confuses oom score calculation if the memcg limit is much smaller than
19 the available swap because the used memory (capped by the limit) is
20 negligible comparing to totalpages so the resulting score is too small
21 if adj!=0 (typically task with CAP_SYS_ADMIN or non zero oom_score_adj).
22 A wrong process might be selected as result.
23
24 The problem can be worked around by checking mem_cgroup_swappiness==0
25 and not considering swap at all in such a case.
26
27 Signed-off-by: Michal Hocko <mhocko@suse.cz>
28 Acked-by: David Rientjes <rientjes@google.com>
29 Acked-by: Johannes Weiner <hannes@cmpxchg.org>
30 Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
31 Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
32 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
33 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
34 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36 ---
37 Documentation/cgroups/memory.txt | 4 ++++
38 mm/memcontrol.c | 21 +++++++++++++++------
39 2 files changed, 19 insertions(+), 6 deletions(-)
40
41 --- a/Documentation/cgroups/memory.txt
42 +++ b/Documentation/cgroups/memory.txt
43 @@ -466,6 +466,10 @@ Note:
44 5.3 swappiness
45
46 Similar to /proc/sys/vm/swappiness, but affecting a hierarchy of groups only.
47 +Please note that unlike the global swappiness, memcg knob set to 0
48 +really prevents from any swapping even if there is a swap storage
49 +available. This might lead to memcg OOM killer if there are no file
50 +pages to reclaim.
51
52 Following cgroups' swappiness can't be changed.
53 - root cgroup (uses /proc/sys/vm/swappiness).
54 --- a/mm/memcontrol.c
55 +++ b/mm/memcontrol.c
56 @@ -1458,17 +1458,26 @@ static int mem_cgroup_count_children(str
57 static u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
58 {
59 u64 limit;
60 - u64 memsw;
61
62 limit = res_counter_read_u64(&memcg->res, RES_LIMIT);
63 - limit += total_swap_pages << PAGE_SHIFT;
64
65 - memsw = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
66 /*
67 - * If memsw is finite and limits the amount of swap space available
68 - * to this memcg, return that limit.
69 + * Do not consider swap space if we cannot swap due to swappiness
70 */
71 - return min(limit, memsw);
72 + if (mem_cgroup_swappiness(memcg)) {
73 + u64 memsw;
74 +
75 + limit += total_swap_pages << PAGE_SHIFT;
76 + memsw = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
77 +
78 + /*
79 + * If memsw is finite and limits the amount of swap space
80 + * available to this memcg, return that limit.
81 + */
82 + limit = min(limit, memsw);
83 + }
84 +
85 + return limit;
86 }
87
88 void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,