Linux VPS Performance Tuning: CPU Governors, Swappiness, and I/O Schedulers

A default Linux VPS installation ships with conservative kernel parameters optimized for compatibility, not performance. This guide walks through practical tuning techniques that can improve your VPS throughput by 20-40% with zero hardware cost. Before diving in, compare VPS providers on our comparison table to ensure your provider offers NVMe storage and dedicated vCPUs for consistent performance.

CPU Frequency Scaling and Governors

Modern Linux kernels manage CPU frequency through governors. On a VPS, set the governor to “performance”:

# Check current governor
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

# Install cpupower
sudo apt install -y linux-tools-common linux-tools-$(uname -r)

# Set performance governor
sudo cpupower frequency-set -g performance

# Verify
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Make it permanent with a systemd service:

sudo tee /etc/systemd/system/cpupower.service << 'EOF'
[Unit]
Description=Set CPU governor to performance
[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower frequency-set -g performance
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable --now cpupower.service

Memory Management: Swappiness and HugePages

# Reduce swappiness to 10 (only swap under extreme pressure)
sudo sysctl -w vm.swappiness=10
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf

# Enable Transparent HugePages (best for database servers)
echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

# Tune dirty page ratios
sudo sysctl -w vm.dirty_ratio=30
sudo sysctl -w vm.dirty_background_ratio=5

Disk I/O Scheduler

NVMe SSDs perform best with the “none” scheduler, while SATA SSDs benefit from “mq-deadline”:

# Check current scheduler
cat /sys/block/*/queue/scheduler

# Set "none" for NVMe
echo none | sudo tee /sys/block/nvme0n1/queue/scheduler

# Set "mq-deadline" for SATA SSDs
echo mq-deadline | sudo tee /sys/block/sda/queue/scheduler

# Increase read-ahead
sudo blockdev --setra 4096 /dev/nvme0n1

Network Stack Tuning

# Enable TCP BBR congestion control
echo "tcp_bbr" | sudo tee -a /etc/modules-load.d/modules.conf
sudo modprobe tcp_bbr
sudo sysctl -w net.core.default_qdisc=fq
sudo sysctl -w net.ipv4.tcp_congestion_control=bbr

# Increase network buffer sizes
sudo sysctl -w net.core.rmem_max=134217728
sudo sysctl -w net.core.wmem_max=134217728
sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 134217728"
sudo sysctl -w net.ipv4.tcp_wmem="4096 65536 134217728"

# Increase backlog
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=8192

Verifying Tuning Impact

Run before-and-after benchmarks:

# CPU performance
sysbench cpu --cpu-max-prime=20000 --threads=$(nproc) run

# Memory throughput
sysbench memory --memory-block-size=1K --memory-total-size=10G run

# Network throughput
iperf3 -c iperf.he.net -t 30

These tuning techniques work on any Linux VPS. For rock-solid performance with managed support, consider Cloudways managed VPS. For unmanaged VPS with full root access, InterServer VPS offers KVM-based instances with NVMe storage. Always compare VPS providers on our comparison table to find the best-performing provider for your specific workload.

Leave a Reply