Change swappiness for docker container

I use docker to containerize a bunch of services. Container services change a lot several times. I changed vm.swappiness to 1 via sysctl on my host system. But the docker memory group still has the old (default) value of 60. Therefore, all groups of individual containers have the same value as the parent.

 sysctl vm.swappiness > vm.swappiness = 1 cat /sys/fs/cgroup/memory/docker/memory.swappiness > 60 cat /sys/fs/cgroup/memory/docker/${CONTAINER_ID}/memory.swappiness > 60 

All attempts to change swappiness manually (by repeating the desired value in the memory.swappiness file) fail with permission denied .

Subject: How can I limit the swappiness of containers?

I am using ubuntu 12.04 with kernel 3.13 , my version of docker is 1.1.2 with its own runtime driver (not lxc) version 0.2 . The kernel is loaded using cgroup_enable=memory swapaccount=1 .

+6
source share
2 answers

Got! Docker does not even touch this parameter. memory.swappines for groups that really change according to /proc/vm/swappiness . All children inherit this value from the parent. Docker does not even touch this parameter. Moreover, in some cases (and precisely in my own) there is no way to write something in memory.swappines . If a memory group uses a hierarchy or contains children , all attempts to write something to memory.swappiness groups will fail.

Take a look. This is from mm/memcontrol.c .

 static int mem_cgroup_swappiness_write(struct cgroup_subsys_state *css, struct cftype *cft, u64 val) { struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css)); if (val > 100 || !parent) return -EINVAL; mutex_lock(&memcg_create_mutex); /* If under hierarchy, only empty-root can set this value */ if ((parent->use_hierarchy) || memcg_has_children(memcg)) { mutex_unlock(&memcg_create_mutex); return -EINVAL; } memcg->swappiness = val; mutex_unlock(&memcg_create_mutex); return 0; } 
+2
source

If you upgrade to kernel 3.18 or later, the exception prohibiting the modification of the cgroup memory.swappiness parameter in child / hierarchical groups is removed. The Linux kernel patch that removed this limitation can be seen here: https://github.com/torvalds/linux/commit/3dae7fec5e884a4e72e5416db0894de66f586201

Docker 1.8 will most likely include the following PR ( https://github.com/docker/docker/pull/14004 ), which allows the container to set its own value memory.swappiness , allowing the user control over this cgroup parameter if the Docker host kernel has the patch noted above, or the host kernel is 3.18 or higher.

+3
source

Source: https://habr.com/ru/post/975069/


All Articles