Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable transparent hugepage at boot #153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
name: sentinel_{{ redis_sentinel_port }}
state: restarted
when: redis_as_service

- name: "restart disable-transparent-hugepages"
service:
name: disable-transparent-hugepages
state: restarted
49 changes: 49 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,55 @@
ignoreerrors: yes
when: redis_travis_ci is not defined

- name: Disable Transparent Hugepages
shell: |
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled; fi;
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag; fi;
when: redis_travis_ci is not defined

- name: create script to Disable Transparent Hugepages
template:
src: "{{ item }}"
dest: /etc/init.d/disable-transparent-hugepages
mode: 0755
# Choose the distro-specific template. We must specify the templates
# path here because with_first_found tries to find files in files/
with_first_found:
- files:
- "{{ ansible_os_family }}/disable-transparent-hugepages.j2"
- default/disable-transparent-hugepages.j2
paths:
- ../templates
when: ansible_service_mgr|default() != 'systemd'

- name: create Disable Transparent Hugepages systemd service
template:
src: "{{ item }}"
dest: /etc/systemd/system/disable-transparent-hugepages.service
mode: 0644
with_first_found:
- files:
- "{{ ansible_os_family }}/disable-transparent-hugepages.service.j2"
- default/disable-transparent-hugepages.service.j2
paths:
- ../templates
register: dth_unit_file
when: ansible_service_mgr|default() == "systemd"

- name: set Disable Transparent Hugepages to start at boot
service:
name: disable-transparent-hugepages
enabled: yes
when:
- redis_travis_ci is not defined

- name: ensure Disable Transparent Hugepages is started
service:
name: disable-transparent-hugepages
state: started
when:
- redis_travis_ci is not defined

- name: compile redis
command: make -j{{ ansible_processor_cores + 1 }}{{ ' 32bit' if redis_make_32bit|bool else '' }}
args:
Expand Down
40 changes: 40 additions & 0 deletions templates/RedHat/disable-transparent-hugepages.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: disable-transparent-hugepages
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before: redis_{{ redis_port }} sentinel_{{ redis_sentinel_port }}
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description: Disable Linux transparent huge pages, to improve
# database performance.
### END INIT INFO

case $1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
exit 0
fi

echo 'never' > ${thp_path}/enabled
echo 'never' > ${thp_path}/defrag

re='^[0-1]+$'
if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
then
# RHEL 7
echo 0 > ${thp_path}/khugepaged/defrag
else
# RHEL 6
echo 'no' > ${thp_path}/khugepaged/defrag
fi

unset re
unset thp_path
;;
esac
29 changes: 29 additions & 0 deletions templates/default/disable-transparent-hugepages.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: disable-transparent-hugepages
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before: redis_{{ redis_port }} sentinel_{{ redis_sentinel_port }}
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description: Disable Linux transparent huge pages, to improve
# database performance.
### END INIT INFO

case $1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
exit 0
fi

echo 'never' > ${thp_path}/enabled
echo 'never' > ${thp_path}/defrag

unset thp_path
;;
esac
15 changes: 15 additions & 0 deletions templates/default/disable-transparent-hugepages.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Disable Transparent Huge Pages

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "/usr/bin/echo never | tee /sys/kernel/mm/transparent_hugepage/enabled"
ExecStart=/usr/bin/sh -c "/usr/bin/echo never | tee /sys/kernel/mm/transparent_hugepage/defrag"
{% if ansible_distribution_major_version == '6' %}
ExecStart=/usr/bin/sh -c "/usr/bin/echo no | tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag"
{% elif ansible_distribution_major_version == '7' %}
ExecStart=/usr/bin/sh -c "/usr/bin/echo 0 | tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag"
{% endif %}

[Install]
WantedBy=multi-user.target