[Devel] [PATCH rh7] mm: memcontrol: reclaim when shrinking memory.high below usage

Vladimir Davydov vdavydov at virtuozzo.com
Tue Jun 21 10:08:50 PDT 2016


From: Johannes Weiner <hannes at cmpxchg.org>

When setting memory.high below usage, nothing happens until the next
charge comes along, and then it will only reclaim its own charge and not
the now potentially huge excess of the new memory.high.  This can cause
groups to stay in excess of their memory.high indefinitely.

To fix that, when shrinking memory.high, kick off a reclaim cycle that
goes after the delta.

https://jira.sw.ru/browse/PSBM-48546

Signed-off-by: Johannes Weiner <hannes at cmpxchg.org>
Acked-by: Michal Hocko <mhocko at suse.com>
Cc: Vladimir Davydov <vdavydov at virtuozzo.com>
Cc: <stable at vger.kernel.org>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
(cherry picked from commit 588083bb37a3cea8533c392370a554417c8f29cb)
Signed-off-by: Vladimir Davydov <vdavydov at virtuozzo.com>

Conflicts:
	mm/memcontrol.c
---
 mm/memcontrol.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index de7c36295515..1f525f27e481 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5314,7 +5314,7 @@ static int mem_cgroup_high_write(struct cgroup *cont, struct cftype *cft,
 				 const char *buffer)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
-	unsigned long long val;
+	unsigned long long val, usage;
 	int ret;
 
 	ret = res_counter_memparse_write_strategy(buffer, &val);
@@ -5322,6 +5322,12 @@ static int mem_cgroup_high_write(struct cgroup *cont, struct cftype *cft,
 		return ret;
 
 	memcg->high = val;
+
+	usage = res_counter_read_u64(&memcg->res, RES_USAGE);
+	if (usage > val)
+		try_to_free_mem_cgroup_pages(memcg,
+					     (usage - val) >> PAGE_SHIFT,
+					     GFP_KERNEL, false);
 	return 0;
 }
 
-- 
2.1.4



More information about the Devel mailing list