Skip to content

Instantly share code, notes, and snippets.

@kdidenko
Created March 10, 2017 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdidenko/bfa666c816aa9203409662ce3f7f0009 to your computer and use it in GitHub Desktop.
Save kdidenko/bfa666c816aa9203409662ce3f7f0009 to your computer and use it in GitHub Desktop.
Init srcipt for disabling Transparent Huge Pages on Ubuntu 16.04 [Must be located at /etc/init.d/disable-transparent-hugepages file with 0755 permissions]
#!/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
@kdidenko
Copy link
Author

  1. Go to:
    $ cd /etc/init.d/
    $ sudo touch disable-transparent-hugepages && sudo vim disable-transparent-hugepages

  2. Insert code above, save, than and run:
    $ sudo chmod 755 /etc/init.d/disable-transparent-hugepages
    $ sudo update-rc.d disable-transparent-hugepages defaults

  3. Restart the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment