Skip to content

Instantly share code, notes, and snippets.

@cherts
Created October 8, 2019 14:28
Show Gist options
  • Select an option

  • Save cherts/750be6dcae925127e36d3f18837aa1e9 to your computer and use it in GitHub Desktop.

Select an option

Save cherts/750be6dcae925127e36d3f18837aa1e9 to your computer and use it in GitHub Desktop.
Disable Transparent Huge Pages (THP) in Ubuntu
#!/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
@cherts

cherts commented Oct 8, 2019

Copy link
Copy Markdown
Author
sudo wget https://gist.githubusercontent.com/CHERTS/750be6dcae925127e36d3f18837aa1e9/raw/8fa5eef9c01b5fcaf35d09e1f6be6dcd48e6e6b6/disable-transparent-hugepages -O /etc/init.d/disable-transparent-hugepages
sudo chmod 755 /etc/init.d/disable-transparent-hugepages
sudo update-rc.d disable-transparent-hugepages defaults
sudo /etc/init.d/disable-transparent-hugepages start

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