Tuesday, January 15, 2019

Disable Transparent Hugepages on Oracle Linux / Redhat Enterprise Linux

Transparent Hugepages (THP) are similar to standard HugePages. However, while standard HugePages allocate memory at startup, Transparent Hugepages memory uses the khugepaged thread in the kernel to allocate memory dynamically during runtime, using swappable HugePages.

They may cause delays in accessing memory that can result in node restarts in Oracle RAC environments, or performance issues or delays for Oracle Database single instances. Oracle recommends to disable Transparent HugePages on Oracle database servers.

Following discussion is based on Oracle Linux / Redhat Enterprise Linux 7.5, it may be different on other Linux distributions.
Updated on Tuesday, February 1, 2022 with following,
It also works for Oracle Linux /Redhat Enterprise Linux 8.x

1. Check if THP is enabled

Run one of the following commands as the root user

Red Hat Enterprise Linux (RHEL) kernels:
# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled

Oracle Unbreakable Enterprise Kernel (UEK):
# cat /sys/kernel/mm/transparent_hugepage/enabled

If the directory "/sys/kernel/mm/transparent_hugepage/" does not exist on Oracle Linux with UEK, the transparent hugepage is removed from the kernel, so there is no need to disable the transparent hugepage.

If Transparent HugePages are being used, the output looks like following
[always] madvise never

If Transparent Hugepages are disabled, [never] flag will be enabled as following
always madvise [never]

2. Disable THP at run time

The quick and easiest way to disable Transparent Hugepages is 'echo' command,

RHEL kernel,
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag

Oracle UEK,
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag

The above commands will stop only creation and usage of the new THP. The THP which were created and used before the above commands were run would not be disassembled into the regular memory pages. And the THP will be enabled again after system is rebooted.

To get rid of THP completely, the system should be rebooted with THP disabled at boot time. Therefore, you may be able to use above commands in RC script (i.e. "rc.local") to disable THP at boot time.


3. Disable THP at boot time

The THP can be disabled at boot time via Linux kernel command line as following,

3.1 Check if the system boot using BIOS or EFI

System using EFI has efi created under directory /sys/firmware as following,
# ls -l /sys/firmware
total 0
drwxr-xr-x  6 root root 0 Jan 15 15:37 acpi
drwxr-xr-x  4 root root 0 Jan 15 15:37 dmi
drwxr-xr-x  5 root root 0 Jan 14 09:05 efi
drwxr-xr-x 56 root root 0 Jan 15 15:37 memmap
# ls -l /sys/firmware/efi
total 0
-r--r--r--  1 root root 4096 Jan 15 15:35 config_table
drwxr-xr-x  2 root root    0 Jan  7 16:13 efivars
-r--r--r--  1 root root 4096 Jan 15 15:35 fw_platform_size
-r--r--r--  1 root root 4096 Jan 15 15:35 fw_vendor
-r--r--r--  1 root root 4096 Jan 15 15:35 runtime
drwxr-xr-x  6 root root    0 Jan 15 15:35 runtime-map
-r--------  1 root root 4096 Jan 15 15:35 systab
drwxr-xr-x 56 root root    0 Jan 15 15:35 vars

EFI NVRAM variables will be found under "/sys/firmware/efi/vars" or "/sys/firmware/efi/efivars".

System using BIOS does not have efi directory created in /sys/firmware,
# ls -l /sys/firmware
total 0
drwxr-xr-x.  5 root root 0 Jan 11 14:48 acpi
drwxr-xr-x.  4 root root 0 Jan 11 14:48 dmi
drwxr-xr-x. 11 root root 0 Jan 11 14:48 memmap

3.2 Add "transparent_hugepage=never" to the GRUB_CMDLINE_LINUX entry of "/etc/default/grub"

Original "/etc/default/grub" sample,
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rootvg/rootlv rd.lvm.lv=rootvg/swaplv rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

Modified "/etc/default/grub" sample,
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rootvg/rootlv rd.lvm.lv=rootvg/swaplv rhgb quiet transparent_hugepage=never"
GRUB_DISABLE_RECOVERY="true"

3.3 Create GRUB configuration file

It is recommended to backup original configuration file before creating new one.

System using BIOS,
# cp -p /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old
# grub2-mkconfig -o /boot/grub2/grub.cfg

System using EFI,
# cp -p /boot/efi/EFI/redhat/grub.cfg /boot/efi/EFI/redhat/grub.cfg.old
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

3.4 Reboot system and confirm THP is disabled

No comments: