Disabling transparent hugepages on Ubuntu/Debian

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

If your mongo installation is complaining about transparent hugepages being enabled:

Server has startup warnings:
2016-09-16T00:25:40.010+0000 I CONTROL  [initandlisten]
2016-09-16T00:25:40.010+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-09-16T00:25:40.010+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-09-16T00:25:40.010+0000 I CONTROL  [initandlisten]

Then you can disable them in several ways:

  • disable temporarily (will not survive restart):
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

Then, you will have to restart your mongod.


  • disable permanently (will survive restart) - here is a init.d script for Ubuntu/Debian, though a similar one should also work for CentOS/RedHat and other systems:
#!/bin/sh
### 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

    unset thp_path
    ;;
esac

Then, make sure to have it enabled with:

update-rc.d disable-transparent-hugepages defaults