[Devel] [PATCH rh7] ms/mm/memcontrol.c: fix the margin computation in mem_cgroup_margin()

Andrey Ryabinin aryabinin at virtuozzo.com
Tue Jun 6 16:49:12 MSK 2017


From: Li RongQing <roy.qing.li at gmail.com>

commit cbedbac3e66121ddbac363776c23119f8eaeefda upstream.

mem_cgroup_margin() might return (memory.limit - memory_count) when the
memsw.limit is in excess.  This doesn't happen usually because we do not
allow excess on hard limits and (memory.limit <= memsw.limit), but
__GFP_NOFAIL charges can force the charge and cause the excess when no
memory is really swappable (swap is full or no anonymous memory is
left).

[mhocko at suse.com: rewrote changelog]
  Link: http://lkml.kernel.org/r/20160525155122.GK20132@dhcp22.suse.cz
Link: http://lkml.kernel.org/r/1464068266-27736-1-git-send-email-roy.qing.li@gmail.com
Signed-off-by: Li RongQing <roy.qing.li at gmail.com>
Acked-by: Vladimir Davydov <vdavydov at virtuozzo.com>
Acked-by: Michal Hocko <mhocko at suse.com>
Cc: Johannes Weiner <hannes at cmpxchg.org>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>

https://jira.sw.ru/browse/PSBM-67076
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 66d51b7b07c5..b1bc0924f6d5 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1761,6 +1761,8 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
 		limit = ACCESS_ONCE(memcg->memsw.limit);
 		if (count <= limit)
 			margin = min(margin, limit - count);
+		else
+			margin = 0;
 	}
 
 	return margin;
-- 
2.13.0



More information about the Devel mailing list