Redis Memory allocation Simple analysis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.