Linux 下关闭THP(Transparent Huge Pages)
背景:有MongoBD数据库和tokuBD对THP 的设置有特殊的设置要求。需要关闭THP功能。设置:#touch/etc/init.d/disable-transparent-hugepages#vim /etc/init.d/disable-transparent-hugepages#!/bin/bash### BEGIN INIT INFO# Provides:...
·
背景:
有MongoBD数据库和tokuBD对THP 的设置有特殊的设置要求。需要关闭THP功能。
设置:
#touch /etc/init.d/disable-transparent-hugepages
#vim /etc/init.d/disable-transparent-hugepages
#!/bin/bash
### BEGIN INIT INFO
# Provides: disable-transparent-hugepages
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before: mongod mongodb-mms-automation-agent
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description: Disable Linux transparent huge pages, to improve
# database performance.
### END INIT INFO
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
2.设置权限:
#sudo chmod 755 /etc/init.d/disable-transparent-hugepages
3.设置系统自动启动:
sudo chkconfig --add disable-transparent-hugepages
4.创建目录:
sudo mkdir /etc/tuned/no-thp
5.编写文件:
#vim /etc/tuned/no-thp/tuned.conf
[main]
include=virtual-guest
[vm]
transparent_hugepages=never
#sudo tuned-adm profile no-thp
6.验证:
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag
更多推荐
已为社区贡献2条内容
所有评论(0)