From 6d70ecaf90b7cc1f50634467b715144582e30f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Tue, 18 Dec 2018 10:50:38 +0100 Subject: [PATCH] Add a variable to disable transparent hugepages on systemd debian installations --- README.md | 3 +++ defaults/main.yml | 2 ++ files/disable-transparent-hugepages.init | 10 ++++++++++ files/disable-transparent-hugepages.sh | 10 ++++++++++ tasks/disable_transparent_hugepages.yml | 22 ++++++++++++++++++++++ tasks/install.debian.yml | 6 ++++++ 6 files changed, 53 insertions(+) create mode 100644 files/disable-transparent-hugepages.init create mode 100644 files/disable-transparent-hugepages.sh create mode 100644 tasks/disable_transparent_hugepages.yml diff --git a/README.md b/README.md index 49336b4..e678f40 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ mongodb_pymongo_pip_version: 3.6.1 # Choose PyMong version to inst mongodb_user_update_password: "on_create" # MongoDB user password update default policy mongodb_manage_service: true +# Disable transparent hugepages on systemd debian based installations +mongodb_disable_transparent_hugepages: false + mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}" mongodb_uid: mongodb_gid: diff --git a/defaults/main.yml b/defaults/main.yml index c0a94fc..e474a1f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,6 +14,8 @@ mongodb_pymongo_pip_version: 3.6.1 mongodb_user_update_password: "on_create" # MongoDB user password update default policy mongodb_manage_service: true +mongodb_disable_transparent_hugepages: false + mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}" mongodb_uid: mongodb_gid: diff --git a/files/disable-transparent-hugepages.init b/files/disable-transparent-hugepages.init new file mode 100644 index 0000000..c3a5d5e --- /dev/null +++ b/files/disable-transparent-hugepages.init @@ -0,0 +1,10 @@ +[Unit] +Description="Disable transparent hugepages" +Before=mongodb.service + +[Service] +Type=oneshot +ExecStart=/opt/disable-transparent-hugepages.sh + +[Install] +WantedBy=multi-user.target diff --git a/files/disable-transparent-hugepages.sh b/files/disable-transparent-hugepages.sh new file mode 100644 index 0000000..5bd10ac --- /dev/null +++ b/files/disable-transparent-hugepages.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ -d /sys/kernel/mm/transparent_hugepage ]; then + thp_path=/sys/kernel/mm/transparent_hugepage +else + return 0 +fi + +echo 'never' > ${thp_path}/enabled +echo 'never' > ${thp_path}/defrag diff --git a/tasks/disable_transparent_hugepages.yml b/tasks/disable_transparent_hugepages.yml new file mode 100644 index 0000000..e32de2a --- /dev/null +++ b/tasks/disable_transparent_hugepages.yml @@ -0,0 +1,22 @@ +- name: Install disable transparent hugepages helper + copy: + src: disable-transparent-hugepages.sh + dest: /opt/disable-transparent-hugepages.sh + owner: root + group: root + mode: 0700 + +- name: Create disable transparent hugepages init file + copy: + src: disable-transparent-hugepages.init + dest: /etc/systemd/system/disable-transparent-hugepages.init + owner: root + group: root + mode: 0644 + +- name: Enable init file + systemd: + name: disable-transparent-hugepages + daemon-reload: yes + enabled: yes + state: started diff --git a/tasks/install.debian.yml b/tasks/install.debian.yml index ded7089..a508d20 100644 --- a/tasks/install.debian.yml +++ b/tasks/install.debian.yml @@ -11,6 +11,12 @@ mongodb_is_systemd: "{{ sbin_init.stat.islnk is defined and sbin_init.stat.islnk }}" mongodb_major_version: "{{ mongodb_version[0:3] }}" +- name: Disable transparent huge pages on systemd systems + include_tasks: disable_transparent_hugepages.yml + when: + - mongodb_disable_transparent_hugepages + - mongodb_is_systemd + - name: Add APT key apt_key: keyserver: "{{ mongodb_apt_keyserver }}"