[rh7,2/2] mm/memcontrol: try to free all memcg during offline.

Submitted by Andrey Ryabinin on April 23, 2018, 1 p.m.

Details

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

Commit Message

Andrey Ryabinin April 23, 2018, 1 p.m.
Currently we don't reclaim memory on memcg offlining.
kmem in memcg pins cgroup indefinitely which don't allow
us to reuse cgroup's id. Since cgroups id count is limited
to ~65K we may exhaust all possible ids.

Try to free all memcg memory during offline. This should
allow us to destroy cgroup almost immedieatly and reuse id.

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

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d68650ad7a53..590851f6c1d3 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6146,6 +6146,19 @@  static void mem_cgroup_invalidate_reclaim_iterators(struct mem_cgroup *memcg)
 		mem_cgroup_iter_invalidate(root_mem_cgroup);
 }
 
+static void mem_cgroup_free_all(struct mem_cgroup *memcg)
+{
+	int nr_retries = 5;
+
+	lru_add_drain_all();
+
+	while (nr_retries && page_counter_read(&memcg->memory))
+		if (!try_to_free_mem_cgroup_pages(memcg, -1UL, GFP_KERNEL, 0))
+			nr_retries--;
+
+	lru_add_drain();
+}
+
 static void mem_cgroup_css_offline(struct cgroup *cont)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
@@ -6175,6 +6188,7 @@  static void mem_cgroup_css_offline(struct cgroup *cont)
 		rcu_read_lock();
 	}
 	rcu_read_unlock();
+	mem_cgroup_free_all(memcg);
 	mem_cgroup_reparent_charges(memcg);
 
 	/*