From cfe98fb4beacadd5ce7a8fdcda49a7debbdecea0 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Wed, 8 Mar 2017 10:03:10 -0500 Subject: [PATCH 1/2] attempt to disable transparent hugepage at boot --- tasks/install.yml | 27 +++++++++++++ .../RedHat/disable-transparent-hugepages.j2 | 40 +++++++++++++++++++ .../default/disable-transparent-hugepages.j2 | 29 ++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 templates/RedHat/disable-transparent-hugepages.j2 create mode 100644 templates/default/disable-transparent-hugepages.j2 diff --git a/tasks/install.yml b/tasks/install.yml index f03e03f3..dfa8d40e 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -8,6 +8,33 @@ 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: redis_travis_ci is not defined + +- name: set Disable Transparent Hugepages to start at boot + service: + name: disable-transparent-hugepages + enabled: yes + 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: diff --git a/templates/RedHat/disable-transparent-hugepages.j2 b/templates/RedHat/disable-transparent-hugepages.j2 new file mode 100644 index 00000000..d7defce9 --- /dev/null +++ b/templates/RedHat/disable-transparent-hugepages.j2 @@ -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 diff --git a/templates/default/disable-transparent-hugepages.j2 b/templates/default/disable-transparent-hugepages.j2 new file mode 100644 index 00000000..d26f012e --- /dev/null +++ b/templates/default/disable-transparent-hugepages.j2 @@ -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 From 75840c439e95e742bd400e739c3f08b3eb872dff Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Sun, 12 Mar 2017 00:23:06 -0500 Subject: [PATCH 2/2] add systemd version of transparent-hugepages --- handlers/main.yml | 5 ++++ tasks/install.yml | 26 +++++++++++++++++-- .../disable-transparent-hugepages.service.j2 | 15 +++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 templates/default/disable-transparent-hugepages.service.j2 diff --git a/handlers/main.yml b/handlers/main.yml index 8c6985bc..b8c45363 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/tasks/install.yml b/tasks/install.yml index dfa8d40e..232bfb3c 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -27,13 +27,35 @@ - default/disable-transparent-hugepages.j2 paths: - ../templates - when: redis_travis_ci is not defined + 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 + 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 '' }} diff --git a/templates/default/disable-transparent-hugepages.service.j2 b/templates/default/disable-transparent-hugepages.service.j2 new file mode 100644 index 00000000..ac2e3b4f --- /dev/null +++ b/templates/default/disable-transparent-hugepages.service.j2 @@ -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 \ No newline at end of file