Change swappiness for docker container Change swappiness for docker container docker docker

Change swappiness for docker container


Got it! Docker does not even touch this parameter. memory.swappines for cgroups really changing according /proc/vm/swappiness. All children inherits this value from parent. Docker does not even touch this parameter. Moreover, in some cases (and exactly in my own) there is no ability to write something in memory.swappines. If memory cgroup uses hierarchy, or contains children, all attempts to write something to cgroups memory.swappiness will fail.

Look there. 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;}


If you upgrade to a 3.18 kernel or later, the restriction preventing modification to the cgroup memory.swappiness parameter in child/hierarchy cgroups is removed. The Linux kernel patch which removed this restriction 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 memory.swappiness value allowing user control over this cgroup setting, as long as the Docker daemon host kernel has the patch noted above, or the host kernel is 3.18 or greater.