Operations 38 min read

Master Linux System Optimization: Tools, Techniques, and Performance Tuning

This comprehensive guide explains how to identify and resolve Linux server performance bottlenecks by adjusting kernel parameters, optimizing CPU, memory, disk, and network settings, and using monitoring tools such as vmstat, mpstat, iostat, sar, top, ps, htop, pidstat, and strace to ensure stable and efficient operation.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux System Optimization: Tools, Techniques, and Performance Tuning

Introduction

Linux servers often run many applications, and under high load they may encounter performance bottlenecks such as high CPU utilization, insufficient memory, or disk I/O limits, leading to system lag or service interruptions. Adjusting kernel parameters and related components can improve performance and stability.

Two Aspects of Linux System Optimization

Hardware: adding memory, using enterprise SSDs, increasing bandwidth, etc.

Software: tuning kernel parameters, disk I/O, and resource allocation.

Software-Level Optimization Areas

Memory tuning: improve memory usage efficiency, reduce leaks and fragmentation.

Disk tuning: increase read/write speed and reliability.

CPU tuning: improve CPU utilization.

Network tuning: improve network performance and reduce latency.

Process and thread tuning: optimize scheduling and reduce contention.

Optimization Steps

Collect performance data with monitoring tools (e.g., vmstat, iostat, sar).

Trace specific applications and processes.

Analyze the data and adjust memory, disk, CPU, etc., accordingly.

Key System Performance Concepts

IOPS : Input/Output operations per second.

Throughput : Number of transactions processed per unit time.

Response Time : Time from request receipt to result.

Bandwidth : Data transfer speed.

Latency : Delay from request to response.

Bottleneck : Resource limiting overall performance.

Workload : Set of running applications or tasks.

Cache : Technique to improve performance.

CPU Cache : L1, L2, L3 caches stored on the CPU.

Memory Cache : Kernel-managed cache region.

Buffer : Temporary storage area for data.

Linux Resource Monitoring

Monitoring tools provide insight into system status:

1. vmstat

Shows memory, process, I/O, context switches, etc.

procs   r  b   swpd   free   buff  cache   si   so   bi   bo   in   cs   us  sy  id  wa  st

2. mpstat

Focuses on CPU usage per core, including %usr, %sys, %iowait, %idle, etc.

# Example output

3. iostat

Monitors disk I/O performance, showing read/write rates, await times, and utilization.

Device:            tps    kB_read/s    kB_wrtn/s    %util

4. sar

Collects historical performance data for deeper analysis.

5. top / htop

Real‑time view of processes, CPU, memory, and load.

6. ps

Lists processes with detailed information.

7. pidstat

Shows per‑process CPU and memory usage.

8. strace

Traces system calls of a process for debugging.

image
image

System Tuning Methods

1. Limiting and Controlling Process Resources

ulimit : Set limits on CPU time, virtual memory, open files, etc.

PAM : Authentication framework that can enforce resource limits.

cgroup : Kernel feature to isolate and limit CPU, memory, I/O for groups of processes.

2. CPU Optimization

Set CPU affinity with taskset -c 0,1 -p 1234 to bind processes to specific cores.

Adjust scheduler policies (CFS, deadline, noop) – requires kernel recompilation.

Modify time‑slice size – also requires kernel changes.

Tune CPU migration overhead – kernel recompilation needed.

3. Memory Optimization

Disable swap with swapoff -a or set /proc/sys/vm/swappiness to 0.

Adjust /proc/sys/vm/dirty_bytes to control dirty page thresholds.

Configure dirty page writeback intervals via vm.dirty_expire_centisecs and vm.dirty_writeback_centisecs.

Use tmpfs for fast in‑memory filesystems.

Enable huge pages by setting /proc/sys/vm/nr_hugepages and mounting hugetlbfs.

Manually reclaim dirty data with sync or adjust writeback settings.

Clear caches via echo 3 > /proc/sys/vm/drop_caches (files) or echo 1 > /proc/sys/vm/drop_caches (dentries).

4. Disk Optimization

Mount with noatime to reduce metadata writes.

Choose appropriate filesystem (ext4 for many small files, XFS for large files).

Adjust inode count during filesystem creation if many small files are expected.

Select disk scheduler (CFQ, deadline, noop) via /sys/block/<device>/queue/scheduler.

Set read‑ahead size with /sys/block/<device>/queue/read_ahead_kb.

Defragment ext4 with e4defrag or XFS with xfs_fsr.

image
image

5. Network Optimization

Increase TCP backlog and listen queue: echo 10000 > /proc/sys/net/ipv4/tcp_max_syn_backlog and echo 10000 > /proc/sys/net/core/somaxconn.

Enable TCP Fast Open: echo 2 > /proc/sys/net/ipv4/tcp_fastopen.

Select congestion control algorithm (e.g., cubic): echo cubic > /proc/sys/net/ipv4/tcp_congestion_control.

Increase socket buffers: echo 16777216 > /proc/sys/net/core/wmem_max and similar for rmem.

Disable IPv6 if not needed via net.ipv6.conf.all.disable_ipv6=1 in /etc/sysctl.conf.

Adjust TCP window scaling and buffer sizes in /etc/sysctl.conf.

Increase connection queue size with net.core.somaxconn.

image
image
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 optimizationResource ManagementServer Tuning
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.