Databases 14 min read

7 Essential Linux Tweaks to Supercharge Redis Performance

This guide explains seven critical Linux operating‑system settings—memory overcommit, swappiness, Transparent Huge Pages, OOM killer, NTP synchronization, ulimit, and TCP backlog—that together ensure Redis runs reliably and at peak speed.

Programmer DD
Programmer DD
Programmer DD
7 Essential Linux Tweaks to Supercharge Redis Performance

Redis developers often focus on Redis‑specific configuration, but operating‑system settings are crucial for stable, high‑performance operation.

1. Memory allocation control

vm.overcommit_memory

When vm.overcommit_memory is set to 0, the kernel may reject memory allocation, causing fork failures during background saves. Setting it to 1 allows overcommit and prevents these errors.

# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect.

Check the current value: cat /proc/sys/vm/overcommit_memory Set the value:

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1

Configure a reasonable maxmemory and keep 20‑30% of RAM free.

Centralize AOF rewrite and RDB bgsave management.

Set vm.overcommit_memory=1 to avoid fork failures.

2. Swappiness

Parameter meaning

Swappiness (0‑100) controls how aggressively Linux uses swap. Lower values keep data in RAM; higher values increase swap usage. The default is 60. For Redis, values 0‑1 are recommended on kernels >3.5, otherwise 0.

Configuration

echo {bestvalue} > /proc/sys/vm/swappiness

Persist across reboots:

echo vm.swappiness={bestvalue} >> /etc/sysctl.conf

Monitoring swap

Use free -m to view total swap usage, vmstat 1 for real‑time swap activity, and inspect /proc/<pid>/smaps for per‑process swap consumption.

3. Transparent Huge Pages (THP)

THP can increase latency and memory usage for Redis. Disable it:

echo never > /sys/kernel/mm/transparent_hugepage/enabled

Persist the setting by adding the command to /etc/rc.local. On some distributions the path is /sys/kernel/mm/redhat_transparent_hugepage/enabled.

4. OOM killer

Adjust oom_adj for Redis processes to a low value (e.g., -17) to reduce the chance of being killed when memory is scarce.

for redis_pid in $(pgrep -f "redis-server"); do
  echo -17 > /proc/${redis_pid}/oom_adj
done

5. NTP

Synchronize system clocks to avoid time drift between Redis nodes, which simplifies troubleshooting of Sentinel or Cluster events.

0 * * * * /usr/sbin/ntpdate ntp.xx.com > /dev/null 2>&1
NTP synchronization diagram
NTP synchronization diagram

6. ulimit

Increase the open‑files limit to accommodate maxclients. For example, set ulimit -Sn 10032 or edit /etc/security/limits.conf to raise the soft limit.

7. TCP backlog

Ensure /proc/sys/net/core/somaxconn is at least the Redis tcp-backlog (default 511). If it is lower, Redis will emit a warning.

echo 511 > /proc/sys/net/core/somaxconn
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.

performanceMemory ManagementdatabaseredisOS Tuning
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

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.