千家信息网

禁用透明HugePages

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,1.检查是否已启用Transparent HugePages红帽企业Linux内核:# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled其他
千家信息网最后更新 2025年01月20日禁用透明HugePages


1.检查是否已启用Transparent HugePages
红帽企业Linux内核:

# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled


其他内核:

# cat /sys/kernel/mm/transparent_hugepage/enabled[always] madvise never  <<---- [always]标志 THP is enabled 如果从内核中删除Transparent HugePages,则既不存在/sys/kernel/mm/transparent_hugepage也不/sys/kernel/mm/redhat_transparent_hugepage files存在。


2.禁用透明HugePages:

OL 7:

1.编辑tuned.conf[root@prodb ~]# uname -r4.1.12-112.16.4.el7uek.x86_64[root@prodb ~]# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never][root@prodb ~]# cd /usr/lib/tuned/throughput-performance/[root@prodb ~]# cp tuned.conf tuned.conf.bak[vm] transparent_hugepages=always to [vm]transparent_hugepages=never2.重启# shutdown -r now3.校验[root@prodb ~]# uname -r4.1.12-112.16.4.el7uek.x86_64[root@prodb ~]# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never]  <<--- THP Disabled# cat /proc/cmdlineBOOT_IMAGE=/vmlinuz-4.1.12-112.16.4.el7uek.x86_64 .... transparent_hugepage=never如果未生效,按如下方法设置:1.检查profile# tuned-adm activeCurrent active profile: virtual-guest <<--- Virtual-guest is the active profile2.修改tuned.conf#cp /usr/lib/tuned/virtual-guest/tuned.conf /usr/lib/tuned/virtual-guest/tuned.conf.bkp_original增加以下内容:[main]include=throughput-performance[vm]transparent_hugepages=never3.重启# shutdown -r now4.校验[root@prodb ~]# uname -r[root@prodb ~]# cat /sys/kernel/mm/transparent_hugepage/enabled # cat /proc/cmdline


RHEL 7:

1.编辑grub.conf在GRUB_CMDLINE_LINUX末尾添加transparent_hugepage=never #vim /etc/default/grubGRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap ... transparent_hugepage=never"2.Rebuild grubOn BIOS-based machines: ~]# grub2-mkconfig -o /boot/grub2/grub.cfgOn UEFI-based machines: ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg3.reboot# shutdown -r now4.校验# cat /proc/cmdlineBOOT_IMAGE=/vmlinuz-4.1.12-112.16.4.el7uek.x86_64 .... transparent_hugepage=never如果未生效,按如下方法设置:1.检查profile# tuned-adm active2.自定义profile# mkdir /etc/tuned/myprofile-nothp# cat /etc/tuned/myprofile-nothp/tuned.conf[main]include= throughput-performance[vm]transparent_hugepages=never3.激活配置文件# chmod +x /etc/tuned/myprofile-nothp/tuned.conf# tuned-adm profile myprofile-nothp4.重启校验# shutdown -r now# cat /sys/kernel/mm/transparent_hugepage/enabled5.关闭服务# systemctl stop tuned# systemctl disable tuned# systemctl stop ktune# systemctl disable ktune或者# tuned-adm offTHP status in other UEK kernel versionsUEK3 disabled by default  [root@ol6 ~]# grep -i CONFIG_TRANSPARENT_HUGEPAGE /boot/config-3.8.13-118.6.2.el6uek.x86_64# CONFIG_TRANSPARENT_HUGEPAGE is not set  UEK4 enabled by default[root@ol7 ~]# grep -i CONFIG_TRANSPARENT_HUGEPAGE /boot/config-4.1.12-37.2.2.el7uek.x86_64CONFIG_TRANSPARENT_HUGEPAGE=yCONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y


RHEL 6或更低版本

启用状态为[always]# cat /sys/kernel/mm/[hedhat_]transparent_hugepage/enabled[always] never或者查询以下内容# grep AnonHugePages /proc/meminfoAnonHugepages: xxxx kB要求XXXX>0禁用状态为[never]# cat /sys/kernel/mm/[hedhat_]transparent_hugepage/enabledalways [never]禁用huge1.编辑grub.conf #vi  /etc/grub.conf kernel /vmlinuz-2.6.32-300.25.1.el6uek.x86_64 ro root=LABEL=/ transparent_hugepage=never或者#vi /etc/rc.localif test -f /sys/kernel/mm/transparent_hugepage/enabled; then   echo never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag; then   echo never > /sys/kernel/mm/transparent_hugepage/defragfi2.重启生效


引用:

ALERT: Disable Transparent HugePages on SLES11, RHEL6, RHEL7, OL6, OL7, and UEK2 and above (文档 ID 1557478.1)  NOTE:2066217.1 - Oracle Linux 7 - How to disable Transparent HugePages for RHCK kernel?  (How to disable transparent hugepages (THP) on Red Hat Enterprise Linux 7)


0