micwanyoike

/etc/init.d/disable-transparent-hugepages

Feb 23rd, 2017
618
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides:          disable-transparent-hugepages
  4. # Required-Start:    $local_fs
  5. # Required-Stop:
  6. # X-Start-Before:    mongod mongodb-mms-automation-agent
  7. # Default-Start:     2 3 4 5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: Disable Linux transparent huge pages
  10. # Description:       Disable Linux transparent huge pages, to improve
  11. #                    database performance.
  12. ### END INIT INFO
  13.  
  14. case $1 in
  15.   start)
  16.     if [ -d /sys/kernel/mm/transparent_hugepage ]; then
  17.       thp_path=/sys/kernel/mm/transparent_hugepage
  18.     elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
  19.       thp_path=/sys/kernel/mm/redhat_transparent_hugepage
  20.     else
  21.       return 0
  22.     fi
  23.  
  24.     echo 'never' > ${thp_path}/enabled
  25.     echo 'never' > ${thp_path}/defrag
  26.  
  27.     re='^[0-1]+$'
  28.     if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
  29.     then
  30.       # RHEL 7
  31.       echo 0  > ${thp_path}/khugepaged/defrag
  32.     else
  33.       # RHEL 6
  34.       echo 'no' > ${thp_path}/khugepaged/defrag
  35.     fi
  36.  
  37.     unset re
  38.     unset thp_path
  39.     ;;
  40. esac
RAW Paste Data