Google Inc. a new version of the memory allocation system , which is used in many internal Google projects. The TCMalloc code is written in C++ and is licensed under the Apache license. To operate, a compiler supporting C++17 for C++ and C11 for C (gcc 9.2+ or clang 9.0+) is required. Of operating systems only Linux (x86, PPC).
It is noteworthy that since 2005 there has been another version of tcmalloc that as part of the package (Google Performance Tools). These are two projects that have common roots. The new TCMalloc is more of an attempt to open the code of current internal developments at Google, but it is not yet aimed at providing a stable ABI and supporting a wide range of operating systems. The maintenance of the old tcmalloc from gperftools will continue, but new features such as CPU cache binding will not be transferred to it.
TCMalloc includes an implementation of the C function malloc() and the C++ operator 'new', optimized for high performance and use in multithreaded applications. TCMalloc also provides introspection and profiling capabilities, allowing the application to obtain detailed information about memory usage in the heap. The code uses optimizations based on the modern capabilities of the C++ language, such as
the delete operator with from C++14 and memory allocation with from C++17.
TCMalloc consists of three components: a frontend with a cache for fast allocation and deallocation of memory, a layer for filling the frontend cache, and a backend that performs operations such as obtaining memory from the operating system, managing large chunks of unused memory, and returning excess memory back to the OS. The cache is free from locks and works in association with CPU cores, but reverts to a thread-bound caching model if the necessary functionality is absent in the OS kernel (CPU cache binding works only in recent Linux kernels). The backend supports working with both regular memory pages and large pages (hugepage).
Key features of TCMalloc:
- Fast allocation and deallocation of memory using caching. Most memory allocation operations do not require locking, which provides good scalability for multi-threaded applications with high parallelism in task execution;
- Flexible memory usage that allows the reuse of freed memory areas for objects of different sizes or returning memory to the operating system;
- Low overhead for each object due to allocating pages of uniformly sized objects and efficiently representing small objects. Logical pages of sizes 4KiB, 8KiB, 32KiB, and 256KiB are supported. For example, when requesting blocks of 512 bytes of memory, a whole 4KiB page will be allocated for 512-byte objects, fitting 8 such objects;
- Fine-tuning available through cache size definitions and memory return intensity parameters to the OS;
- Providing detailed information for analyzing memory usage by the application.
Source: opennet.ru
