Skip to Content
DocsOperationsSystem AdministrationPerformance Tuning

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 htop

Common htop operations:

ShortcutFunction
F2Setup/Configuration
F3Search process
F4Filter processes
F5Tree view
F6Sort
F9Send signal (kill process)
F10Quit
uFilter by user
MSort by memory
PSort by CPU
TSort 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 btop

Viewing 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 -tunapl

CPU 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 powersave

On 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 performance

Process 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.sh

Memory Optimization

Swap Tuning

# View current swap usage swapon --show free -h # View current swappiness value (default is 60) cat /proc/sys/vm/swappiness

swappiness parameter guide:

ValueUse Case
0-10Desktop systems / servers with ample memory, minimize swap usage
30-40General server workloads
60Default value
80-100Memory-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 --system

Other 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 --system

Clearing 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_caches

I/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/scheduler

I/O Scheduler Selection

SchedulerUse Case
mq-deadlineGeneral purpose, suitable for most HDDs and SSDs
bfqDesktop systems, provides better interactive responsiveness
kyberHigh-performance NVMe SSDs
noneNVMe 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-rules

SSD 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.timer

SSD Optimization Options in fstab

# Recommended SSD mount options UUID=xxxx / ext4 defaults,noatime,discard 0 1
OptionDescription
noatimeDo not record file access times, reduces writes
discardReal-time TRIM (or use fstrim.timer instead)
commit=60Extend 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_control

Filesystem 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/sda2

File 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 65535

System-level:

echo "fs.file-max=2097152" | sudo tee -a /etc/sysctl.d/99-performance.conf sudo sysctl --system

Boot 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 err

Performance 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_ip
Last updated on