diff --git a/README.md b/README.md index f137f61..56b9228 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ mongodb_package: mongodb-org mongodb_force_wait_for_port: false # When not forced, the role will wait for mongod port to become available only with systemd mongodb_pymongo_from_pip: false # Install latest PyMongo via PIP or package manager +mongodb_disable_thp: true mongodb_manage_service: true diff --git a/defaults/main.yml b/defaults/main.yml index d387db3..6a4c25d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,6 +3,7 @@ mongodb_package: mongodb-org mongodb_force_wait_for_port: false mongodb_pymongo_from_pip: false # Install latest PyMongo via PIP or package manager +mongodb_disable_thp: true mongodb_manage_service: true diff --git a/files/disable_thp.sh b/files/disable_thp.sh new file mode 100644 index 0000000..abf2f48 --- /dev/null +++ b/files/disable_thp.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +if test -f /sys/kernel/mm/transparent_hugepage/khugepaged/defrag; then + echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag +fi +if test -f /sys/kernel/mm/transparent_hugepage/defrag; then + echo never > /sys/kernel/mm/transparent_hugepage/defrag +fi +if test -f /sys/kernel/mm/transparent_hugepage/enabled; then + echo never > /sys/kernel/mm/transparent_hugepage/enabled +fi \ No newline at end of file diff --git a/tasks/configure.yml b/tasks/configure.yml index 5f6a578..181810e 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -60,6 +60,18 @@ template: src=mongod.conf.j2 dest=/etc/mongod.conf backup=yes owner=root group=root mode=0644 register: config_result +- name: Install disable_thp script + copy: src=disable_thp.sh dest=/usr/local/bin/disable_thp.sh mode='u=rwx,g=rx,o=rx' + when: ansible_os_family == 'Debian' and mongodb_disable_thp + +- name: Disable Linux transparent hugepages now + command: /usr/local/bin/disable_thp.sh + when: ansible_os_family == 'Debian' and mongodb_disable_thp + +- name: Disable Linux transparent hugepages on boot + lineinfile: dest=/etc/rc.local regexp='/usr/local/bin/disable_thp.sh' line='if test -f '/usr/local/bin/disable_thp.sh'; /usr/local/bin/disable_thp.sh; fi' + when: ansible_os_family == 'Debian' and mongodb_disable_thp + - name: get pid of mongod command: pidof mongod register: mongod_new_pid