Redis Memory Management1. There are three ways to request memory for Redis memory: (1) system comes with the Malloc/free method to apply/release. (2Application for memory using Tcmalloc/release. (3) use Jemalloc for memory requests/release. /*explicitly override Malloc/free etc when using Tcmalloc.*/ #ifDefined (USE_TCMALLOC)#definemalloc (size) tc_malloc (size)#defineCalloc (count,size) tc_calloc (count,size)#defineReAlloc (ptr,size) tc_realloc (ptr,size)#defineFree (PTR) tc_free (PTR)#elifDefined (USE_JEMALLOC)#definemalloc (size) je_malloc (size)#defineCalloc (count,size) je_calloc (count,size)#defineReAlloc (ptr,size) je_realloc (ptr,size)#defineFree (PTR) je_free (PTR)#endif2A set of atomic operations with GCC is used on the memory counter, and the function is to used_memory+operation of N//1. Do the operation first, then return the changed value//2. First return the value before change, then do the operation#ifDefined (__atomic_relaxed)#defineUpdate_zmalloc_stat_add (__n) __atomic_add_fetch (&used_memory, (__n), __atomic_relaxed)//used_memory+=n;#defineUpdate_zmalloc_stat_sub (__n) __atomic_sub_fetch (&used_memory, (__n), __atomic_relaxed)//used_memory-=n;#elifDefined (have_atomic)#defineUpdate_zmalloc_stat_add (__n) __sync_add_and_fetch (&used_memory, (__n))//used_memory+=n;#defineUpdate_zmalloc_stat_sub (__n) __sync_sub_and_fetch (&used_memory, (__n))//used_memory-=n;#else 3. There is also a function to get the configuration information of the system
Redis Memory allocation Simple analysis