Using jemalloc to Optimize Memory Allocation
Principle
jemalloc is a memory allocator. Compared with other memory allocators (glibc), jemalloc has the following advantages: high memory allocation performance and fewer memory fragments in multi-thread scenarios. To make full use of the multi-core and multi-concurrency advantages of the Kunpeng chip. It is recommended to use jemalloc in the service application code to allocate memory.
During memory allocation, locks cause thread waiting, which greatly affects performance. The jemalloc function uses the following measures to prevent threads from contending for locks: thread variables are used; each thread has its own memory manager, and allocation is performed in the thread. Therefore, the thread does not need to contend for locks with other threads.
Modification Method
- Download jemalloc and compile and install it by referring to INSTALL.md.
- Modify the link library mode of the application software and add the following compilation options:
- For some open-source software, you can modify configuration parameters to specify the memory allocation library. For example, you can configure the my.cnf file malloc-lib=/usr/local/lib/libjemalloc.so for MySQL.