Table of Contents
In this article I will share the steps and instructions to check transparent huge pages and disable Transparent HugePages using
grub2-editenv in RHEL 8 Linux. To permanently disable Transparent huge pages GRUB2 must be updated with
transparent_hugepage=never followed by a reboot to activate the changes.
The steps to update GRUB2 in RHEL/CentOS 8 is different compared to RHEL/CentOS 7 and earlier releases, so follow the article instructions Step-by-Step to disable transparent huge pages in RHEL/CentOS 8
Overview on HugePages
Hugepages is a feature that allows the Linux kernel to utilise the multiple page size capabilities of modern hardware architectures. CPUs have a built-in memory management unit that contains a list of these pages, with each page referenced through a page table entry.
There are two ways to enable the system to manage large amounts of memory:
- Increase the number of page table entries in the hardware memory management unit
- Increase the page size
The first method is expensive, since the hardware memory management unit in a modern processor only supports hundreds or thousands of page table entries.
- The typical page size in an x86 system is 4KB, with other larger page sizes available.
- Larger page sizes mean that there are fewer pages overall, and therefore increases the amount of system memory that can have its virtual to physical address translation stored in the TLB, and as a result lowers the potential for TLB misses, which increases performance.
- With larger page sizes, there is an increased potential for memory to be wasted as processes must allocate in pages, but not all of the memory is likely required.
- As a result, choosing a page size is a trade off between providing faster access times by using larger pages and ensuring maximum memory utilization by using smaller pages.
- In Linux we use hugepages for this purpose where huge pages are blocks of memory that come in 2MB and 1GB sizes. The page tables used by the 2MB pages are suitable for managing multiple gigabytes of memory, whereas the page tables of 1GB pages are best for scaling to terabytes of memory
Check Transparent Huge Pages (before disable)
Before you enable or disable transpare huge pages, it is important to know if THP is running or disabled currently on the Linux server. To check transparent huge pages status, look out for below file:
[root@rhel-8 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never
So currently transparent huge pages are enabled on our RHEL/CentOS 8 server.
Permanently disable TransParent HugePages GRUB2 RHEL/CentOS 8
To permanently disable Transparent HugePages GRUB2 update is required. If you are using RHEL/CentOS 7 and earlier releases then you should check: steps to disable transparent hugepage on RHEL/CentOS 7.
As with RHEL/CentOS 8, we use grub2-editenv and grubby tool to update GRUB2. Hence in this article to permanently disable Transparent Hugepages GRUB2 update would be done using
Although you can also use the traditional
grub2-mkconfig to rebuild the GRUB2 configuration.
Get GRUB2 kernel parameter list
Get the current kernel command line parameters added in GRUB2 using
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
Update GRUB2 to disable Transparent HugePages (THP)
Here we must append
transparent_hugepage=never at the end of
kernelopts to disable transparent hugepages. This will modify
kernelopts content in
[root@rhel-8 ~]# grub2-editenv - set "$(grub2-editenv - list | grep kernelopts) transparent_hugepage=never"
OR Alternatively you can also give the entire section of
kernelopts and just append
transparent_hugepage=never as shown below: (ignore this command if you have executed above command)
[root@rhel-8 ~]# grub2-editenv - set "kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet transparent_hugepage=never"
Once added, verify the existing kernel options using
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet transparent_hugepage=never
Next reboot the node to permanently disable transparent hugepages
[root@rhel-8 ~]# reboot
Check transparent huge pages status (after disable)
Post reboot check transparent huge pages status
(AnonHugePages) to make sure THP is disabled
[root@rhel-8 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never]
So now this file is pointed at
[never] which means THP is disabled.
You can also check the following files to check transparent huge pages (THP) is disabled.
[root@rhel-8 ~]# grep AnonHugePages: /proc/meminfo AnonHugePages: 0 kB [root@rhel-8 ~]# grep nr_anon_transparent_hugepages /proc/vmstat nr_anon_transparent_hugepages
Lastly I hope the steps from the article to disable transparent huge pages in CentOS/RHEL 8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
How to disable transparent huge pages in RHEL 8