diff mbox

[v3,2/2] mm: ignore memory.min of abandoned memory cgroups

Message ID 20180503114358.7952-2-guro@fb.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roman Gushchin May 3, 2018, 11:43 a.m. UTC
If a cgroup has no associated tasks, invoking the OOM killer
won't help release any memory, so respecting the memory.min
can lead to an infinite OOM loop or system stall.

Let's ignore memory.min of unpopulated cgroups.

Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
---
 include/linux/memcontrol.h | 10 ++++++++++
 mm/vmscan.c                |  6 +++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

Comments

Johannes Weiner May 3, 2018, 5:38 p.m. UTC | #1
On Thu, May 03, 2018 at 12:43:58PM +0100, Roman Gushchin wrote:
> If a cgroup has no associated tasks, invoking the OOM killer
> won't help release any memory, so respecting the memory.min
> can lead to an infinite OOM loop or system stall.
> 
> Let's ignore memory.min of unpopulated cgroups.
> 
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Tejun Heo <tj@kernel.org>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

I wouldn't mind merging this into the previous patch. It's fairly
small, and there is no reason to introduce an infinite OOM loop
scenario into the tree, even if it's just for one commit.
diff mbox

Patch

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 3b65d092614f..7d8472022aae 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -374,6 +374,11 @@  static inline void mem_cgroup_put(struct mem_cgroup *memcg)
 	css_put(&memcg->css);
 }
 
+static inline bool mem_cgroup_is_populated(struct mem_cgroup *memcg)
+{
+	return cgroup_is_populated(memcg->css.cgroup);
+}
+
 #define mem_cgroup_from_counter(counter, member)	\
 	container_of(counter, struct mem_cgroup, member)
 
@@ -835,6 +840,11 @@  static inline void mem_cgroup_put(struct mem_cgroup *memcg)
 {
 }
 
+static inline bool mem_cgroup_is_populated(struct mem_cgroup *memcg)
+{
+	return false;
+}
+
 static inline struct mem_cgroup *
 mem_cgroup_iter(struct mem_cgroup *root,
 		struct mem_cgroup *prev,
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 50055d72f294..5e2047e04770 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2549,8 +2549,12 @@  static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 				/*
 				 * Hard protection.
 				 * If there is no reclaimable memory, OOM.
+				 * Abandoned cgroups are losing protection,
+				 * because OOM killer won't release any memory.
 				 */
-				continue;
+				if (mem_cgroup_is_populated(memcg))
+					continue;
+				break;
 			case MEMCG_PROT_LOW:
 				/*
 				 * Soft protection.