php disable hugepage,禁用Transparent Huge Pages
全文翻譯于MongoDB官方手冊 ,已經(jīng)盡力保持原版。但能力有限……
開機(jī)腳本
使用tunded與ktune
測試配置是否生效
注意:
本頁描述了如何在Red Hat Enterprise Linux 與CentOS 6、7上禁用Transparent Huge Page,如需在其他的系統(tǒng)上執(zhí)行禁用THP,請參閱相應(yīng)文檔。
Transparent Huge Pages (THP)是一種Linux內(nèi)存管理機(jī)制,減少了Translation Lookaside Buffer (TLB)使用larger memory pages時(shí)的尋址開銷。
但是數(shù)據(jù)庫系統(tǒng)通常在使用THP的時(shí)候性能低下,因?yàn)樗鼈儍A向于稀疏而非連續(xù)的內(nèi)存訪問模式。你應(yīng)該再Linux主機(jī)上禁用THP以確保MongoDB具備最佳性能。
開機(jī)腳本
重要:
如果你使用了 tuned 或者 ktune (例如,如果你使用的是Red Hat 或者 CentOS 6及更高版本,你必須>附加另外設(shè)置以確保THP不會被重新啟用,參見 使用tuned與ktune
1. 創(chuàng)建開機(jī)腳本
創(chuàng)建此文件并寫入如下內(nèi)容 /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. 賦予可運(yùn)行權(quán)限:
sudo chmod 755 /etc/init.d/disable-transparent-hugepages
3.配置此腳本開機(jī)啟動:
發(fā)行版 與 命令
Ubuntu 與Debian sudo update-rc.d disable-transparent-hugepages defaults
SUSE sudo insserv /etc/init.d/disable-transparent-hugepages
Red Hat, CentOS, Amazon Linux, and derivatives sudo chkconfig --add disable-transparent-hugepages
4. 覆蓋tuned與ktune設(shè)置
如果你使用了 tuned 或者 ktune (例如,如果你使用的是Red Hat 或者 CentOS 6及更高版本,你必須立刻配置以保護(hù)上述設(shè)置。
使用 tuned 或者 ktune
如果你使用了tuned 或者 ktune,除了安裝開機(jī)腳本外還必須執(zhí)行此步驟
tuned與ktune是動態(tài)內(nèi)核調(diào)整工具,可以在Redhat或CentOS上禁用THP。在tuned或者ktune中禁用THP,你需要創(chuàng)建一個(gè)新的配置文件去設(shè)置THP的狀態(tài)為never
Redhat與CentOS6
1.創(chuàng)建新的配置文件
從相關(guān)目錄下復(fù)制默認(rèn)配置文件并重命名,本例中,我們復(fù)制 default 并命名為np-top:
sudo cp -r /etc/tune-profiles/default /etc/tune-profiles/no-thp
2.編輯ktune.sh
編輯 /etc/tune-profiles/no-thp/ktune.sh 增加如下一行:
set_transparent_hugepages never
在此文件的start()塊,return 0之前。
3.使此文件可用
sudo tuned-adm profile no-thp
Red Hat /Cent OS 7
1.創(chuàng)建新文件
創(chuàng)建一個(gè)新的tuned配置文件目錄:
sudo mkdir /etc/tuned/no-thp
2.編輯tuned.conf文件
創(chuàng)建并編譯/etc/tuned/no-thp/tuned.conf,寫入如下內(nèi)容:
[main]
include=virtual-guest
[vm]
transparent_hugepages=never
3.使能新文件:
sudo tuned-adm profile no-thp
測試你的配置
使用如下命令檢查THP狀態(tài):
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag
在Red Hat Enterprise Linux或者CentOS或者其他基于Red hat Linux的發(fā)行版,你可能需要使用如下命令:
cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
cat /sys/kernel/mm/redhat_transparent_hugepage/defrag
輸出結(jié)果應(yīng)該是
always madvise [never]
總結(jié)
以上是生活随笔為你收集整理的php disable hugepage,禁用Transparent Huge Pages的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UTL_FILE
- 下一篇: 动态规划算法php,php算法学习之动态