How do I disable Transparent Huge Pages (required for redis/tokudb)?

Transparent Huge Pages is required to be disabled for the TokuDB engine and for Redis. In the past, I could just docker-machine ssh into the host and disable it. I no longer have access to the host OS, so how do I disable it?

You can actually do this with a privileged container in Docker native. You can do it like this:

docker run -ti --privileged ubuntu /bin/bash
echo never | tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | tee /sys/kernel/mm/transparent_hugepage/defrag

I ended up creating an image for this and made redis/mariadb include it under depends_on in my docker-compose.yml file

FROM ubuntu:latest
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

where docker-entrypoint.sh has:

#!/bin/bash
set -e

echo never | tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | tee /sys/kernel/mm/transparent_hugepage/defrag
1 Like

The privileged container is one option. While, remember using the privileged container is not recommended, and docker swarm does not support it.

You may consider to simply disable THP at the OS level. For example, run a script right after the node is created.

For Redis, you would also consider to increase somaxconn to 512., net.core.somaxconn=512 and net.ipv4.tcp_max_syn_backlog=512. If the container could use the host network. Setting them at the OS level would be enough. While, docker swarm service could not use the host network. You could refer to docker somaxconn workaround for it.

And overcommit_memory to 1, vm.overcommit_memory=1, see Redis’s detail explanation.