How to disable Transparent Hugepage in Linux

Transparent Huge Pages (THP) is a Linux memory management feature that allows the kernel to automatically create and manage large memory pages (2MB or 1GB) on demand. THP can improve system performance by reducing the number of page table entries required to map the system’s memory, and can also improve memory locality for certain workloads.

To enable Transparent Huge Pages (THP) on Linux, you can use the following steps:

  1. Check the current THP status:
[root@techie ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@techie ~]#
  1. To enable THP, you can use the command:
[root@techie ~]# echo always > /sys/kernel/mm/transparent_hugepage/enabled
[root@techie ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@techie ~]#
  1. To disable THP, you can use the command:
[root@techie ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@techie ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@techie ~]#
  1. To make the setting persistent across reboots, you can edit the grub configuration file /etc/default/grub and add the following kernel parameter:
transparent_hugepage=never
  1. Finally, update the grub configuration:
update-grub

Please note that enabling THP may not always improve performance and can sometimes even have a negative impact on performance. It’s important to test and monitor the system’s performance with and without THP to determine the best configuration for your specific workload.

Leave a Reply

Your email address will not be published. Required fields are marked *