I'm trying to disable THP via ansible on vagrant up, because it interferes with Redis (causes latency and memore usage issues with redis if enabled)
The command to disable THP is "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
but it doesn't seem to be working with a simple shell role as shown below.
- name: Disable THP support (causes latency and mem usage issues with redis)
shell: echo never {{ ">" }} /sys/kernel/mm/transparent_hugepage/enabled
become: yes
become_method: sudo
become_user: root
This is the ansible output:
TASK [Disable-THP : Disable THP support (causes latency and mem usage issues with redis)] *** changed: [127.0.0.1] => {"changed": true, "cmd": "echo never > /sys/kernel/mm/transparent_hugepage/enabled", "delta": "0:00:00.003939", "end": "2018-07-09 12:22:33.183451", "rc": 0, "start": "2018-07-09 12:22:33.179512", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
After this i ssh into the virtual machine and start the redis-server, which still gives me the warning message.
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.
Am I doing something wrong with the ansible script or can anyone help me as to why this simple shell command is not working?
Br, Victor
UPDATE: I slightly modified my ansible role to check if the contents of the file actually changes. The role looks like this now:
- name: Disable THP support (causes latency and mem usage issues with redis)
shell: |
echo "never" >> /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/enabled
become: true
become_user: root
become_method: sudo
And according to the output, the enabled file actually changes the value to [never]. But when I ssh into the VM and cat the enabled file, it shows that the value is still [always]
TASK [Disable-THP : Disable THP support (causes latency and mem usage issues with redis)] *** changed: [127.0.0.1] => {"changed": true, "cmd": "echo \"never\" >> /sys/kernel/mm/transparent_hugepage/enabled\n cat /sys/kernel/mm/transparent_hugepage/enabled", "delta": "0:00:00.005309", "end": "2018-07-10 10:41:27.801697", "rc": 0, "start": "2018-07-10 10:41:27.796388", "stderr": "", "stderr_lines": [], "stdout": "always madvise [never]", "stdout_lines": ["always madvise [never]"]}
Why does the content of the files show that it has been changed, but then when i SSH into the VM it seems to tell me otherwise?
[vagrant@test ~]$ cd ..
[vagrant@test home]$ cd ..
[vagrant@test /]$ cd sys/kernel/mm/transparent_hugepage/
[vagrant@test transparent_hugepage]$ cat enabled
[always] madvise never