Learning redis source code [Memory Allocation]

Source: Internet
Author: User
Introduction

The current version of redis supports tcmalloc, jemalloc, Apple's malloc, or redis's own zmalloc. Zmalloc manages the memory allocation, which is thread-safe, and the allocated memory must be sizeof (long.

Source code

Zmalloc. h zmalloc. c

Description of macro variables:

  • Prefix_size: the size of the allocated memory is recorded before the actually allocated memory. It is similar to the memory data structure of malloc in the actual C, but C may be different depending on the specific environment.
  • Have_malloc_size: Indicates whether other malloc functions are used to implement the malloc. Related functions can be used to directly obtain the allocated memory size, if not, the actual size + prefix_size is allocated based on zmalloc.
Others

In addition to the standard zamlloc, zcalloc, zrealloc, and zfree functions, zmalloc also provides the zstrdup function for dumping memory data to strings, obtain the zmalloc_used_memory function that has used the total memory and the zmalloc_set_oom_handler that sets the memory overflow handler. It also provides the actual material memory size used by the program to obtain RSS in the system.

For specific implementation, you can read the detailed source code. It is easy to read the source code based on the above.

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.