get different value of used memory by command "info" and "info memory" in version 3.2.5
10.8.40.236:6379> info memory
Memory
used_memory:106788864 used_memory_human:101.84M used_memory_rss:126259200 used_memory_rss_human:120.41M used_memory_peak:167347280 used_memory_peak_human:159.59M total_system_memory:8210415616 total_system_memory_human:7.65G used_memory_lua:37888 used_memory_lua_human:37.00K maxmemory:0 maxmemory_human:0B maxmemory_policy:noeviction mem_fragmentation_ratio:1.18 mem_allocator:jemalloc-4.0.3
10.8.40.236:6379> info
Server
redis_version:3.2.5 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:6b77e833017f111f redis_mode:standalone os:Linux 2.6.32-431.el6.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll gcc_version:4.4.7 process_id:3657 run_id:c0fa8487d8331820b746100985c8bf035715657c tcp_port:6379 uptime_in_seconds:17590 uptime_in_days:0 hz:10 lru_clock:7258751 executable:/usr/local/redis/bin/redis-server config_file:/usr/local/redis/bin/redis.conf
Clients
connected_clients:4 client_longest_output_list:0 client_biggest_input_buf:0 blocked_clients:0
Memory
used_memory:106774608 used_memory_human:101.83M used_memory_rss:126259200 used_memory_rss_human:120.41M used_memory_peak:167347280 used_memory_peak_human:159.59M total_system_memory:8210415616 total_system_memory_human:7.65G used_memory_lua:37888 used_memory_lua_human:37.00K maxmemory:0 maxmemory_human:0B maxmemory_policy:noeviction mem_fragmentation_ratio:1.18 mem_allocator:jemalloc-4.0.3
Comment From: tporadowski
It is generated by the very same function server.c/genRedisInfoString(section) and a lot can happen between two calls to "info" and "info memory" and hence the difference.
Comment From: mingrammer
Same problem here
Comment From: hornsey
@tporadowski when I didn't write to redis server, I executed command "info " and "info memory " by turn , I got the same value of used_memory from command "info", and same value from "info memory", but the two value is different.
Comment From: tporadowski
@hornsey I see what you mean now. I suppose this is due to the fact that "info" output itself requires more memory allocated than "info memory" as the former is simply a longer string :). Before "info" reaches the memory section - it uses some memory for "server" and "clients" sections, so running both commands will always yield slightly different results.
Comment From: jonahharris
I believe you're correct @tporadowski -- The info command buffers data using sds, which defines its allocators (s_malloc/s_realloc) as zmalloc/zrealloc and appears to incur several additional reallocations in the default (defsections) case (where info is called without [section | ALL]). zmalloc_used_memory() is returning the higher memory as a result of the larger sds used to store the info data and is the only difference in allocations between calls. I believe this can be closed. @antirez
Comment From: oranagra
as indicated above, this isn't an issue (many things background tasks, and the INFO command itself) can use memory and change the usage between calls.