0

In order to disable the THP

We did the following on all 635 RHEL machines (we have rhel 7.5 version)

This lines are from bash script that we runs on all machines

Step 1

[[ -f /sys/kernel/mm/transparent_hugepage/enabled ]] && echo never > /sys/kernel/mm/transparent_hugepage/enabled
[[ -f /sys/kernel/mm/transparent_hugepage/defrag  ]] && echo never > /sys/kernel/mm/transparent_hugepage/defrag

Verification:

cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]

But as all know this steps are not considered when machine restarted/rebooted

Step 2

So we also did this , we append the following lines to /etc/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

The question is:

Does step 1 as I mentioned above really disabled the THP on the fly?

Note - also other info from one typical machine

sysctl -a | grep hugepage
vm.hugepages_treat_as_movable = 0
vm.nr_hugepages = 0
vm.nr_hugepages_mempolicy = 0
vm.nr_overcommit_hugepages = 0

reference - Configuring Transparent Huge Pages.

Paulo Tomé
  • 3,754
  • 6
  • 26
  • 38
yael
  • 12,598
  • 51
  • 169
  • 303
  • not see how we can do it from sysctl.conf – yael Feb 20 '20 at 14:53
  • Sorry, yes, `/sys` isn’t `/proc/sys`! – Stephen Kitt Feb 20 '20 at 15:02
  • yes: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-configuring_transparent_huge_pages – ron Feb 20 '20 at 18:23
  • in RHEL/CentOS 7.x I strongly recommend `yum install tuned*` and `yum install tuna` – ron Feb 20 '20 at 18:24
  • https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-performance_monitoring_tools-tuned_and_tuned_adm – ron Feb 20 '20 at 18:26
  • we have hadoop machines and tuned not recommended – yael Feb 20 '20 at 19:33

1 Answers1

1

Does step 1 as I mentioned above really disabled the THP on the fly?

Yes, any thing you do in sysfs is done on the fly. It's already documented in the kernel doc/transhuge.html

However, Quoting from https://access.redhat.com/solutions/46111

NOTE: Running the above commands will stop only creation and usage of the new THP. The THP which were created and used at the moment the above commands were run would not be disassembled into the regular memory pages. To get rid of THP completely the system should be rebooted with THP disabled at boot time.

There is a post with your same question. There, ub3rst4r explained that /etc/rc.local didn't work for his use case since it is executed after all the services are started

So, I highly recommend following the official way mentioned in the same kernel doc/transhuge.html

You can change the sysfs boot time defaults of Transparent Hugepage Support by passing the parameter ... transparent_hugepage=never to the kernel command line.

You can of course make it persistent using /etc/default/grub. Also, I recommend testing after the reboot with

grep AnonHugePages /proc/meminfo
AnonHugePages:         0 kB

You should get a value of 0 if it's disabled properly.

Munzir Taha
  • 1,445
  • 4
  • 12
  • so all my procedure is right> – yael Feb 20 '20 at 14:53
  • @yael I updated the answer to reflect a better way of doing it and verifying based on offical docs and others experiences. – Munzir Taha Feb 20 '20 at 15:39
  • /etc/default/grub is too risky , better /etc/rc.local – yael Feb 20 '20 at 16:48
  • @yael: As I said try rc.local and if you got 0 value in your case, that's good. However, with `rc.local` some pages might be reserved by other services that run before `rc.local`. `/etc/default/grub` is not an alternative to `rc.local`. It guarantee that the pages are disabled before any other service manage to use it. Of course, you should always take a backup and make sure you know how to fix things in case something goes wrong or else don't do it. Can you paste the output of `grep AnonHugePages /proc/meminfo` after reboot – Munzir Taha Feb 20 '20 at 16:52
  • grep AnonHugePages /proc/meminfo AnonHugePages: 11001856 kB – yael Feb 20 '20 at 19:55
  • sorry but I dont want to edit the grub with script , its can be risky when edit not do the things right in file , so I not have choice – yael Feb 20 '20 at 19:56
  • @yael: Then don't do it. Sometimes, with some hosting services, you don't even have the option to edit the boot loader. so `rc.local` is a good way to keep in your arsenal but to make the answer useful I clarified the difference, any thing remaining now that I didn't answer for you? – Munzir Taha Feb 21 '20 at 04:02