Linux Performance Optimization
A collection of 140 little known Linux optimization commands for optimizing Linux VPS's and general Gaming Performance. Gaming devices such as the Steam Deck/Linux laptops and Desktops should have improved FPS, Battery life and network performance.
Formatting is a WIP due to how many optimizations there are, commands will be bolded soon. For now they are space separated with a blank line between the description of what the command does and the actual command.
- System Configuration
- Memory Management
- CPU Optimization
- Disk I/O Optimization
- Network Optimization
- File System Optimization
- Process Management
- Kernel Tuning
- Database Optimization
- Miscellaneous Optimizations
THP can cause performance issues for databases. More info
Tuned-ADM is a tool for tuning system performance. Manual
init 3
Instructions for changing run levels
Stacer is a system optimizer and monitoring tool. More info
systemctl list-unit-files --type=service
sudo systemctl disable SERVICE_NAME
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash noapic noacpi nosplash irqpoll"
DefaultTimeoutStartSec=10s
DefaultTimeoutStopSec=10s
sudo perl -pi -e 's/^(GRUB_CMDLINE_LINUX_DEFAULT.*)"$/$1 zswap.enabled=1 zswap.compressor=lz4 zswap.zpool=z3fold zswap.max_pool_percent=25"/' /etc/default/grub
sudo update-grub
sudo echo -e 'lz4\nlz4_compress\nz3fold' >> /etc/initramfs-tools/modules
sudo update-initramfs -u
sudo reboot
cat << EOF | sudo tee /etc/tmpfiles.d/mglru.conf
w /sys/kernel/mm/lru_gen/enabled - - - - 7
w /sys/kernel/mm/lru_gen/min_ttl_ms - - - - 0
EOF
cat << EOF | sudo tee /etc/security/limits.d/memlock.conf
* hard memlock 2147484
* soft memlock 2147484
EOF
sysctl -w vm.dirty_background_ratio=5
sysctl -w vm.dirty_ratio=10
echo 'vm.nr_hugepages=128' >> /etc/sysctl.conf
apt-get install zram-config
sysctl -w vm.swappiness=10
cat << EOF | sudo tee /etc/systemd/system/cpu_performance.service
[Unit]
Description=CPU performance governor
[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower frequency-set -g performance
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable cpu_performance.service
isolcpus=1,2
echo 1 > /proc/sys/kernel/sched_autogroup_enabled
apt-get install schedtool
schedtool -R -p 20 -e myapp
cat << EOF | sudo tee /etc/udev/rules.d/64-ioschedulers.rules
ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="kyber"
ACTION=="add|change", KERNEL=="sd[a-z]|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="kyber"
EOF
hdparm -W1 /dev/sda
mount -t tmpfs -o size=1G tmpfs /mnt/ramdisk
echo 1 > /sys/module/zswap/parameters/enabled
echo lz4 > /sys/module/zswap/parameters/compressor
echo 20 > /sys/module/zswap/parameters/max_pool_percent
apt-get install blktrace
blktrace -d /dev/sda
blockdev --setra 2048 /dev/sda
ifconfig eth0 mtu 9000
or
ip link set dev eth0 mtu 9000
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
sysctl -w net.ipv4.tcp_keepalive_time=600
sysctl -w net.ipv4.tcp_keepalive_probes=5
sysctl -w net.ipv4.tcp_keepalive_intvl=60
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.ipv4.tcp_sack=1
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.tcp_max_syn_backlog=2048
sysctl -w net.ipv4.tcp_max_tw_buckets=400000
sysctl -w net.ipv4.tcp_fastopen=3
ethtool -K eth0 gro on
ethtool -K eth0 gso on
ethtool -K eth0 tso on
apt-get install dnsmasq
iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
apt-get install ifenslave
sysctl -w net.ipv6.conf.all.disable_ipv6=0
sysctl -w net.ipv4.tcp_reordering=3
ifconfig eth0 txqueuelen 10000
xfs_fsr /dev/sda1
fstrim -v /
apt-get install zfsutils-linux
zpool create mypool /dev/sda
mount -o remount,noatime,nodiratime /
echo "fs.file-max = 500000" >> /etc/sysctl.conf
ulimit -n 500000
echo '-1000' > /proc/$(pidof critical_process)/oom_score_adj
cgcreate -g cpu,memory:mygroup
cgset -r cpu.shares=512 mygroup
cgset -r memory.limit_in_bytes=512M mygroup
npm install pm2@latest -g
pm2 start app.js
apt-get install cpulimit
cpulimit -e myapp -l 50
sysctl -w net.core.somaxconn=1024
sysctl -w net.core.netdev_max_backlog=5000
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w fs.inotify.max_user_watches=524288
sysctl -w kernel.panic=10
sysctl -w kernel.panic_on_oops=1
sysctl -w net.ipv4.tcp_rfc1337=1
sysctl -w net.ipv4.tcp_mtu_probing=1
sysctl -w net.ipv4.tcp_base_mss=536
sysctl -w fs.file-max=2097152
sysctl -w net.ipv4.tcp_low_latency=1
echo 1000 > /proc/sys/kernel/timer_frequency
echo 1 > /sys/kernel/mm/ksm/run
sysctl -w kernel.sem="250 32000 100 128"
sysctl -w fs.inode-nr
sysctl -w fs.inode-state
echo 0 > /proc/sys/kernel/preempt
innodb_use_native_aio = 1
query_cache_size = 64M
query_cache_type = ON
mount -t tmpfs -o size=512M tmpfs /tmp
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
apt-get install squid
sed -i 's/^#LogLevel=info/LogLevel=error/' /etc/systemd/journald.conf
sudo sed -i -e '/home/s/\bdefaults\b/&,noatime/' /etc/fstab
Note: Always test these optimizations in a controlled environment before applying them to production systems. Some optimizations may not be suitable for all use cases or may require fine-tuning based on your specific hardware and workload.