Transparent Huge Pages (THP) are enabled by default in RHEL 6 for all applications. The kernel will always attempt to satisfy a memory allocation using hugepages. If no hugepages are available (due to non availability of physically continuous memory for example) the kernel will fall back to the regular 4KB pages.
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. The file /sys/kernel/mm/redhat_transparent_hugepage/enabled gives the current status of THP (enabled/disabled). The values for /sys/kernel/mm/redhat_transparent_hugepage/enabled can be one of the following:
always - always use THP never - disable THP
Below command output confirm that the THP are enabled or disabled on the system.
Output when THP is enabled
# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never
Output when THP is disable
# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never]
1. To disable THP at boot time
1. Append the parameter transparent_hugepage=never to the kernel command line in /etc/grub.conf:
# vim /etc/grub.conf default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Red Hat Enterprise Linux 6 (2.6.32-504.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vg_os-lv_os rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_os/lv_os KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet transparent_hugepage=never initrd /initramfs-2.6.32-504.el6.x86_64.img
2. Add a small script given below to the file /etc/rc.d/rc.local.
# vi /etc/rc.d/rc.local .... if test −f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test −f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi
3. Take a reboot of the system for the changes to take effect.
# shutdown -r now
2. To disable THP at runtime
Run the following commands to disable THP without rebooting the system.
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled # echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag
Troubleshooting
If Transparent Huge Pages (THP) is still not disabled, continue and use one of the options below.
1. Disable tuned/ktune services
1. Disable the tuned services if it is re-enabling the THP using either of the below commands.
# service tuned stop # chkconfig tuned off # service ktune stop # chkconfig ktune off
OR
# tuned-adm off
2. Verify ktune and tuned services are disabled to start at boot:
# chkconfig --list |egrep -i "ktune|tuned" ktune 0:off 1:off 2:off 3:off 4:off 5:off 6:off tuned 0:off 1:off 2:off 3:off 4:off 5:off 6:off
2. Create a customized tuned profile with disabled THP
1. We will create a customized version of the currently running profile. The customized version will disable THP. 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 Service tuned: enabled, running Service ktune: enabled, running
2. Create a duplicate profile from the existing profile. We will use the new profile to disable the THP. To do this copy all the content from the current profile directory to the newly created profile directory.
# cd /etc/tune-profiles/ # cp -r /etc/tune-profiles/throughput-performance /etc/tune-profiles/nothp_profile
3. We will now disable THP in the new profile and activate the new profile. Change the line shown below :
From :
# vi /etc/tune-profiles/nothp_profile/ktune.sh set_transparent_hugepages always
To :
# vi /etc/tune-profiles/nothp_profile/ktune.sh set_transparent_hugepages never
4. Activate the new profile for changes to take effect.
# tuned-adm profile nothp_profile
# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled always [never]