Skip to content

695: New method for managing THP #697

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

Open
wants to merge 3 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
2 changes: 2 additions & 0 deletions roles/mongodb_linux/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ memlock_limit: 1024
mongodb_ntp_package:
mongodb_ntp_service:
mongodb_gnu_c_lib:

mongodb_enable_thp: false
10 changes: 10 additions & 0 deletions roles/mongodb_linux/files/thp-enable.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Enable Transparent Huge Pages
ConditionPathIsDirectory=/sys/kernel/mm/transparent_hugepage

[Service]
Type=oneshot
ExecStart=/usr/bin/env sh -c "echo 'always' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'always' > /sys/kernel/mm/transparent_hugepage/defrag"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this was intentional, but this unit is quite different from the example provided in the MongoDB docs.


[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion roles/mongodb_linux/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_swappiness_value(host):


def test_thp_service_file(host):
f = host.file("/etc/systemd/system/disable-transparent-huge-pages.service")
f = host.file("/etc/systemd/system/manage-transparent-huge-pages.service")

assert f.exists
assert f.user == "root"
Expand Down
28 changes: 6 additions & 22 deletions roles/mongodb_linux/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
- "setup"

# https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
- name: Ensure thp-disable service exists
- name: Ensure manage-transparent-huge-pages service exists
copy:
src: thp-disable.service
dest: /etc/systemd/system/disable-transparent-huge-pages.service
src: "{{ mongodb_enable_thp | ternary('thp-enable.service', 'thp-disable.service') }}"
dest: /etc/systemd/system/manage-transparent-huge-pages.service
owner: root
group: root
register: thp
Expand All @@ -165,28 +165,12 @@
path: /sys/kernel/mm/transparent_hugepage
register: sys_thp

- name: Check if disable-transparent-huge-pages service is already run
shell: cat /sys/kernel/mm/transparent_hugepage/enabled | grep -o '{{ bs }}[never{{ bs }}]'
when: sys_thp.stat.exists
register: _huge_page_status
ignore_errors: yes
changed_when: _huge_page_status.stdout == ""
tags:
- "linux"
- "service"
- "setup"
vars:
bs: \

- debug:
var: _huge_page_status.stdout

- name: Enable disable-transparent-huge-pages service
- name: Enable manage-transparent-huge-pages service
service:
name: disable-transparent-huge-pages
name: manage-transparent-huge-pages
state: started
enabled: yes
when: (sys_thp.stat.exists) and (_huge_page_status.stdout == "")
when: thp.changed
tags:
- "linux"
- "service"
Expand Down
Loading