Redis VPS Requirements: maxmemory, Eviction Policies & Persistence Architecture

A production guide to sizing RAM and configuring maxmemory, eviction algorithms, and RDB/AOF persistence for high-throughput Redis instances on KVM VPS.

Deploying Redis on a Linux VPS provides microsecond-level data caching, session management, and pub/sub message brokering for high-performance applications. Because Redis operates primarily as an in-memory datastore, managing system memory, eviction algorithms, and disk persistence mechanisms requires careful architectural planning. Misconfiguring the maxmemory ceiling or selecting an eviction policy incompatible with your workload can lead to unexpected key loss or disruptive Out-Of-Memory (OOM) crashes.

The maxmemory Parameter and Buffer Headroom Mechanics

The maxmemory directive in redis.conf establishes the upper ceiling of memory Redis is permitted to allocate for user datasets. Setting maxmemory to 100% of your VPS physical RAM is a critical configuration error.

According to official Redis documentation, internal operational buffers, including client output buffers, replication backlog streams, and Append Only File (AOF) rewrite buffers, are not counted toward the maxmemory limit. If buffer allocations were included within the maxmemory calculation, evicting keys to free up memory would generate replication stream updates that immediately refill those buffers, triggering a feedback loop of continuous key evictions.

Furthermore, background persistence operations, such as RDB snapshots via bgsave or AOF compaction via bgrewriteaof, rely on the Linux kernel's fork() system call. During a fork, the operating system utilizes Copy-on-Write (CoW) page duplication. If your application sustains heavy write traffic while a background save occurs, memory consumption will increase as modified memory pages are copied. Therefore, production guidelines recommend setting maxmemory to approximately 65% to 75% of total physical system RAM, reserving the remaining memory for replication buffers, OS processes, and CoW page overhead.

Selecting the Right Eviction Policy: Caching vs State Datastores

When dataset volume reaches the configured maxmemory ceiling, Redis applies the maxmemory-policy algorithm to determine how subsequent write operations are handled:

  • noeviction (Default): When the memory limit is reached, Redis returns an error (OOM command not allowed when used memory > 'maxmemory') on incoming write commands while continuing to serve read requests. This is the mandatory policy when Redis is used as a primary state store, queue broker, or persistent database, preventing automated data deletion.
  • allkeys-lru / allkeys-lfu: Evaluates all keys across the entire database, evicting the least recently used (LRU) or least frequently used (LFU) keys regardless of whether an expiration (TTL) timestamp is set. These policies are ideal when Redis operates strictly as a transient cache backed by a persistent relational database like PostgreSQL or MySQL.
  • volatile-lru / volatile-lfu / volatile-ttl: Restricts key eviction exclusively to keys that have an explicit expiration time configured via EXPIRE. Keys without a TTL are protected from eviction. This policy suits hybrid environments where temporary session tokens coexist with permanent configuration metadata.
  • allkeys-random / volatile-random: Evicts keys randomly across all keys or volatile keys, typically used only for specific benchmarking scenarios.

Persistence Engineering: RDB Snapshots vs AOF Logs

Redis offers two distinct persistence engines to safeguard data across server reboots:

  • RDB (Redis Database Snapshots): RDB generates compact, point-in-time binary snapshots of the entire dataset at configured intervals (e.g., save 900 1). While RDB maximizes restart speeds and minimizes disk space usage, any writes that occur between snapshots are lost if an unexpected system failure occurs.
  • AOF (Append Only File): AOF logs every write operation received by the server to an append-only log file. Configured with appendfsync everysec, AOF balances high write throughput with durability, ensuring that at most one second of write activity is at risk during a power loss.

For mission-critical production deployments, combine both engines: use AOF with appendfsync everysec for durability, alongside daily RDB snapshots for off-site backup archiving.

Linux Kernel Memory Tuning for Redis

To ensure deterministic memory handling during background persistence forks, configure the Linux kernel overcommit memory setting in /etc/sysctl.conf:

# Enable memory overcommit to prevent fork() allocation failures
vm.overcommit_memory = 1

# Disable transparent huge pages (THP) to eliminate latency spikes during CoW
echo never > /sys/kernel/mm/transparent_hugepage/enabled

Transparent Huge Pages (THP) must be disabled. When THP is active, the Linux kernel duplicates 2 MB memory pages during Copy-on-Write forks rather than standard 4 KB pages, causing significant memory bloat and write latency spikes.

Redis VPS Sizing Reference Table

Use Case Target Dataset Size Recommended VPS Allocation Configured maxmemory
Application Session Cache Up to 2 GB Data KVM VPS: 2 vCPU, 4 GB RAM, RAID NVMe maxmemory 2.8gb (allkeys-lru)
High-Throughput API Caching Tier Up to 6 GB Data KVM VPS: 4 vCPU, 8 GB RAM, RAID NVMe maxmemory 5.5gb (allkeys-lfu)
Persistent Queue & Analytics Datastore Up to 24 GB Data KVM VPS: 8 vCPU, 32 GB RAM, RAID NVMe maxmemory 22gb (noeviction + AOF)

StreamData Networks delivers KVM Cloud VPS instances equipped with enterprise RAID NVMe storage arrays and flexible RAM tiers from 1 GB to 128 GB, designed for high-throughput database and caching architectures. Explore virtual server tiers on KVM VPS, evaluate bare-metal hosting on Dedicated Servers, or review network connectivity options via StreamData Company Overview.


Sources