Performance Tuning
This article covers commonly used performance monitoring tools and optimization techniques in Ubuntu 26.04 to help you get the most out of your hardware.
System Monitoring Tools
htop - Interactive Process Manager
# Install (usually pre-installed on Ubuntu 26.04)
sudo apt install htop
# Launch
htopCommon htop operations:
| Shortcut | Function |
|---|---|
F2 | Setup/Configuration |
F3 | Search process |
F4 | Filter processes |
F5 | Tree view |
F6 | Sort |
F9 | Send signal (kill process) |
F10 | Quit |
u | Filter by user |
M | Sort by memory |
P | Sort by CPU |
T | Sort by time |
Other Monitoring Tools
# top - basic process monitoring
top
# vmstat - virtual memory statistics
vmstat 1 5 # once per second, 5 times
# iostat - I/O statistics
sudo apt install sysstat
iostat -xz 1
# iotop - view per-process I/O
sudo apt install iotop
sudo iotop
# nmon - comprehensive performance monitoring
sudo apt install nmon
nmon
# glances - modern system monitoring
sudo apt install glances
glances
# btop - visually appealing resource monitor
sudo apt install btop
btopViewing System Resource Information
# CPU information
lscpu
cat /proc/cpuinfo | grep "model name" | head -1
# Memory information
free -h
cat /proc/meminfo
# Disk usage
df -h
# Load averages
uptime
cat /proc/loadavg
# Network connections
ss -tunaplCPU Optimization
CPU Frequency Management
# cpufrequtils is deprecated; use cpupower instead (provided by linux-tools)
sudo apt install linux-tools-common linux-tools-generic
# View current CPU frequency and governor
cpupower frequency-info
# View available frequency governors
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
# Set to performance mode
sudo cpupower frequency-set -g performance
# Set to power-saving mode
sudo cpupower frequency-set -g powersaveOn the desktop you can also use the higher-level power management tool power-profiles-daemon:
# List available power profiles
powerprofilesctl list
# Switch to performance mode
powerprofilesctl set performanceProcess Priority
# Use nice to start a process (-20 to 19, lower values = higher priority)
nice -n 10 /path/to/task.sh
# Change the priority of a running process
renice -n 5 -p PID
# Set real-time priority
sudo chrt -f 50 /path/to/realtime-task
# Pin a process to specific CPU cores
taskset -c 0,1 /path/to/task.shMemory Optimization
Swap Tuning
# View current swap usage
swapon --show
free -h
# View current swappiness value (default is 60)
cat /proc/sys/vm/swappinessswappiness parameter guide:
| Value | Use Case |
|---|---|
| 0-10 | Desktop systems / servers with ample memory, minimize swap usage |
| 30-40 | General server workloads |
| 60 | Default value |
| 80-100 | Memory-constrained systems, use swap aggressively |
# Temporarily change swappiness
sudo sysctl vm.swappiness=10
# Permanently change swappiness
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.d/99-performance.conf
sudo sysctl --systemOther Memory Parameters
# Cache pressure (default 100; lower values retain more directory and inode caches)
echo "vm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.d/99-performance.conf
# Dirty page writeback policy
echo "vm.dirty_ratio=15" | sudo tee -a /etc/sysctl.d/99-performance.conf
echo "vm.dirty_background_ratio=5" | sudo tee -a /etc/sysctl.d/99-performance.conf
# Apply all changes
sudo sysctl --systemClearing Cache
# Free page cache
sudo sync; echo 1 | sudo tee /proc/sys/vm/drop_caches
# Free dentry and inode cache
sudo sync; echo 2 | sudo tee /proc/sys/vm/drop_caches
# Free all caches
sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_cachesI/O Scheduler
Viewing and Changing the I/O Scheduler
# View current I/O scheduler
cat /sys/block/sda/queue/scheduler
# Example output: [mq-deadline] kyber bfq none
# Temporarily change
echo "bfq" | sudo tee /sys/block/sda/queue/schedulerI/O Scheduler Selection
| Scheduler | Use Case |
|---|---|
mq-deadline | General purpose, suitable for most HDDs and SSDs |
bfq | Desktop systems, provides better interactive responsiveness |
kyber | High-performance NVMe SSDs |
none | NVMe SSD direct access, lowest latency |
Persisting I/O Scheduler Settings
Create a udev rule:
sudo nano /etc/udev/rules.d/60-scheduler.rules# HDD uses mq-deadline
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="mq-deadline"
# SSD uses none or mq-deadline
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"
# NVMe uses none
ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="none"sudo udevadm control --reload-rulesSSD Optimization
Enabling TRIM
TRIM allows the operating system to inform the SSD which data blocks are no longer in use, helping maintain SSD performance and extend its lifespan.
# Check if the SSD supports TRIM
sudo hdparm -I /dev/sda | grep TRIM
# Manually run TRIM
sudo fstrim -v /
# Check the scheduled TRIM service
systemctl status fstrim.timer
# Enable scheduled TRIM (runs weekly)
sudo systemctl enable --now fstrim.timerSSD Optimization Options in fstab
# Recommended SSD mount options
UUID=xxxx / ext4 defaults,noatime,discard 0 1| Option | Description |
|---|---|
noatime | Do not record file access times, reduces writes |
discard | Real-time TRIM (or use fstrim.timer instead) |
commit=60 | Extend commit interval, reduces write frequency |
Reducing Unnecessary Disk Writes
# Mount /tmp to memory
# Add to /etc/fstab:
# tmpfs /tmp tmpfs defaults,noatime,size=2G 0 0
# Reduce journal writes
sudo nano /etc/systemd/journald.conf
# Set: Storage=volatile (memory only, lost after reboot)
# Or: SystemMaxUse=100M (limit journal size)Network Optimization
TCP Parameter Tuning
sudo nano /etc/sysctl.d/99-network.conf# TCP buffer sizes
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
# TCP connection optimization
net.ipv4.tcp_fastopen=3
net.ipv4.tcp_mtu_probing=1
net.ipv4.tcp_congestion_control=bbr
# Connection queue
net.core.somaxconn=65535
net.core.netdev_max_backlog=65535
# TIME_WAIT optimization
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_fin_timeout=15# Enable BBR congestion control
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.d/99-network.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.d/99-network.conf
sudo sysctl --system
# Verify BBR is active
sysctl net.ipv4.tcp_congestion_controlFilesystem Optimization
ext4 Optimization
# View filesystem parameters
sudo tune2fs -l /dev/sda2
# Reduce reserved space (default 5%, can be lowered for large partitions)
sudo tune2fs -m 1 /dev/sda2File Descriptor Limits
# View current limit
ulimit -n
# Temporarily increase the limit
ulimit -n 65535
# Permanently change
sudo nano /etc/security/limits.conf# /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535System-level:
echo "fs.file-max=2097152" | sudo tee -a /etc/sysctl.d/99-performance.conf
sudo sysctl --systemBoot Optimization
# Analyze boot time
systemd-analyze
# View boot time per service
systemd-analyze blame
# View critical boot path
systemd-analyze critical-chain
# Disable unnecessary services
sudo systemctl disable bluetooth.service # not using Bluetooth
sudo systemctl disable cups.service # not using printing
sudo systemctl disable ModemManager.service # not using modem
# Check boot log for errors
journalctl -b -p errPerformance Benchmarking
# Disk performance test
sudo apt install fio
# Sequential read test
fio --name=seqread --rw=read --bs=1M --size=1G --numjobs=1 --runtime=30
# Random read/write test
fio --name=randreadwrite --rw=randrw --bs=4k --size=1G --numjobs=4 --runtime=30
# Simple disk write speed test
dd if=/dev/zero of=/tmp/testfile bs=1M count=1024 oflag=direct
# Memory bandwidth test
sudo apt install sysbench
sysbench memory run
# CPU benchmark
sysbench cpu --threads=$(nproc) run
# Network performance test
sudo apt install iperf3
# Server: iperf3 -s
# Client: iperf3 -c server_ipLast updated on