You could run those commands before MySQL startup by editing the mysql startup scripts. But it would be better to make those settings persistent by editing your /etc/sysfs.conf
.
If you want to disable transparent hugepage you should add:
kernel/mm/transparent_hugepage/enabled = never
to your sysctl configuration.
After you edited your sysctl configuration you can reread the configuration with:
sysctl -p path/to/your/sysctl/config
The location of the sysctl configuration file depends on the distribution you are using. You should be able to determine the file by looking into the sysctl
man page man sysctl
. The path should be listed at the end under FILES
Debian based distributions like Ubuntu seem to use /etc/sysfs.conf
, RedHat based distributions seem to use /etc/sysctl.conf
.
If you really want to change the setting via startup scripts you could edit your /etc/rc.local
and add these lines:
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
But editing /etc/sysfs.conf
would be much cleaner.
If you need more information I recommend reading this https://askubuntu.com/ question.