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 3Instructions for changing run levels
Stacer is a system optimizer and monitoring tool. More info
systemctl list-unit-files --type=service
sudo systemctl disable SERVICE_NAMEGRUB_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 rebootcat << 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
EOFcat << EOF | sudo tee /etc/security/limits.d/memlock.conf
* hard memlock 2147484
* soft memlock 2147484
EOFsysctl -w vm.dirty_background_ratio=5
sysctl -w vm.dirty_ratio=10echo 'vm.nr_hugepages=128' >> /etc/sysctl.confapt-get install zram-configsysctl -w vm.swappiness=10cat << 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.serviceisolcpus=1,2echo 1 > /proc/sys/kernel/sched_autogroup_enabledapt-get install schedtool
schedtool -R -p 20 -e myappcat << 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"
EOFhdparm -W1 /dev/sdamount -t tmpfs -o size=1G tmpfs /mnt/ramdiskecho 1 > /sys/module/zswap/parameters/enabled
echo lz4 > /sys/module/zswap/parameters/compressor
echo 20 > /sys/module/zswap/parameters/max_pool_percentapt-get install blktrace
blktrace -d /dev/sdablockdev --setra 2048 /dev/sdaifconfig eth0 mtu 9000or
ip link set dev eth0 mtu 9000echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -psysctl -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=3ethtool -K eth0 gro on
ethtool -K eth0 gso on
ethtool -K eth0 tso onapt-get install dnsmasqiptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtusysctl -w net.ipv4.tcp_window_scaling=1sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216apt-get install ifenslavesysctl -w net.ipv6.conf.all.disable_ipv6=0sysctl -w net.ipv4.tcp_reordering=3ifconfig eth0 txqueuelen 10000xfs_fsr /dev/sda1fstrim -v /apt-get install zfsutils-linux
zpool create mypool /dev/sdamount -o remount,noatime,nodiratime /echo "fs.file-max = 500000" >> /etc/sysctl.conf
ulimit -n 500000echo '-1000' > /proc/$(pidof critical_process)/oom_score_adjcgcreate -g cpu,memory:mygroup
cgset -r cpu.shares=512 mygroup
cgset -r memory.limit_in_bytes=512M mygroupnpm install pm2@latest -g
pm2 start app.jsapt-get install cpulimit
cpulimit -e myapp -l 50sysctl -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=1echo 1000 > /proc/sys/kernel/timer_frequencyecho 1 > /sys/kernel/mm/ksm/runsysctl -w kernel.sem="250 32000 100 128"sysctl -w fs.inode-nr
sysctl -w fs.inode-stateecho 0 > /proc/sys/kernel/preemptinnodb_use_native_aio = 1
query_cache_size = 64M
query_cache_type = ON
mount -t tmpfs -o size=512M tmpfs /tmpLD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2apt-get install squidsed -i 's/^#LogLevel=info/LogLevel=error/' /etc/systemd/journald.confsudo sed -i -e '/home/s/\bdefaults\b/&,noatime/' /etc/fstabNote: 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.