linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH resend] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself
@ 2020-02-16 14:52 Yafang Shao
  2020-02-17  9:24 ` Michal Hocko
  0 siblings, 1 reply; 13+ messages in thread
From: Yafang Shao @ 2020-02-16 14:52 UTC (permalink / raw)
  To: guro, hannes, mhocko, vdavydov.dev, akpm, chris
  Cc: linux-mm, Yafang Shao, stable

memory.{emin, elow} are set in mem_cgroup_protected(), and the values of
them won't be changed until next recalculation in this function. After
either or both of them are set, the next reclaimer to relcaim this memcg
may be a different reclaimer, e.g. this memcg is also the root memcg of
the new reclaimer, and then in mem_cgroup_protection() in get_scan_count()
the old values of them will be used to calculate scan count, that is not
proper. We should reset them to zero in this case.

Here's an example of this issue.

    root_mem_cgroup
         /
        A   memory.max=1024M memory.min=512M memory.current=800M

Once kswapd is waked up, it will try to scan all MEMCGs, including
this A, and it will assign memory.emin of A with 512M.
After that, A may reach its hard limit(memory.max), and then it will
do memcg reclaim. Because A is the root of this reclaimer, so it will
not calculate its memory.emin. So the memory.emin is the old value
512M, and then this old value will be used in
mem_cgroup_protection() in get_scan_count() to get the scan count.
That is not proper.

Fixes: 9783aa9917f8 ("mm, memcg: proportional memory.{low,min} reclaim")
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Roman Gushchin <guro@fb.com>
Cc: Chris Down <chris@chrisdown.name>
Cc: stable@vger.kernel.org
---
 mm/memcontrol.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 6f6dc8712e39..df7fedbfc211 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6250,8 +6250,17 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,
 
 	if (!root)
 		root = root_mem_cgroup;
-	if (memcg == root)
+	if (memcg == root) {
+		/*
+		 * Reset memory.(emin, elow) for reclaiming the memcg
+		 * itself.
+		 */
+		if (memcg != root_mem_cgroup) {
+			memcg->memory.emin = 0;
+			memcg->memory.elow = 0;
+		}
 		return MEMCG_PROT_NONE;
+	}
 
 	usage = page_counter_read(&memcg->memory);
 	if (!usage)
-- 
2.14.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-02-18 11:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-16 14:52 [PATCH resend] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself Yafang Shao
2020-02-17  9:24 ` Michal Hocko
2020-02-17 13:08   ` Yafang Shao
2020-02-17 13:24     ` Michal Hocko
2020-02-17 13:51       ` Yafang Shao
2020-02-17 14:04         ` Michal Hocko
2020-02-17 14:28           ` Yafang Shao
2020-02-17 14:35             ` Michal Hocko
2020-02-17 14:40               ` Yafang Shao
2020-02-17 15:14                 ` Michal Hocko
2020-02-18  2:09                   ` Yafang Shao
2020-02-18  8:59                     ` Michal Hocko
2020-02-18 11:03                       ` Yafang Shao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).