- 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/smaps size of "Private Dirty" in the query |
Zmalloc_get_rss |
/proc/<pid>/stat get 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