I am running a very simple standalone redis 5.0 instance on a VM. There is not very much memory consumption, but somehow my memory fragmentation ratio stays high and above 1.5.

I've already tried setting activedefrag to yes, but it does not make a difference. I've surely tried restarting the redis but it does not help neither.

Your help is appreciated!

# Memory
used_memory:1500552
used_memory_human:1.43M
used_memory_rss:3698688
used_memory_rss_human:3.53M
used_memory_peak:1930176
used_memory_peak_human:1.84M
used_memory_peak_perc:77.74%
used_memory_overhead:1295068
used_memory_startup:791432
used_memory_dataset:205484
used_memory_dataset_perc:28.98%
allocator_allocated:1701072
allocator_active:2121728
allocator_resident:6782976
total_system_memory:3973873664
total_system_memory_human:3.70G
used_memory_lua:81920
used_memory_lua_human:80.00K
used_memory_scripts:3648
used_memory_scripts_human:3.56K
number_of_cached_scripts:4
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.25
allocator_frag_bytes:420656
allocator_rss_ratio:3.20
allocator_rss_bytes:4661248
rss_overhead_ratio:0.55
rss_overhead_bytes:-3084288
mem_fragmentation_ratio:2.40
mem_fragmentation_bytes:2157248
mem_not_counted_for_evict:1436
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:468456
mem_aof_buffer:1436
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0

you can also see the graphics here: Redis Redis 5.0.11 high memory fragmentation ratio, with regular jemalloc-5.1.0, with output and graphics

Comment From: huangzhw

Your used memory is so little that I don't think it's a problem.

Comment From: oranagra

@zyitingftnt you are looking at mem_fragmentation_ratio which is not actually fragmentation. It's the ratio of used memory to RSS (resident physical memory), We don't rename if for the sake of backwards compatibility. RSS includes shared libraries, code, stack and other things, so while this metric is useful, it's not actually fragmentation (which has risk of rising to high values). If you wanna look at fragmentation, you should look at allocator_frag_ratio instead.

But another point is that your db is nearly empty, so although the ratio seems high, it's not actually a lot of memory. allocator_frag_bytes shows just about 400kb.

You only wanna be concerned if that number is high, and in that case you can enable activedefrag

Comment From: ghost

@huangzhw yes, it is because this is a new install and I wanted to turn the performance before adding traffic but I got warming for mem_fragmentation_ratio > 1.5

@oranagra, are you suggesting that I should not look at mem_fragmentation_ratio and only look at allocator_frag_ratio? So, mem_fragmentation_ratio is not good any more to provide insight about memory fragmentation?

thank you in advance for your help and I am looking forward to your replies.

Comment From: oranagra

@zyitingftnt you can keep looking at mem_fragmentation_ratio, there are some other theoretical scenarios that can cause high RSS usage and this metric will warn about it. But if you wanna know the real fragmentation, then the other metric is the right one. In any case there's no reason to be alarmed about a high ratio when the amount of memory is low. It is typical for redis to show high ratio of either of these when empty.

Which component produced that warning? it should probably be improved..

Comment From: ghost

@oranagra thanks for the explanation, I will keep an eye on it for the real world number when it is not empty anymore. BTW, the reporting tool is Zabbix 5.0

Comment From: oranagra

is the alert for mem_fragmentation_ratio > 1.5 something that comes as default configuration with Zabbix?

Comment From: ghost

@oranagra Yes, it is a default value, but based on what I understand 1.5 is also a best practice value, for example, datadog also talks about 1.5 as well as other vendors that I learned from.

https://www.datadoghq.com/blog/how-to-monitor-redis-performance-metrics/

So.....I am kinda a bit hesitating to ignore it.....

Comment From: oranagra

threshold of 1.5 for mem_fragmentation_ratio may be good.. but for the alert to be useful, it should ignored if mem_fragmentation_bytes is below some 100mb. (similar to the active-defrag-ignore-bytes mechanism in redis). if you have time to figure out where to submit a suggestion to improve that somehow, please go ahead.

Comment From: ghost

@oranagra i'd love to, but is there any documentation that I can refer to so I can support my case facing them? Cheers,

Comment From: oranagra

@zyitingftnt Yes, following this discussion, I updated the docs in https://redis.io/commands/info And I suppose you can also refer to this discussion and the similar active-defrag-ignore-bytes config