sysctl is used to adjust kernel parameters at runtime to optimize Linux system performance. The answer is to improve the performance of specific workloads by placing network, memory and security-related parameters rationally. 1. Understand the basics of sysctl: Use sysctl to view or set the kernel parameters under /proc/sys, temporarily modify the command such as sudo sysctl net.core.rmem_max=16777216, permanent modification requires writing /etc/sysctl.conf or /etc/sysctl.d/ and executing sudo sysctl -p to take effect. 2. Network performance tuning: For high-traffic scenarios, increase the TCP buffer (such as net.core.rmem_max, tcp_rmem, etc.), enable tcp_window_scaling to improve throughput, adjust tcp_tw_reuse and fin_timeout to optimize connection reuse, and expand the local port range and connection queue (somaxconn, tcp_max_syn_backlog) to avoid resource exhaustion. 3. Memory and VM management: Reduce vm.swappiness to reduce the use of swap partitions, set dirty_ratio and dirty_background_ratio to control dirty page writeback frequency to balance performance and data security, and adjust vfs_cache_pressure to reduce file system cache pressure. 4. Security and performance trade-off: Decide whether to turn off tcp_timestamps to enhance security based on actual needs, enable tcp_syncookies to defend against SYN flood attacks, but avoid excessive limitations to lead to performance overhead. Finally, it is recommended to gradually test the changes, combine the monitoring effects of iperf, sar and other tools, record the reasons for adjusting parameters, and eliminate blindly applying other people's configurations. It should be optimized accurately based on actual workloads (such as network-intensive and memory-intensive). Correctly using a few key parameters can significantly improve system performance.
Linux performance tuning with sysctl
is all about adjusting kernel parameters at runtime to optimize system behavior for specific workloads—whether it's improving network throughput, reducing latency, or better memory management. Unlike recompiling the kernel or rebooting, sysctl
lets you make changes on the fly, and persist them across reboots with proper configuration.

Here's how to use sysctl
effectively for performance tuning, broken down into key areas.
1. Understanding sysctl
Basics
sysctl
is a tool that reads or sets kernel parameters exposed through the /proc/sys/
virtual filesystem. These parameters control various aspects of the Linux kernel's behavior.

-
View current settings:
sysctl net.core.rmem_max
List all settings:
sysctl -a
Set a parameter temporarily:
sudo sysctl net.core.rmem_max=16777216
Make changes permanent: Add entries to
/etc/sysctl.conf
or a dedicated file in/etc/sysctl.d/
:net.core.rmem_max = 16777216
After editing config files, apply with:
sudo sysctl -p
2. Network Performance Tuning
For servers handling high network traffic (eg, web servers, load balancers), tweaking network-related parameters can significantly improve throughput and responsiveness.
Key Parameters to Adjust:
Increase TCP buffer sizes: Larger buffers help with high-bandwidth, high-latency networks (eg, WANs).
net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 65536 16777216
Enable TCP window scaling: Allows larger window sizes for better throughput.
net.ipv4.tcp_window_scaling = 1
Reduce TIME_WAIT socket reuse: Useful for servers handling many short-lived connections.
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 30
Increase connection tracking and port range: Prevents running out of ports under heavy load.
net.ipv4.ip_local_port_range = 1024 65535 net.core.somaxconn = 65535 net.ipv4.tcp_max_syn_backlog = 65535
?? Be careful with
tcp_tw_reuse
in NAT environments—it can cause issues with some clients.
3. Memory and VM Management
Tuning virtual memory behavior can reduce latency and prevent stalls due to paging.
Useful Memory-Related Settings:
Reduce swappiness: Minimize swapping to avoid performance hits on systems with sufficient RAM.
vm.swappiness = 10
Control dirty page flushing: Adjust how often dirty pages are written to disk. Higher values delay writes, improving throughput but increasing risk of data loss on crash.
vm.dirty_ratio = 15 vm.dirty_background_ratio = 5
Optimize page reclaim: For memory-heavy applications, tune how aggressively the kernel reclaims memory.
vm.vfs_cache_pressure = 50
This reduces pressure on inode and dentry caches, which can help systems with heavy file operations.
4. Security vs. Performance Trade-offs
Some secure defaults may limit performance. Evaluate your threat model before tuning.
Disable TCP timestamps (security vs. performance): Can help mitigate some attacks but may affect RTT calculations.
net.ipv4.tcp_timestamps = 0
Enable SYN cookies for flood protection: Useful under DoS conditions.
net.ipv4.tcp_syncookies = 1
But avoid over-locking down unless necessary—every check adds overhead.
Final Tips
- Test changes incrementally: Apply one change at a time and measure impact using tools like
iperf
,netperf
, orhtop
. - Monitor before and after: Use
sar
,nstat
, ordstat
to observe effects. - Document your changes: Keep a record of why a parameter was tuned—especially in production.
- Avoid copy-pasting random sysctl configs: What works for a CDN node may hurt a database server.
Basically, sysctl
is a powerful lever for performance tuning, but it requires understanding what each parameter does. Start with your workload profile—network-heavy, memory-intensive, low-latency—and adjust accordingly. Not all knobs need turning, but the right few can make a real difference.
The above is the detailed content of Linux Performance Tuning with `sysctl`. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

Clear Linux OS is the ideal operating system for people – ahem system admins – who want to have a minimal, secure, and reliable Linux distribution. It is optimized for the Intel architecture, which means that running Clear Linux OS on AMD sys

The key steps for creating a self-signed SSL certificate are as follows: 1. Generate the private key, use the command opensslgenrsa-outselfsigned.key2048 to generate a 2048-bit RSA private key file, optional parameter -aes256 to achieve password protection; 2. Create a certificate request (CSR), run opensslreq-new-keyselfsigned.key-outselfsigned.csr and fill in the relevant information, especially the "CommonName" field; 3. Generate the certificate by self-signed, and use opensslx509-req-days365-inselfsigned.csr-signk

Decompress the .zip file on Windows, you can right-click to select "Extract All", while the .tar.gz file needs to use tools such as 7-Zip or WinRAR; on macOS and Linux, the .zip file can be double-clicked or unzip commanded, and the .tar.gz file can be decompressed by tar command or double-clicked directly. The specific steps are: 1. Windows processing.zip file: right-click → "Extract All"; 2. Windows processing.tar.gz file: Install third-party tools → right-click to decompress; 3. macOS/Linux processing.zip file: double-click or run unzipfilename.zip; 4. macOS/Linux processing.tar

Firefox browser is the default browser for most modern Linux distributions such as Ubuntu, Mint, and Fedora. Initially, its performance might be impressive, however, with the passage of time, you might notice that your browser is not as fast and resp

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.
