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

Andrey Ryabinin aryabinin at virtuozzo.com
Fri Mar 31 06:51:09 PDT 2017

From: Vladimir Davydov <vdavydov at 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 at virtuozzo.com>

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

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;

More information about the Devel mailing list