mongodb WARNING:transparent_hugepage/enabled

登陸mongodb 數據庫:顯示報警信息如下:

2018-09-12T05:41:06.390+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-09-12T05:41:06.390+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

原因:

就是允許hugepage可以動態分配,而不是系統啓動時預先分配,對內存消耗很大的服務都不喜歡它,坑人無數。

這個配置會在多個服務上都是坑 :hdfs 、elasticsearch ,mongodb ,oracle ,推薦默認系統初始化就關掉。

關閉方法:

centos上的關閉方法是
echo never > /sys/kernel/mm/transparent_hugepage/enabled

ubuntu:

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never> /sys/kernel/mm/transparent_hugepage/defrag

永久關閉

寫入文件 :/etc/rc.local

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

或者

1: Create the init.d script.
Create the following file at /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

Make it executable.
Run the following command to ensure that the init script can be used:

sudo chmod 755 /etc/init.d/disable-transparent-hugepages

參考信息:
http://www.mongoing.com/docs/tutorial/transparent-huge-pages.html
https://blog.csdn.net/csfreebird/article/details/49307935

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章