[rh7,1/5] ms/mm: memcontrol: simplify detecting when the memory+swap limit is hit

Submitted by Andrey Ryabinin on Jan. 30, 2018, 3:51 p.m.

Details

Message ID 20180130155157.21074-1-aryabinin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrey Ryabinin Jan. 30, 2018, 3:51 p.m.
From: Johannes Weiner <hannes@cmpxchg.org>

When attempting to charge pages, we first charge the memory counter and
then the memory+swap counter.  If one of the counters is at its limit, we
enter reclaim, but if it's the memory+swap counter, reclaim shouldn't swap
because that wouldn't change the situation.  However, if the counters have
the same limits, we never get to the memory+swap limit.  To know whether
reclaim should swap or not, there is a state flag that indicates whether
the limits are equal and whether hitting the memory limit implies hitting
the memory+swap limit.

Just try the memory+swap counter first.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Vladimir Davydov <vdavydov@parallels.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Dave Hansen <dave@sr71.net>
Cc: Greg Thelen <gthelen@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

https://jira.sw.ru/browse/PSBM-80732
(cherry picked from commit 3fbe724424fb104aaca9973389b4a9df428c3e2a)
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 32 +++++---------------------------
 1 file changed, 5 insertions(+), 27 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f7036e71edde..5396157488ec 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -340,9 +340,6 @@  struct mem_cgroup {
 	/* OOM-Killer disable */
 	int		oom_kill_disable;
 
-	/* set when res.limit == memsw.limit */
-	bool		memsw_is_minimum;
-
 #ifdef CONFIG_CLEANCACHE
 	/*
 	 * cleancache_disabled_toggle: toggled by writing to
@@ -2163,8 +2160,6 @@  static unsigned long mem_cgroup_reclaim(struct mem_cgroup *memcg,
 
 	if (flags & MEM_CGROUP_RECLAIM_NOSWAP)
 		noswap = true;
-	if (!(flags & MEM_CGROUP_RECLAIM_SHRINK) && memcg->memsw_is_minimum)
-		noswap = true;
 
 	for (loop = 0; loop < MEM_CGROUP_MAX_RECLAIM_LOOPS; loop++) {
 		if (loop)
@@ -3849,7 +3844,6 @@  static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
 {
 	unsigned long curusage;
 	unsigned long oldusage;
-	unsigned long memswlimit;
 	bool enlarge = false;
 	int retry_count;
 	int ret;
@@ -3870,23 +3864,14 @@  static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
 			break;
 		}
 		mutex_lock(&memcg_limit_mutex);
-		memswlimit = memcg->memsw.limit;
-		if (limit > memswlimit) {
+		if (limit > memcg->memsw.limit) {
 			mutex_unlock(&memcg_limit_mutex);
 			ret = -EINVAL;
 			break;
 		}
-
 		if (limit > memcg->memory.limit)
 			enlarge = true;
-
 		ret = page_counter_limit(&memcg->memory, limit);
-		if (!ret) {
-			if (memswlimit == limit)
-				memcg->memsw_is_minimum = true;
-			else
-				memcg->memsw_is_minimum = false;
-		}
 		mutex_unlock(&memcg_limit_mutex);
 
 		if (!ret)
@@ -3913,7 +3898,6 @@  static int mem_cgroup_resize_memsw_limit(struct mem_cgroup *memcg,
 {
 	unsigned long curusage;
 	unsigned long oldusage;
-	unsigned long memlimit, memswlimit;
 	bool enlarge = false;
 	int retry_count;
 	int ret;
@@ -3929,23 +3913,17 @@  static int mem_cgroup_resize_memsw_limit(struct mem_cgroup *memcg,
 			ret = -EINTR;
 			break;
 		}
+
 		mutex_lock(&memcg_limit_mutex);
-		memlimit = memcg->memory.limit;
-		if (limit < memlimit) {
+		if (limit < memcg->memory.limit) {
 			mutex_unlock(&memcg_limit_mutex);
 			ret = -EINVAL;
 			break;
 		}
-		memswlimit = memcg->memsw.limit;
-		if (limit > memswlimit)
+
+		if (limit > memcg->memsw.limit)
 			enlarge = true;
 		ret = page_counter_limit(&memcg->memsw, limit);
-		if (!ret) {
-			if (memlimit == limit)
-				memcg->memsw_is_minimum = true;
-			else
-				memcg->memsw_is_minimum = false;
-		}
 		mutex_unlock(&memcg_limit_mutex);
 
 		if (!ret)