Skip to content

Memory Accounting & Capacity Sizing

When migrating from a per-object heap allocator (stock Redis 7.2 or Valkey) to Engula's compact block storage kernel, the most common operational pitfall is applying legacy allocator-byte or static fragmentation heuristics to packed memory blocks. This guide explains how to read physical vs. logical memory metrics on Engula 2.3.0, how eviction utilization is calculated, and how to size host and Kubernetes container memory limits safely.


1. Core Memory Metric Reference

On Engula, OS-level physical resident footprint and intra-block payload utilization are reported across two complementary commands:

Command & Field Physical / Logical Meaning Production Accounting Rule
INFO memory → used_memory_rss Actual OS physical resident memory (RSS) mapped by the engula-server process Authoritative metric for RAM savings, shard consolidation ratios, and host memory utilization
INFO memory → used_memory Allocator-accounted bytes (includes active mutable-block headroom and tombstoned records awaiting background compaction) Governs maxmemory eviction alongside mem_not_counted_for_evict; does not equal net compressed payload bytes
INFO memory → mem_not_counted_for_evict Replication backlog and replica output buffers excluded from data eviction quotas Subtracted from used_memory when computing effective eviction utilization
ENGULA INFO memory → engula_arena_block_bytes Total byte footprint currently held by compact blocks (including uncompacted deletion holes) Tracks compact block-pool footprint; pair with engula_recyclable_bytes to gauge reclaimable holes
ENGULA INFO memory → engula_arena_record_bytes Net compressed byte sum of all live records packed inside compact blocks Net record bytes divided by block bytes gives live block utilization (typically 85%–99% at steady state)
ENGULA INFO memory → engula_arena_records Total live compact records (each field in a large Hash and each member in a large Set counts as a record) Expected to exceed top-level DBSIZE on collection-heavy workloads

Inspect physical RSS alongside compact block utilization on any running node:

1redis-cli INFO memory | grep -E '^(used_memory_human|used_memory_rss_human|maxmemory_human|mem_not_counted_for_evict):'
2redis-cli ENGULA INFO memory evict

2. Tuning Legacy Fragmentation Alerts and Per-Key Sizing Rules

Before pointing existing Prometheus or Grafana alert rules at Engula nodes, update these two stock heuristics (full alert thresholds in ENGULA INFO & Monitoring):

  1. Retire or raise static fragmentation alerts above 1.4:
    • mem_fragmentation_ratio continues reporting physical RSS divided by allocator-accounted memory. Because Engula manages compressed blocks in a dedicated arena with an independent ~1,000 ms OS page-decay cadence and pre-allocated writable block buffers, healthy steady-state ratios typically sit near 1.55 (and fluctuate between 1.7 and 2.5 under heavy variable-length overwrites)—even while total used_memory_rss remains 40%–75% lower than stock Redis or Valkey.
    • To monitor reclaimable intra-block holes on Engula, track engula_mem_defrag_pressure_ratio (0–1 pressure gauge) and engula_recyclable_bytes under ENGULA INFO evict, and ignore per-object heap warnings from MEMORY DOCTOR.
  2. Avoid extrapolating shard capacity from sampled per-key memory usage:
    • For wire compatibility, MEMORY USAGE <key> estimates the uncompressed logical object size of a key (for example, a 1 KB string compressed down to 300 bytes inside a block still reports ~1,304 bytes). Always size and audit shards using used_memory_rss.

3. Effective Eviction Utilization & Predictive Eviction

Whenever a non-zero maxmemory ceiling and eviction policy (such as allkeys-lru or volatile-lfu) are configured, the kernel evaluates eviction thresholds against effective logical memory:

1Effective Eviction Utilization = (used_memory - mem_not_counted_for_evict) / maxmemory

To prevent burst writes from slamming into the hard ceiling and causing synchronous foreground stalls, Engula 2.3.0 coordinates two mechanisms:

  • Memory usage pressure ratio (engula_mem_usage_pressure_ratio): Remains 0 below 80% of the ceiling and ramps linearly toward 1.0 between 80% and 100%, accelerating background sparse-block compaction so deleted space is reclaimed before live keys are evicted.
  • 10-second EWMA predictive eviction (engula-evict-forecast-lead-ms): Defaults to 10,000 ms, projecting net memory growth rate via exponentially weighted moving averages and initiating smooth incremental eviction whenever the ceiling is projected to be reached within 10 seconds. Keep enable-debug-command no in production (enabling debug commands automatically disables predictive eviction).

4. Host & Kubernetes Container Memory Sizing Formula

Whereas stock Redis and Valkey deployments often reserve 70%–100% extra RAM above steady-state RSS to survive background snapshot Copy-on-Write (CoW) spikes, Engula's progressive per-block page release bounds peak BGSAVE CoW growth under heavy random writes to approximately +14%.

Step-by-Step Shard Memory Sizing

  1. Measure steady-state physical memory: Run ValueSight offline against a masked dump.rdb backup, or attach a read-only shadow replica behind a live primary for one business cycle to measure steady-state used_memory_rss.
  2. Configure maxmemory: Set the ceiling above observed allocator memory with 15%–25% headroom for organic dataset growth (during live Cluster slot consolidation, reserve 25%–30% transient headroom on destination shards so incoming RESTORE-ASKING bursts never outpace initial background compression).
  3. Size container and VM memory limits: Account for the +14% snapshot CoW window, repl-backlog-size (for example 512 MB), replica/client output buffers, and OS page headroom using:
1Container / Host Memory Limit >= max(1.30 × maxmemory, 1.25 × used_memory_rss + repl_backlog_size + peak_replica_output_buffer)

For a production Kubernetes StatefulSet shard configured with maxmemory 32gb and repl-backlog-size 512mb:

  • Setting both Pod memory requests and limits to 42Gi–44Gi (Guaranteed QoS class) comfortably absorbs steady-state resident memory, the +14% CoW window, and cross-DC replication buffers without risking Linux OOM-Killer eviction.
  • Always pair disable-thp yes in engula.conf with disabling OS Transparent Huge Pages on the host (see Configuration Guide and Go-Live Checklist) so 2 MB huge pages never amplify Copy-on-Write page faults.