Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh -e
- # Ensure MSR module is loaded
- sudo modprobe msr
- # Set vm.swappiness to 10 to reduce swapping
- sudo sysctl -w vm.swappiness=10
- # Ensure PWM is enabled
- if [ -e /sys/class/hwmon/hwmon4/pwm1_enable ]; then
- echo 1 | sudo tee /sys/class/hwmon/hwmon4/pwm1_enable
- fi
- # Set fan speed to maximum (255)
- if [ -e /sys/class/hwmon/hwmon4/pwm1 ]; then
- echo 255 | sudo tee /sys/class/hwmon/hwmon4/pwm1
- fi
- # HugePages and 1GB HugePages Setup
- echo "Setting HugePages and 1GB HugePages..."
- # Set HugePages to the number of CPU cores
- echo "Setting vm.nr_hugepages=1280"
- sysctl -w vm.nr_hugepages=1280
- # Enable 1GB HugePages
- for i in $(find /sys/devices/system/node/node* -maxdepth 0 -type d); do
- echo 3 >"$i/hugepages/hugepages-1048576kB/nr_hugepages"
- done
- echo "1GB pages successfully enabled"
- # MSR Tuning Script
- MSR_FILE=/sys/module/msr/parameters/allow_writes
- # Ensure script is run as root
- [ "$(id -u)" -eq 0 ] || {
- echo "Please run this script as root."
- exit 1
- }
- # Check for wrmsr command
- command -v wrmsr >/dev/null || {
- echo "wrmsr command not found. Please install 'msr-tools'."
- exit 1
- }
- if test -e "$MSR_FILE"; then
- echo on >$MSR_FILE
- else
- modprobe msr allow_writes=on
- fi
- CPUINFO=/proc/cpuinfo
- # MSR tuning for AMD or Intel CPUs
- if grep -E 'AMD Ryzen|AMD EPYC|AuthenticAMD' $CPUINFO >/dev/null; then
- if grep "cpu family[[:space:]]\{1,\}:[[:space:]]25" $CPUINFO >/dev/null; then
- if grep "model[[:space:]]\{1,\}:[[:space:]]97" $CPUINFO >/dev/null; then
- echo "Detected Zen4 CPU"
- wrmsr -a 0xc0011020 0x4400000000000 || echo "Failed to write MSR 0xc0011020"
- wrmsr -a 0xc0011021 0x4000000000040 || echo "Failed to write MSR 0xc0011021"
- wrmsr -a 0xc0011022 0x8680000401570000 || echo "Failed to write MSR 0xc0011022"
- wrmsr -a 0xc001102b 0x2040cc10 || echo "Failed to write MSR 0xc001102b"
- else
- echo "Detected Zen3 CPU"
- wrmsr -a 0xc0011020 0x4480000000000 || echo "Failed to write MSR 0xc0011020"
- wrmsr -a 0xc0011021 0x1c000200000040 || echo "Failed to write MSR 0xc0011021"
- wrmsr -a 0xc0011022 0xc000000401570000 || echo "Failed to write MSR 0xc0011022"
- wrmsr -a 0xc001102b 0x2000cc10 || echo "Failed to write MSR 0xc001102b"
- fi
- elif grep "cpu family[[:space:]]\{1,\}:[[:space:]]26" $CPUINFO >/dev/null; then
- echo "Detected Zen5 CPU"
- wrmsr -a 0xc0011020 0x4400000000000 || echo "Failed to write MSR 0xc0011020"
- wrmsr -a 0xc0011021 0x4000000000040 || echo "Failed to write MSR 0xc0011021"
- wrmsr -a 0xc0011022 0x8680000401570000 || echo "Failed to write MSR 0xc0011022"
- wrmsr -a 0xc001102b 0x2040cc10 || echo "Failed to write MSR 0xc001102b"
- else
- echo "Detected Zen1/Zen2 CPU"
- wrmsr -a 0xc0011020 0 || echo "Failed to write MSR 0xc0011020"
- wrmsr -a 0xc0011021 0x40 || echo "Failed to write MSR 0xc0011021"
- wrmsr -a 0xc0011022 0x1510000 || echo "Failed to write MSR 0xc0011022"
- wrmsr -a 0xc001102b 0x2000cc16 || echo "Failed to write MSR 0xc001102b"
- fi
- elif grep "Intel" $CPUINFO >/dev/null; then
- echo "Detected Intel CPU"
- wrmsr -a 0x1a4 0xf || echo "Failed to write MSR 0x1a4"
- else
- echo "No supported CPU detected"
- fi
- echo "System optimizations applied."
Advertisement
Add Comment
Please, Sign In to add comment