Redis provides powerful in-memory data storage capabilities, making it essential to monitor and understand its memory usage. The INFO MEMORY
command offers valuable insights into how Redis allocates and manages memory. In this blog, we'll break down the meaning of each metric in the output of INFO MEMORY
.
Sample Output of INFO MEMORY
127.0.0.1:6379> info memory
# Memory
used_memory:880824
used_memory_human:860.18K
used_memory_rss:6557696
used_memory_rss_human:6.25M
used_memory_peak:3272840
used_memory_peak_human:3.12M
used_memory_peak_perc:26.91%
used_memory_overhead:830784
used_memory_startup:809864
used_memory_dataset:50040
used_memory_dataset_perc:70.52%
allocator_allocated:1123280
allocator_active:1470464
allocator_resident:4055040
total_system_memory:6209691648
total_system_memory_human:5.78G
used_memory_lua:43008
used_memory_lua_human:42.00K
used_memory_scripts:200
used_memory_scripts_human:200B
number_of_cached_scripts:1
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.31
allocator_frag_bytes:347184
allocator_rss_ratio:2.76
allocator_rss_bytes:2584576
rss_overhead_ratio:1.62
rss_overhead_bytes:2502656
mem_fragmentation_ratio:7.81
mem_fragmentation_bytes:5717896
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:20504
mem_aof_buffer:0
mem_allocator:jemalloc-5.2.1
active_defrag_running:0
lazyfree_pending_objects:0
Breaking Down the Metrics
1. General Memory Usage
- ``** (880824 bytes)**: The total memory used by Redis, including keys, values, and internal data structures.
- ``** (860.18K)**: A human-readable representation of
used_memory
. - ``** (6557696 bytes or 6.25MB)**: The actual physical memory used by Redis, which may be higher than
used_memory
due to fragmentation. - ``** (3272840 bytes or 3.12MB)**: The highest memory usage recorded by Redis.
- ``** (26.91%)**: The percentage of peak memory usage compared to the current memory usage.
2. Memory Overhead and Dataset
- ``** (830784 bytes)**: Memory consumed by Redis for bookkeeping (e.g., managing data structures, clients, replication, etc.).
- ``** (809864 bytes)**: Memory Redis uses at startup before loading any data.
- ``** (50040 bytes)**: The actual memory occupied by user data.
- ``** (70.52%)**: Percentage of total used memory allocated to dataset storage.
3. Memory Allocation Details
- ``** (1123280 bytes)**: Memory allocated by the Redis memory allocator.
- ``** (1470464 bytes)**: Memory actively used by the allocator.
- ``** (4055040 bytes)**: The amount of physical memory allocated and not yet released.
- ``** (jemalloc-5.2.1)**: The memory allocator being used (Jemalloc in this case, known for reducing fragmentation).
4. System Memory Information
- ``** (6209691648 bytes or 5.78GB)**: The total memory available in the system.
- ``** (0 bytes)**: The configured maximum memory limit for Redis (0 means unlimited).
- ``** (noeviction)**: Redis' policy for handling memory exhaustion (no eviction means keys are not removed automatically).
5. Lua and Scripts Memory Usage
- ``** (43008 bytes or 42.00K)**: Memory used by Lua scripts.
- ``** (200 bytes)**: Memory used by cached scripts.
- ``** (1)**: The number of scripts stored in the cache.
6. Memory Fragmentation Analysis
- ``** (1.31)**: Ratio of
allocator_active
to allocator_allocated
. A value >1 indicates fragmentation. - ``** (347184 bytes)**: The amount of memory fragmentation in bytes.
- ``** (2.76)**: Ratio of
allocator_resident
to allocator_active
, showing how much memory is mapped but not used. - ``** (2584576 bytes)**: Memory wasted due to RSS fragmentation.
- ``** (7.81)**: The overall fragmentation ratio. A high value (>2) suggests excessive fragmentation.
- ``** (5717896 bytes)**: Total memory lost due to fragmentation.
7. Client and Replication Memory
- ``** (20504 bytes)**: Memory used by connected clients.
- ``** (0 bytes)**: Memory used by Redis replicas.
- ``** (0 bytes)**: Memory allocated for replication backlog.
- ``** (0 bytes)**: Memory used by the AOF buffer.
8. Defragmentation and Lazy Freeing
- ``** (0)**: Indicates whether active memory defragmentation is running.
- ``** (0)**: Number of objects pending lazy deletion.
Key Takeaways
- Memory Usage vs. RSS:
used_memory
represents logical usage, while used_memory_rss
shows actual system memory usage, which may be higher due to fragmentation. - Memory Fragmentation: High
mem_fragmentation_ratio
suggests Redis may benefit from memory defragmentation. - Memory Overhead: Redis uses memory not just for storing data but also for metadata and internal structures.
- Optimization: Consider setting
maxmemory
and a proper maxmemory_policy
to manage Redis' memory efficiently.
Understanding Redis memory usage helps optimize performance and prevent out-of-memory issues. Regularly monitoring INFO MEMORY
ensures Redis operates smoothly within your infrastructure's constraints.