Redis uses zmalloc for memory allocation, while tcmallc or jemalloc is used in the lower layer of zmalloc. They have better performance than glibcmalloc In the case of multi-thread concurrency. The following four functions are replaced: malloccallocreallocfreezmalloc mainly adds an 8-byte header for memory allocation for each segment, which records this
Redis uses zmalloc for memory allocation, while tcmallc or jemalloc is used in the lower layer of zmalloc. They have better performance than glibc malloc In the case of multi-thread concurrency. The following four functions are replaced: malloc calloc realloc free zmalloc is mainly used to allocate an additional 8-byte header for each segment of memory, which records this
Redis uses zmalloc for memory allocation, while tcmallc or jemalloc is used in the lower layer of zmalloc. They have better performance than glibc malloc In the case of multi-thread concurrency. The following four functions are replaced:
- Malloc
- Calloc
- Realloc
- Free
Zmalloc adds an additional 8-byte header to the memory allocated for each segment, which records the length of the memory allocated for this allocation. Zmalloc and other functions automatically process the offset. You do not need to know the existence of the header.
Zmalloc defines the total memory allocated by used_memory records.
To evaluate the memory fragmentation problem, Redis needs to know the actual memory consumed by the process (RSS, resident set size), which mainly uses the interface provided by the operating system.
- Linux: each process has its own directory under the/proc directory. By naming the process ID, read the 24th fields of the stat file to get the memory usage of the process;
- Apple: Use task_info to obtain the task_basic_info of the current process. The resident_size indicates the memory usage.
Calculate RSS/used_memory to know the severity of the current fragmentation problem.
Original address: Redis memory allocation. Thank you for sharing it with the original author.