The cornerstone of Redis memory management ZMALLC.C Source code interpretation (appendix): Source Structure table

Source: Internet
Author: User

    • The cornerstone of Redis memory management ZMALLC.C Source code interpretation (a)
    • The cornerstone of Redis memory management ZMALLC.C Source code interpretation (ii)

The previous two posts, detailed introduction of the ZMALLOC.C file of the various functions, but we want to learn more redis, but also need to see the source code is, I combed the structure of the zmalloc.c file, for everyone to read the source code to facilitate.

Global variables
name type Description
Used_memory Static size_t Size of Redis used memory space
Zmalloc_thread_safe static int Identifies whether thread-safe
Used_memory_mutex pthread_mutex_t Mutual exclusion Lock when modifying variable used_memory
Zmalloc_oom_handler static void (*) (size_t) function pointer to function called when memory is low
Function Main function
name Description
Zmalloc Allocating memory space
Zfree Free up space allocated by Zmalloc
Zcalloc Allocate memory space and initialize to 0
Zrealloc Size of the reallocation space
Zstrdup String copy
Zlibc_free With free ()
Other functions
name Description
Zmalloc_enable_thread_safeness Set the thread safety ID (zmalloc_thread_safe 1)
Zmalloc_get_fragmentation_ratio Memory Utilization: Rss/used_memory
zmalloc_get_memory_size Returns the size of the system's physical memory (in bytes)
Zmalloc_get_private_dirty /proc/self/smapssize of "Private Dirty" in the query
Zmalloc_get_rss /proc/<pid>/statget RSS values by querying a file
Zmalloc_get_smap_bytes_by_field The /proc/self/smaps size of the specified field for the query
Zmalloc_set_oom_handler Set the value of the Oom (out of memory) function pointer
Zmalloc_size Querying the size of the system's actual allocated memory space
Zmalloc_used_memory Query the size of the used space (used_memory)

zmalloc_get_memory_size()This function has not been included in the latest Redis release. Only in the current (2015/04) GitHub development version.

Honghong function
name Description
Update_zamlloc_stat_alloc Update the value of Used_memory after allocating memory space
Update_zamlloc_stat_free Update the value of Used_memory after releasing memory space
Update_zamlloc_stat_add Thread Safely used_memory Add operations
Update_zamlloc_stat_sub Thread safely used_memory reduce operations
Macro
name Description
Prefix_size Allocating more space than required for memory allocation
Have_malloc_size Define this macro if you use Tcmalloc, Jemalloc, or Mac systems

The cornerstone of Redis memory management ZMALLC.C Source code interpretation (appendix): Source Structure table

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.