[Devel,rh7,5/7] ve/memcg: enable kmem accounting for all cgroups

Submitted by Andrey Ryabinin on March 31, 2017, 1:51 p.m.


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

Commit Message

Andrey Ryabinin March 31, 2017, 1:51 p.m.
From: Vladimir Davydov <vdavydov@virtuozzo.com>

Currently, kmem accounting is only enabled for a cgroup upon write to
memory.kmem.limit_in_bytes. This is fine in case of containers, because
we've already taught vzctl to do it, but we also want to enable it for
system.slice, otherwise dcache used by the host will be scanned too
aggressively in case all cgroups are protected with memory.low, and here
comes the problem: system.slice is populated by systemd, which never
sets memory.kmem.limit_in_bytes, and once a cgroup is populated one
cannot enable kmem accounting for it.

To overcome this, let's enable kmem accounting by default for all memory
cgroups. Since we already enable it for most cgroups, this shouldn't
cause any problems apart from perhaps small performance degradation of
processes on the host, which is of least importance. Note, the system
can be still returned to the former behavior by passing kmemaccount=0 on

Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
 mm/memcontrol.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index bc72a26..4e1dbbb 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4382,6 +4382,18 @@  static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
 	return ret;
+static bool do_kmem_account = true;
+static int __init enable_kmem_account(char *s)
+	if (!strcmp(s, "1"))
+		do_kmem_account = true;
+	else if (!strcmp(s, "0"))
+		do_kmem_account = false;
+	return 1;
+__setup("kmemaccount=", enable_kmem_account);
 static int memcg_propagate_kmem(struct mem_cgroup *memcg)
 	int ret = 0;
@@ -4395,7 +4407,7 @@  static int memcg_propagate_kmem(struct mem_cgroup *memcg)
 	 * If the parent cgroup is not kmem-active now, it cannot be activated
 	 * after this point, because it has at least one child already.
-	if (memcg_kmem_is_active(parent))
+	if (do_kmem_account || memcg_kmem_is_active(parent))
 		ret = __memcg_activate_kmem(memcg, PAGE_COUNTER_MAX);
 	return ret;