Skip to content

Instantly share code, notes, and snippets.

@pankkor
Created April 29, 2025 08:45
Show Gist options
  • Select an option

  • Save pankkor/37365dab55078bad04d1ca2c496e0680 to your computer and use it in GitHub Desktop.

Select an option

Save pankkor/37365dab55078bad04d1ca2c496e0680 to your computer and use it in GitHub Desktop.
Reduce performance variance of Linux machine.
#!/bin/sh
help="Reduce performance variance of the system.
OPTIONS:
-h, --help This help.
* ANY other argument reverts the changes.
"
case "$1" in
-h|--help) echo "$help"; exit 0;;
esac
if [ "$1" ]; then
echo "REVERT CHANGES"
echo "───────────────────────────────────────────"
echo "Setting CPU governor profile 'powersave'..."
echo "───────────────────────────────────────────"
echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
[ $? = 0 ] && echo "☑ DONE" || echo "☒ FAILED"
echo "───────────────────────────────────────────"
echo "Enabling CPU boost"...
echo "───────────────────────────────────────────"
echo "Trying '/sys/devices/system/cpu/cpufreq/boost'..."
if ! echo 1 | sudo tee /sys/devices/system/cpu/cpufreq/boost; then
echo "Trying intel_pstate..."
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
fi
[ $? = 0 ] && echo "☑ DONE" || echo "☒ FAILED"
echo "───────────────────────────────────────────"
echo "Enabling ASLR..."
echo "───────────────────────────────────────────"
echo 1 | sudo tee /proc/sys/kernel/randomize_va_space
[ $? = 0 ] && echo "☑ DONE" || echo "☒ FAILED"
else
echo "REDUCE VARIANCE"
echo "───────────────────────────────────────────"
echo "Setting CPU governor profile 'performance'..."
echo "───────────────────────────────────────────"
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
[ $? = 0 ] && echo "☑ DONE" || echo "☒ FAILED"
echo "───────────────────────────────────────────"
echo "Disabling CPU boost"...
echo "───────────────────────────────────────────"
echo "Trying '/sys/devices/system/cpu/cpufreq/boost'..."
if ! echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost; then
echo "Trying intel_pstate..."
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
fi
[ $? = 0 ] && echo "☑ DONE" || echo "☒ FAILED"
echo "───────────────────────────────────────────"
echo "Disabling ASLR..."
echo "───────────────────────────────────────────"
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
[ $? = 0 ] && echo "☑ DONE" || echo "☒ FAILED"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment