From:http://wangneng-168.iteye.com/blog/2100379
Redis uses tcmalloc to manage memory, and when a Redis key is removed, the redis Info command is used to view memory usage. The memory is not released, but the default jemalloc does not have this problem
The following is the memory condition that is seen through info after deleting the key after using Tcmalloc and deleting key:
Delete key Before:
used_memory:13051400
used_memory_human:12.45m
used_memory_rss:16326656
used_memory_peak:13051400
used_memory_peak_human:12.45m
used_memory_lua:33792
mem_fragmentation_ratio:1.25
mem_allocator:tcmalloc-2.0
Delete key after
used_memory:835080
used_memory_human:815.51k
used_memory_rss:16392192
used_memory_peak:13051400
used_memory_peak_human:12.45m
used_memory_lua:33792
mem_fragmentation_ratio:19.63
mem_allocator:tcmalloc-2.0
The following is the memory condition that is seen through info after deleting the key after using Jemalloc and deleting key:
Delete key Before:
used_memory:13047176
used_memory_human:12.44m
used_memory_rss:14704640
used_memory_peak:13047176
used_memory_peak_human:12.44m
used_memory_lua:33792
mem_fragmentation_ratio:1.13
mem_allocator:jemalloc-3.6.0
Delete key after
used_memory:830696
used_memory_human:811.23k
used_memory_rss:2318336
used_memory_peak:13047176
used_memory_peak_human:12.44m
used_memory_lua:33792
mem_fragmentation_ratio:2.79
mem_allocator:jemalloc-3.6.0
from the results, after deleting a large number of keys, Redis allocated memory with Jemalloc reduced to about 2M, while Tcmalloc did not change
Tcmalloc the principle of:
Http://wenku.baidu.com/link?url=pzXI4OTNuoNGPKQ9MtKOX_ 60adnrekve5m94qnuzmj0bsgcaxodpcvolchwd4bjagaqbsrnn2acxzne9mp4fshzm2a-oxt02ohmbyrhcblw
It is mentioned that the current Tcmalloc version does not return any memory to the operating system, and the memory occupied by Redis instances when using Tcmalloc is related to the peak memory usage of Redis
JeMalloc the principle can be see:
http://club.alibabatech.org/article_detail.htm?articleId=36
which mentions:
The recycling process is broadly similar to the distribution process, withTcacheWill cache the collected blocks withoutTcacheDirect recovery of the mechanism (no more thanChunkthat will correspond to thepageThe state is modified to reclaim the correspondingRun; greater thanChunkthe directMunmap). It is necessary to focus onJemallocwhen will the memory be returned to the operating system becausePtmallocexists because of the use ofTop_chunkmechanism (see the articles in the court) and make the memory unavailable to the operating system. At present, except for the large memory directlyMunmap,JemallocThere are also two mechanisms to free up memory:
1. when released , it is found that all the memory of a chunk is dirty (i.e., after being allocated and recycled), the entire chunk is released;
2.whenArenain thepagewhen the allocation satisfies a thresholdDirty PagemakePurge(by callingmadviseto proceed). The specific meaning of this threshold is that theArenain theDirty Pagesize has reached aChunksize and account for theactive Pageof the1/opt_lg_dirty_mult(the default is1/32). active PageIt means that it is already in use.Runof thepage, whileDirty Pageis the one that has been allocated and recycled.page.
Both of these mechanisms ensure that jemalloc does not appear to have issues like ptmalloc memory not being returned to the operating system
Conclusion: It is good to use Tcmalloc and jemalloc with caution.
Redis uses Tcmalloc to cause memory not to be freed