Operations 35 min read

Master Linux Performance: Proven Tips to Boost Speed and Stability

This comprehensive guide explains how to identify and resolve common Linux performance bottlenecks—covering key metrics, hardware upgrades, kernel parameter tuning, process and memory management, and network optimization—while providing practical commands, code examples, and step‑by‑step troubleshooting techniques to keep servers and desktops running smoothly.

Deepin Linux
Deepin Linux
Deepin Linux
Master Linux Performance: Proven Tips to Boost Speed and Stability

1. Linux Performance Issues

Performance optimization is crucial for Linux systems, much like regular maintenance for a car. Over time, hardware aging, software bugs, misconfigurations, and load changes degrade performance.

1.1 Performance Metrics

Throughput : Amount of work done per unit time (e.g., HTTP requests per second or disk I/O rate). Higher throughput means higher processing capacity.

Latency : Time from request to response. Lower latency improves user experience.

CPU Utilization : Percentage of CPU time spent on work. Excessive utilization can cause slow responses.

Memory Utilization : Ratio of used memory to total memory. High utilization may trigger swapping, drastically reducing performance.

1.2 Where to Find Problems

Common bottlenecks include:

CPU Bottleneck : High load average, process contention, frequent context switches.

Memory Bottleneck : Memory leaks, excessive swapping.

Disk I/O Bottleneck : Slow reads/writes, high disk utilization.

Network Bottleneck : Insufficient bandwidth, high latency.

2. Hardware Optimization: Giving Linux a “Powerful Engine”

2.1 CPU – Core Driving Force

Select CPUs based on workload: many cores for parallel tasks (big data, distributed computing) and high clock speed for latency‑sensitive tasks (high‑frequency trading, scientific simulation). Optimize code for cache friendliness, e.g., access arrays row‑major to improve cache hits. Use cpufreq to adjust frequency governors (e.g., ondemand).

2.2 Memory – High‑Speed Channel

Increase physical RAM for memory‑intensive services. Employ compression technologies like KSM and zRAM to improve utilization. Periodically drop caches with echo 3 > /proc/sys/vm/drop_caches and tune vm.swappiness to control swap aggressiveness.

2.3 Storage – Stable Foundation

Replace HDDs with SSDs for faster I/O. Use RAID configurations (RAID 5 for redundancy with moderate performance, RAID 10 for high performance and safety) according to workload.

2.4 Network – Connecting the World

Upgrade to 1 GbE or 10 GbE NICs for higher bandwidth. Configure QoS to prioritize critical traffic such as video conferencing.

3. Software Optimization: Injecting “Intelligent Soul”

3.1 Kernel Parameter Tuning

Key parameters:

vm.dirty_background_ratio and vm.dirty_ratio : Control when dirty pages are flushed to disk. Example adjustment:

vm.dirty_background_ratio = 15
vm.dirty_ratio = 30

Apply with sudo sysctl -p.

kernel.shmmax and kernel.shmall : Define maximum shared memory segment size and total shared memory pages. Set to 50‑75% of physical RAM for database workloads.

Disable unnecessary modules (e.g., Bluetooth) using lsmod and rmmod, and blacklist them in /etc/modprobe.d/.

3.2 Process and Resource Management

Adjust process priority with nice (at start) or renice (running processes). Example to lower priority of a video‑transcoding job: nice -n 10 ffmpeg -i input.mp4 output.mp4 Use cgroups to limit resources, e.g., memory limit of 1 GB:

sudo mkdir /sys/fs/cgroup/memory/video_process
sudo sh -c 'echo 1073741824 > /sys/fs/cgroup/memory/video_process/memory.limit_in_bytes'
sudo sh -c 'echo 1234 > /sys/fs/cgroup/memory/video_process/tasks'

3.3 Memory Management

Adjust vm.swappiness (0‑100) to control swap usage. Typical values: 10 for desktops, 1‑10 for database servers. View and set with:

cat /proc/sys/vm/swappiness
sudo sysctl vm.swappiness=10

Enable Transparent Huge Pages (THP) when beneficial: cat /sys/kernel/mm/transparent_hugepage/enabled Configure via GRUB if needed.

3.4 Network Optimization

Application‑level: use epoll or asynchronous I/O, keep‑alive connections, caching, compression (gzip), and DNS caching (dnsmasq). Socket‑level: tune buffers ( net.core.rmem_max, net.core.wmem_max).

4. Hands‑On Practice: Turning Theory into Reality

4.1 Simulating Performance Scenarios

High‑concurrency load : Use Apache JMeter to generate 100 threads with 1000 requests each.

Memory leak : C program that repeatedly allocates 1 MB without freeing.

#include <stdio.h>
#include <stdlib.h>
int main() {
    while (1) {
        char *ptr = (char *)malloc(1024 * 1024);
        if (!ptr) { perror("malloc failed"); return 1; }
    }
    return 0;
}

Disk I/O stress : Continuous dd reads/writes on a 1 GB file.

4.2 Performance Analysis

Use top / htop for real‑time CPU/memory, vmstat for I/O and swap stats, and sar for historical data.

4.3 Optimization Implementation and Verification

After locating bottlenecks, apply the relevant optimizations described in sections 2 and 3, then re‑run the tests to verify improvements such as reduced response time, increased throughput, and lower resource utilization.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

System optimizationperformance tuningLinux
Deepin Linux
Written by

Deepin Linux

Research areas: Windows & Linux platforms, C/C++ backend development, embedded systems and Linux kernel, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.