CentOS7 disables the implementation of Transparent Huge Pages
- 2020-05-27 07:46:35
- OfStack
CentOS7 disables Transparent Huge Pages
Transparent Huge Pages(THP) has been introduced since CentOS6, and this feature is enabled by default from CentOS7. Although THP is intended to improve memory performance, some database vendors recommend turning off THP(e.g., ORACLE, MariaDB, MongoDB, etc.), otherwise performance may suffer.
First check the enabled state of THP:
[root@localhost ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
[root@localhost ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
This state means they're all enabled.
We can, of course, modify each of these files to disable THP at this point, but to make it permanent once and for all, follow these steps.
Edit rc.local file:
[root@localhost ~]# vim /etc/rc.d/rc.local
Add the following:
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
Save exit, and then grant rc.local file execution rights:
[root@localhost ~]# chmod +x /etc/rc.d/rc.local
Finally, restart the system and check THP later. It should be disabled
[root@localhost ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@localhost ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
Thank you for reading, I hope to help you, thank you for your support of this site!