Explicit Huge Pages V/s Transparent Huge Pages
There can be two types of HugePages in the system: Explicit Huge Pages which are allocated explicitly by vm.nr_hugepages sysctl parameter and Transparent Huge Pages which are allocated automatically by the kernel.
Verify if THP is enabled
“tuned.service” on CentOS / RHEL 7 set the transparent_hugepage to always by default. Even if its disabled in grub kernel command line, the tuned service will set it to ‘always‘ during boot. Below command output confirm that the THP are enabled on the system.
# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never
Steps to disable THP
1. Add the “transparent_hugepage=never” kernel parameter option to the grub2 configuration file. Append or change the “transparent_hugepage=never” kernel parameter on the GRUB_CMDLINE_LINUX option in /etc/default/grub file.
# vi /etc/default/grub GRUB_TIMEOUT=5 GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet transparent_hugepage=never" GRUB_DISABLE_RECOVERY="true"
2. Rebuild the /boot/grub2/grub.cfg file by running the grub2-mkconfig -o command. Before rebuilding the GRUB2 configuration file, ensure to take a backup of the existing /boot/grub2/grub.cfg.
On BIOS-based machines
# grub2-mkconfig -o /boot/grub2/grub.cfg
On UEFI-based machines
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
3. Reboot the system and verify option are in effect.
# shutdown -r now
4. Verify the parameter is set correctly
# cat /proc/cmdline BOOT_IMAGE=/vmlinuz-3.10.0-514.10.2.el7.x86_64 root=/dev/mapper/vg_os-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet transparent_hugepage=never LANG=en_US.UTF-8
Troubleshooting
If Transparent Huge Pages (THP) is still not disabled, continue and use one of the options below.
1. Disable tuned services
Disable the tuned services if it is re-enabling the THP using either of the below commands.
# systemctl stop tuned # systemctl disable tuned
OR
# tuned-adm off
2. Create a customized tuned profile with disabled THP
1. Another and recommended way is to create a customized tuned profile with THP disabled. Find out which profile is active, create a copy. In the following example we currently use the throughput-performance profile:
# tuned-adm active Current active profile: throughput-performance
2. To create customized profile, create a new directory in /etc/tuned directory with desired profile name.
# mkdir /etc/tuned/nothp_profile
3. Then create a new tuned.conf file for nothp_profile, and insert the new tuning info:
# cat /etc/tuned/nothp_profile/tuned.conf [main] include= throughput-performance [vm] transparent_hugepages=never
4. Make the script executable.
# chmod +x /etc/tuned/nothp_profile/tuned.conf
5. Enable nothp_profile using the tuned-adm command.
# tuned-adm profile nothp_profile
6. This change will immediately take effect and persist reboots. To verify if THP are disabled or not, run below command:
# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never]