redis icon indicating copy to clipboard operation
redis copied to clipboard

WARNING you have Transparent Huge Pages (THP) support enabled

Open sijnc opened this issue 10 years ago • 21 comments

When Redis starts I'm seeing the following two warnings, Is this something to be concerned about or something that should be corrected in the docker-library redis:2.8 image?

Server started, Redis version 2.8.23

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

sijnc avatar Apr 26 '16 20:04 sijnc

You probably want to see both #19 and #35 -- the short version is that there's nothing we can do to enable these in the image itself. Setting net.core.somaxconn using docker run --sysctl will be possible with Docker 1.12+, but fixing the value of THP is something you're going to have to change on your host if it's necessary.

tianon avatar Apr 26 '16 20:04 tianon

Any help how to do this on MacOS host?

ababich avatar Dec 23 '16 06:12 ababich

On an OSX machine, you are still running the containers in a Linux VM, so you would have to configure it on that VM whether the VM is from docker-toolbox using docker-machine or Docker for Mac.

yosifkit avatar Dec 28 '16 23:12 yosifkit

On Linux I solved this running those on HOST:

echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag

Suggest closing ;)

mostolog avatar Mar 29 '17 13:03 mostolog

Here is a oneshot systemd unit to do it as well:

[Unit]
Description=Disable Transparent Huge Pages
Documentation=https://redis.io/topics/latency

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "/usr/bin/echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled"
ExecStart=/usr/bin/sh -c "/usr/bin/echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"

[Install]
WantedBy=multi-user.target

c4milo avatar Jul 24 '17 23:07 c4milo

There's nothing that can be done here -- This is a host level configuration that can't be modified inside the container (unless it runs in privileged mode).

ushachar avatar Jul 26 '17 14:07 ushachar

Leaving some more detail for this in case other Docker for Mac users still have this problem.

This solved the above problem with the following system info: Docker version 17.12.0-ce, build c97c6d6 Mac OS X El Captain (10.11.6) Redis version=4.0.8

This is a very naive solution this problem (mostly just cutting and pasting from SO and above, so use at your own risk).

Step 1: Start a screen session the linux VM that docker for mac is running on

$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

(h/t https://stackoverflow.com/questions/39739560/how-to-access-the-vm-created-by-dockers-hyperkit)

Step 2: Run the commands above

# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag

Step 3: Exit screen session, and run whatever docker images / commands.

danrubenstein avatar Feb 25 '18 21:02 danrubenstein

What's the fix on Docker for Windows?

ghost avatar Jul 19 '18 05:07 ghost

@danrubenstein great hack, but does it make any practical sense?

ababich avatar Jul 19 '18 06:07 ababich

What's the fix on Docker for Windows?

SSH into the Docker VM (MobyLinuxVM)

docker run --privileged -it -v /var/run/docker.sock:/var/run/docker.sock jongallant/ubuntu-docker-client docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh chroot /host

then, run the commands @mostolog wrote:

echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag

28554010 avatar Oct 25 '18 12:10 28554010

@danrubenstein Thanks for sharing solution 👍

kigawas avatar Oct 26 '18 04:10 kigawas

@danrubenstein Your steps were helpful. However, I found that on my system, the path to Docker's Linux VM was ~/Library/Containers/com.docker.docker/Data/vms/0.

I am using macOS 10.14.2 Mojave; Docker v2.0.0.0-mac81 (29211); and Redis v5.0.3.

stephengtuggy avatar Jan 04 '19 20:01 stephengtuggy

I created a simple shell script to fix this using nsenter that I just execute whenever I start Docker For Mac:

#!/bin/sh
docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'

I'd use alpine instead of debian, but apparently nsenter is broken for sh -c right now.

If there's a more direct way to do this w/o pulling debian I'd be glad to hear it.

tunecrew avatar Feb 22 '19 05:02 tunecrew

Leaving some more detail for this in case other Docker for Mac users still have this problem.

This solved the above problem with the following system info: Docker version 17.12.0-ce, build c97c6d6 Mac OS X El Captain (10.11.6) Redis version=4.0.8

This is a very naive solution this problem (mostly just cutting and pasting from SO and above, so use at your own risk).

Step 1: Start a screen session the linux VM that docker for mac is running on

$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

(h/t https://stackoverflow.com/questions/39739560/how-to-access-the-vm-created-by-dockers-hyperkit)

Step 2: Run the commands above

# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag

Step 3: Exit screen session, and run whatever docker images / commands.

thank you.

WerBinIch avatar Oct 18 '19 09:10 WerBinIch

In case the screen paths from @danrubenstein and @stephengtuggy don't work, I found on my machine the correct path was ~/Library/Containers/com.docker.docker/Data/vms/0/tty

macOS Mojave 10.14.6, Docker 2.1.0.5, and Redis 5.0.5

alecglen avatar Nov 20 '19 22:11 alecglen

What's the fix on Docker for Windows?

Do we have any fix for windows yet?

imujjwalanand avatar Jan 09 '20 00:01 imujjwalanand

What's the fix on Docker for Windows?

Do we have any fix for windows yet?

Did you try https://github.com/docker-library/redis/issues/55#issuecomment-433030237?

Or, since Docker for WIndows is basically the same setup as Docker for Mac, this https://github.com/docker-library/redis/issues/55#issuecomment-466277345 should work. Maybe minus running it as a shell script, but the two commands should be enough to modify the VM that Docker uses to run Linux containers. (basically you need to get direct access to the underlying VM so you can turn off THP).

For those wondering about using an Alpine container instead of Debian, you should be able to the same thing after installing util-linux to get nsenter.

yosifkit avatar Jan 09 '20 21:01 yosifkit

@tunecrew, notice two dashes to signify the end of command options for run followed by sh -c.

#!/bin/bash
set -ex

docker run -it --privileged --pid=host alpine:3.11 nsenter -t 1 -m -u -n -i -- sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
docker run -it --privileged --pid=host alpine:3.11 nsenter -t 1 -m -u -n -i -- sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'

marioroy avatar Jan 19 '20 05:01 marioroy

On Windows I found an easier way to get access to the host VM here: Getting a Shell in the Docker for Windows VM

Here is the TL;DR version: docker run -it --rm --privileged --pid=host justincormack/nsenter1

korggy avatar Apr 08 '20 21:04 korggy

How would one set this on kubernetes?

brandoncollins7 avatar Jun 18 '20 15:06 brandoncollins7