Linux如何禁用透明大页

环境:
RHEL 6.5 + Oracle 11.2.0.4 RAC

1.确认透明大页是否开启

grep HugePage /proc/meminfo
cat /sys/kernel/mm/redhat_transparent_hugepage/enabled

[root@jystdrac1 ~]# grep HugePage /proc/meminfo 
AnonHugePages:    690176 kB
HugePages_Total:    3433
HugePages_Free:      383
HugePages_Rsvd:       23
HugePages_Surp:        0
[root@jystdrac1 ~]# 

若上面的AnonHugePages > 0, 说明启用了透明大页。还可以查看:

[root@jystdrac1 ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
[always] madvise never

若上面扩号是在never的位置,说明禁用了透明大页。

2.尝试修改grub.conf

vi /etc/grub.conf 追加如下配置:

transparent_hugepage=never

重启主机:

shutdown -Fr now

再次查询AnonHugePages发现透明大页并没有被禁用。

3.查阅资料确认最终修改方法

随后查阅资料,参考MOS:ALERT: Disable Transparent HugePages on SLES11, RHEL6, RHEL7, OL6, OL7, and UEK2 and above (Doc ID 1557478.1)
文中提到两种方法:

To disable Transparent HugePages boot time either one of the following 2 methods may be used:

Add the following to the kernel boot line in /etc/grub.conf (a symlink to /boot/grub/grub.conf) and reboot the server (this is the preferred method):

transparent_hugepage=never
Once modified the line will read similar to the following example:

title Oracle Linux Server (2.6.32-300.25.1.el6uek.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-300.25.1.el6uek.x86_64 ro root=LABEL=/ transparent_hugepage=never
initrd /initramfs-2.6.32-300.25.1.el6uek.x86_64.img

OR

Add the following lines in /etc/rc.local and reboot the server (this still can be done on Redhat 7 although rc.local is being deprecated):

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
Please change the file path for RHEL kernel to /sys/kernel/mm/redhat_transparent_hugepage/ accordingly.

发现之前用的方法,同样也是MOS建议优先选择的方法,就是将transparent_hugepage=never添加到/etc/grub.conf中,但是是加到kenel那一行后面的,实际尝试后可行。
在节点2测试,公开 /etc/grub.conf 配置文件:

[root@jystdrac2 ~]# cat /etc/grub.conf 
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_linuxbase-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_linuxbase-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_linuxbase/lv_root rd_NO_MD rd_LVM_LV=vg_linuxbase/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet transparent_hugepage=never
        initrd /initramfs-2.6.32-431.el6.x86_64.img

查看透明大页也是关闭的:

[oracle@jystdrac2 ~]$ grep HugePage /proc/meminfo 
AnonHugePages:         0 kB
HugePages_Total:    3433
HugePages_Free:     3433
HugePages_Rsvd:        0
HugePages_Surp:        0

[root@jystdrac2 ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
always madvise [never]
This entry was posted in Linux and tagged . Bookmark the permalink.