redis info memory研究

info memory输出信息

1
2
3
4
5
6
7
8
9
10
info memory
Memory
used_memory:5198608840
used_memory_human:4.84G
used_memory_rss:11156660224
used_memory_peak:9816601560
used_memory_peak_human:9.14G
used_memory_lua:36864
mem_fragmentation_ratio:2.15
mem_allocator:libc

http://www.cnblogs.com/mushroom/p/4738170.html

对应的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

if (allsections || defsections || !strcasecmp(section,"memory")) {
char hmem[64];
char peak_hmem[64];
size_t zmalloc_used = zmalloc_used_memory();

/* Peak memory is updated from time to time by serverCron() so it
* may happen that the instantaneous value is slightly bigger than
* the peak value. This may confuse users, so we update the peak
* if found smaller than the current memory usage. */
if (zmalloc_used > server.stat_peak_memory)
server.stat_peak_memory = zmalloc_used;

bytesToHuman(hmem,zmalloc_used);
bytesToHuman(peak_hmem,server.stat_peak_memory);
if (sections++) info = sdscat(info,"rn");
info = sdscatprintf(info,
"# Memoryrn"
"used_memory:%zurn"
"used_memory_human:%srn"
"used_memory_rss:%zurn"
"used_memory_peak:%zurn"
"used_memory_peak_human:%srn"
"used_memory_lua:%lldrn"
"mem_fragmentation_ratio:%.2frn"
"mem_allocator:%srn",
zmalloc_used,
hmem,
server.resident_set_size,
server.stat_peak_memory,
peak_hmem,
((long long)lua_gc(server.lua,LUA_GCCOUNT,0))*1024LL,
zmalloc_get_fragmentation_ratio(server.resident_set_size),
ZMALLOC_LIB
);
}

used_memory