Lazyfree-lazy-eviction configured with allkeys-lru policy
0 reputation · 30 Apr 2025, 05:53 UTC
0 reputation · 30 Apr 2025, 05:53 UTC
When using Redis with the lazyfree-lazy-eviction option enabled, the server attempts to evict keys asynchronously to reduce latency spikes during memory pressure. The interaction of this setting with the allkeys-lru eviction policy is not fully documented, leaving administrators unsure whether asynchronous eviction provides the same latency guarantees as the synchronous LRU eviction that occurs when lazyfree-lazy-eviction is disabled.
The goal is to understand if enabling lazyfree-lazy-eviction under allkeys-lru still ensures that eviction decisions are made off the main thread without blocking command processing, and whether any edge cases could cause delayed reclamation or temporary memory growth under heavy write loads.
Specifically:
lazyfree-lazy-eviction guarantee that eviction of LRU‑selected keys happens asynchronously when the policy is allkeys-lru?allkeys-lru could still produce latency spikes?30275 reputation · 30 Apr 2025, 08:37 UTC
When lazyfree-lazy-eviction is set to yes and the maxmemory-policy is allkeys-lru, Redis still performs the LRU candidate selection on the main thread, but the actual memory deallocation of the chosen key is handed to a background lazyfree thread. This guarantees that the command processing path is never blocked by the free operation, while the eviction decision remains deterministic.
lazyfree-lazy-eviction is enabled, the key is queued for the lazyfree thread; the main thread immediately continues.lazyfree_pending_objects to grow. While the queue is full, the memory used by evicted keys is retained, so used_memory may stay above the threshold and trigger another eviction cycle, briefly increasing latency.The lazyfree-lazy-eviction directive was introduced in Redis 4.0 (released 2018). The documented behaviour described above applies to Redis 4.0 and later. Earlier releases do not support lazyfree.
CONFIG GET lazyfree-lazy-eviction
CONFIG GET maxmemory-policy
INFO memory
# look for evicted_keys and lazyfree_pending_objects
LATENCY DOCTOR
Check that spikes diminish when the memory limit is hit under this configuration.Use comments to ask for clarification. Post a solution as an answer.
30,275 reputation · 30 Apr 2025, 08:30 UTC
When lazyfree-lazy-eviction is enabled under allkeys-lru, the LRU candidate is chosen on the main thread, but the actual free operation is handed to a lazyfree worker. This keeps command handling non‑blocking, but the main thread will still block if the lazyfree queue is full and Redis must wait for space to reclaim memory.
maxmemory, momentarily raising latency.These behaviors are documented from Redis 4.0 onward, with refinements in 6.x to better handle queue contention.