Databases 6 min read

How to Expand Redis Memory on Linux: A Step‑by‑Step Guide

This article provides a detailed, practical guide for increasing Redis memory on Linux by adjusting Redis configuration, expanding system swap space, tuning kernel overcommit settings, and monitoring usage with command‑line tools.

Java Architecture Stack
Java Architecture Stack
Java Architecture Stack
How to Expand Redis Memory on Linux: A Step‑by‑Step Guide

1. Adjust Redis Configuration

Edit the Redis configuration file (usually /etc/redis/redis.conf or /usr/local/etc/redis/redis.conf) and set the maxmemory directive to the desired limit, e.g., maxmemory 4gb. Choose an appropriate eviction policy with maxmemory-policy, such as allkeys-lru or volatile-lru. Restart Redis to apply changes:

sudo vim /etc/redis/redis.conf
maxmemory 4gb
maxmemory-policy allkeys-lru
sudo systemctl restart redis

2. Expand System Memory and Swap

When physical RAM is insufficient, create and enable a swap file to provide additional virtual memory.

# Create a 4 GB swap file
sudo fallocate -l 4G /swapfile
# If fallocate is unavailable, use dd
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
# Secure the file
sudo chmod 600 /swapfile
# Set up swap area
sudo mkswap /swapfile
# Enable swap
sudo swapon /swapfile
# Verify
swapon --show
free -h
# Persist across reboots by adding to /etc/fstab
sudo vim /etc/fstab
# Append the following line
/swapfile none swap sw 0 0

3. Tune Linux Overcommit Memory

Modify the kernel overcommit policy to allow the system to allocate more memory than physically available.

# Check current setting
cat /proc/sys/vm/overcommit_memory
# Set to 1 (always overcommit)
sudo sysctl vm.overcommit_memory=1
# Make it permanent
sudo vim /etc/sysctl.conf
# Add or modify the line
vm.overcommit_memory = 1

4. Monitor Redis Memory Usage

Use Redis CLI and standard Linux tools to observe memory consumption.

# Redis memory info
redis-cli info memory
# System memory overview
top
htop
free -h

5. Summary

Increase maxmemory in redis.conf and select a suitable eviction policy.

Add swap space to extend virtual memory when physical RAM is limited.

Adjust /proc/sys/vm/overcommit_memory to allow aggressive allocation.

Continuously monitor Redis and system memory with redis-cli, top / htop, and free.

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.

memory managementdatabaseRedisPerformance TuningLinux
Java Architecture Stack
Written by

Java Architecture Stack

Dedicated to original, practical tech insights—from skill advancement to architecture, front‑end to back‑end, the full‑stack path, with Wei Ge guiding you.

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.