Redis Memory Allocation

Source: Internet
Author: User
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.

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.