I'm trying to disable transparent_hugepage in the kernel. Which according to this article means adding the substring transparent_hugepage=never to the GRUB_CMDLINE_LINUX variable in /etc/default/grub.
My attempt at doing that looks like:
- name: disable transparent_hugepage
ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^(GRUB_CMDLINE_LINUX="[^"]+)"'
line: '\g<1> transparent_hugepage=never"'
backrefs: yes
That however adds the substring every time ansible runs, not only when it is missing.
i.e.
# grep CMD /etc/default/grub
GRUB_CMDLINE_LINUX="resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet transparent_hugepage=never transparent_hugepage=never"
Surely there must be a better way to handle that than trying to do something fancy with regex negative lookahead?
I tried the lookahead approach using:
regexp: '^(GRUB_CMDLINE_LINUX="[^"]+)(?! transparent_hugepage=never)"'
but it behaves the same.
To ensure that THP is disabled before other services starts, one should create a service file which disables THP during boot up. This is the recommend approach by certain Open Source Projects, one in example is MongoDB - Disable Transparent Huge Pages (THP).
Placing a service file
on a Remote Node via
than, a task will do the job
Double checking on CLI result into an output of
Further Readings
systemdin Ubuntu