#這裏只針對CentOs7系統,內核3.10,grub2
#修改/etc/default/grub,在GRUB_CMDLINE_LINUX中添加transparent_hugepage=never,以下
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=system/root rd.lvm.lv=system/swap rhgb quiet transparent_hugepage=never"
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
#可是這裏有個問題,重啓機器後,defrag一直是always,而不是never,可是也不影響使用,
#我尚未弄明白defrag的做用,從字面意思是整理內存碎片的做用,按理說應該不影響使用,可是有問題,重啓機器後,又變成never了。
#下面是解決disable THP的推薦方法(機器重啓後THP仍舊是關閉的):
#disable-transparent-hugepages腳本內容,放到/etc/init.d/下,
#並受權可執行權限chmod 755 /etc/init.d/disable-transparent-hugepages,並加入開機自啓動chkconfig --add disable-transparent-hugepagescentos
#!/bin/bash case $1 in start) if [ -d /sys/kernel/mm/transparent_hugepage ]; then thp_path=/sys/kernel/mm/transparent_hugepage elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then thp_path=/sys/kernel/mm/redhat_transparent_hugepage else return 0 fi echo 'never' > ${thp_path}/enabled echo 'never' > ${thp_path}/defrag re='^[0-1]+$' if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]] then #RHEL 7 echo 0 > ${thp_path}/khugepaged/defrag else #RHEL 6 echo 'no' > ${thp_path}/khugepaged/defrag fi unset re unset thp_path ;; esac
mkdir /etc/tuned/no-thp -p echo -e "[main]\ninclude=virtual-guest\n[vm]\ntransparent_hugepages=never" >/etc/tuned/no-thp/tuned.conf tuned-adm profile no-thp cat /sys/kernel/mm/transparent_hugepage/enabled cat /sys/kernel/mm/transparent_hugepage/defrag #都是always madvise [never]才能夠。這個是不用重啓機器。