### Create hello_world.cc example Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md A simple C++ program to demonstrate basic alignment and size checks using standard C++ and malloc. This file is placed in the 'examples' directory. ```cpp #include #include int main() { std::cout << "Standard Alignment: " << alignof(std::max_align_t) << '\n'; double *ptr = (double*) malloc(sizeof(double)); std::cout << "Double Alignment: " << alignof(*ptr) << '\n'; char *ptr2 = (char*) malloc(1); std::cout << "Char Alignment: " << alignof(*ptr2) << '\n'; void *ptr3; std::cout << "Sizeof void*: " << sizeof(ptr3) << '\n'; return 0; } ``` -------------------------------- ### Run TCMalloc Hello World Example Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Execute the compiled `hello_main` program using Bazel to observe TCMalloc in action. This demonstrates heap size changes after memory allocation. ```bash bazel run tcmalloc/testing:hello_main ...INFO: Found 1 target... ...INFO: Build completed successfully, 1 total action Current heap size = 73728 bytes hello world! new'd 1073741824 bytes at 0x14ea40000000 Current heap size = 1073816576 bytes malloc'd 1073741824 bytes at 0x14eac0000000 Current heap size = 2147558400 bytes ``` -------------------------------- ### Build and Test TCMalloc with Bazel Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Navigate into the cloned TCMalloc directory and run all tests using Bazel to verify the installation. ```bash cd tcmalloc bazel test //tcmalloc/... INFO: Analyzed 112 targets (12 packages loaded, 606 targets configured). ...INFO: Build completed successfully, 827 total actions ``` -------------------------------- ### Build TCMalloc Hello World Example Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Build the `hello_main` target within the TCMalloc testing directory using Bazel. This verifies the build process for a sample application. ```bash bazel build tcmalloc/testing:hello_main Extracting Bazel installation... Starting local Bazel server and connecting to it... INFO: Analyzed target //tcmalloc/testing:hello_main (31 packages loaded ... ...INFO: Build completed successfully, 102 total actions PASSED in 0.1s ``` -------------------------------- ### Build and run TCMalloc example with Bazel Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Commands to build the C++ target using Bazel, specifying C++17 standard, and then run the compiled binary. The output shows alignment and size information. ```bash # It's often good practice to build files from the workspace root $ cd ~/Source/TestProject Source/TestProject$ bazel build //examples:hello_world --cxxopt='-std=c++17' INFO: Analysed target //examples:hello_world (12 packages loaded). INFO: Found 1 target... Target //examples:hello_world up-to-date: bazel-bin/examples/hello_world INFO: Elapsed time: 0.180s, Critical Path: 0.00s INFO: Build completed successfully, 1 total action Source/TestProject$ bazel run //examples:hello_world INFO: Running command line: bazel-bin/examples/hello_world Standard Alignment: 16 Double Alignment: 8 Char Alignment: 1 Sizeof void*: 8 Source/TestProject$ ``` -------------------------------- ### Merge Profile Samples and Get Residency Info Source: https://github.com/google/tcmalloc/blob/master/docs/sampling.md Prepares heap profile samples and queries the operating system for the residency status of underlying memory pages using /proc/pid/pagemap. ```c++ MergeProfileSamplesAndMaybeGetResidencyInfo(); ``` -------------------------------- ### Get Malloc Stats Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Call this function to obtain human-readable statistics from TCMalloc. The output contains a lot of information, some of which may be considered debug info. ```cpp tcmalloc::MallocExtension::GetStats() ``` -------------------------------- ### Create BUILD file for hello_world Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Configure a C++ binary target in Bazel, specifying the source file and setting TCMalloc as the custom malloc implementation. ```bazel cc_binary( name = "hello_world", srcs = ["hello_world.cc"], malloc = "@com_google_tcmalloc//tcmalloc", ) ``` -------------------------------- ### Add Abseil using http_archive Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Declare Abseil as a dependency in the WORKSPACE file using http_archive. Ensure you use a specific commit hash and generate the correct sha256 value. ```bazel http_archive( name = "com_google_absl", urls = ["https://github.com/abseil/abseil-cpp/archive/commit_value.zip"], strip_prefix = "abseil-cpp-commit_value", sha256 = "sha256_of_commit_value", ) ``` -------------------------------- ### C API: realloc Source: https://github.com/google/tcmalloc/blob/master/docs/reference.md Re-allocates memory for an existing memory region by expanding or contracting it based on the new size. Returns a pointer to the start of the memory. realloc(ptr, 0) returns NULL. ```APIDOC ## realloc() ### Description Re-allocates memory for an existing region of memory by either expanding or contracting the memory based on the passed `new_size` in bytes, returning a `void*` pointer to the start of that memory (which may not change); it does not perform any initialization of new areas of memory. `realloc(OBJ*, 0)` returns a NULL pointer. If `realloc()` fails for some reason, it also returns NULL. ### Method C Standard Library Function ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (Pointer to reallocated memory) - **void*** (pointer) - Pointer to the start of the reallocated memory. #### Response Example ```c int* arr = (int*)malloc(10 * sizeof(int)); arr = (int*)realloc(arr, 20 * sizeof(int)); ``` ``` -------------------------------- ### Fixing Base Class Pointer Deletion Without Virtual Destructor (Incorrect) Source: https://github.com/google/tcmalloc/blob/master/docs/mismatched-sized-delete.md This example demonstrates the incorrect way to delete a derived class object via a base class pointer when the base class lacks a virtual destructor. This leads to undefined behavior and potential memory leaks. ```cpp class Base { ... }; class Derived : public Base { ... ~Derived(); // note--no virtual! // or no explicit destructor definition at all... } Derived *d = new Derived; Base *b = static_cast(d); ... delete b; ``` -------------------------------- ### Configure C++17 standard in .bazelrc Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Alternative method to set the C++17 standard for all builds by adding a configuration line to the root .bazelrc file. ```bazel build --cxxopt='-std=c++17' ``` -------------------------------- ### Per-CPU Size Class Capacity Statistics Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Reports statistics on the capacity of size class freelists within per-CPU caches. It details the minimum, average, and maximum number of objects cached per size class, along with the maximum allowed capacity for each. ```text ------------------------------------------------ Size class capacity statistics in per-cpu caches ------------------------------------------------ class 0 [ 0 bytes ] : 0 (minimum), 0.0 (average), 0 (maximum), 0 maximum allowed capacity class 1 [ 8 bytes ] : 0 (minimum), 133.1 (average), 636 (maximum), 2048 maximum allowed capacity class 2 [ 16 bytes ] : 0 (minimum), 51.8 (average), 378 (maximum), 2048 maximum allowed capacity class 3 [ 24 bytes ] : 0 (minimum), 119.3 (average), 510 (maximum), 2048 maximum allowed capacity class 4 [ 32 bytes ] : 0 (minimum), 100.0 (average), 542 (maximum), 2048 maximum allowed capacity class 5 [ 40 bytes ] : 0 (minimum), 80.6 (average), 467 (maximum), 2048 maximum allowed capacity ``` -------------------------------- ### Build TCMalloc with Latency Injection Source: https://github.com/google/tcmalloc/blob/master/docs/latency_injection.md To enable latency injection, link against the `tcmalloc_latency_injection` target in your BUILD file. ```bazel //third_party/tcmalloc:tcmalloc_latency_injection ``` -------------------------------- ### HugePageFiller State Summary Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Displays a time-series summary of the HugePageFiller's state over a 5-minute interval, including realized fragmentation and minimum free pages. ```text HugePageFiller: time series over 5 min interval HugePageFiller: realized fragmentation: 0.0 MiB HugePageFiller: minimum free pages: 0 (0 backed) HugePageFiller: at peak demand: 1774 pages (and 261 free, 13 unmapped) ``` -------------------------------- ### Link TCMalloc Repository with Bazel Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Configure your project's WORKSPACE file to link to your local TCMalloc repository using `local_repository`. Ensure the path to TCMalloc is absolute. ```bazel local_repository( # Name of the TCMalloc repository. This name is defined within your # WORKSPACE file, in its `workspace()` metadata name = "com_google_tcmalloc", # NOTE: Bazel paths must be absolute paths. E.g., you can't use ~/ path = "/PATH_TO_SOURCE/Source/tcmalloc", ) ``` -------------------------------- ### Pageheap Allocation Summary Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Reports on the number of live and slack pages in the pageheap, as well as the largest allocation seen. Useful for understanding overall memory usage patterns. ```text PageHeap: stats on allocation sizes PageHeap: 344420 pages live small allocation PageHeap: 12982 pages of slack on large allocations PageHeap: largest seen allocation 29184 pages ``` -------------------------------- ### C API: calloc Source: https://github.com/google/tcmalloc/blob/master/docs/reference.md Allocates memory for an array of objects, zero-initializes all bytes in the allocated storage, and returns a pointer to the allocated memory block. calloc(num, 0) or calloc(0, size) returns a non-NULL zero-sized pointer. ```APIDOC ## calloc() ### Description Allocates memory for an array of objects, zero-initializes all bytes in allocated storage, and if allocation succeeds, returns a pointer to the first byte in the allocated memory block. `calloc(num, 0)` or `calloc(0, size)` returns a non-NULL zero-sized pointer. If `calloc()` fails for some reason, it returns NULL. ### Method C Standard Library Function ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (Pointer to allocated memory) - **void*** (pointer) - Pointer to the start of the allocated memory block. #### Response Example ```c int* arr = (int*)calloc(10, sizeof(int)); ``` ``` -------------------------------- ### C API: posix_memalign Source: https://github.com/google/tcmalloc/blob/master/docs/reference.md Allocates memory with specified alignment and size, storing the pointer in memptr. Returns 0 on success, or an error code on failure. Alignment must be a power of two multiple of sizeof(void *). ```APIDOC ## posix_memalign() ### Description Allocates `size` bytes of memory with alignment of size `alignment` to the start of memory pointed to by `**memptr`; it does not perform any initialization. This pointer can be cast to the desired type of data pointer in order to be dereferenceable. If the alignment allocation succeeds, `posix_memalign()` returns `0`; otherwise it returns an error value. `posix_memalign` is similar to `aligned_alloc()` but `alignment` be a power of two multiple of `sizeof(void *)`. If the constraints are not satisfied, `posix_memalign()` will fail. `posix_memalign` with `size=0` returns a non-NULL zero-sized pointer. ### Method POSIX Standard Library Function ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (0 on success) - **int** (integer) - 0 on success, error code on failure. #### Response Example ```c void* ptr; int ret = posix_memalign(&ptr, 16, 1024); ``` ``` -------------------------------- ### Per Size Range Pageheap Information Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Details pageheap information broken down by allocation size range. It includes counts of allocated/freed pages, live allocations, MiB of live allocations, and allocation rates per second. Use this for granular analysis of memory allocation behavior. ```text HugePageAware: per-size information: HugePageAware: 1 page info: 5817510 / 3863506 a/f, 1954004 (15265.7 MiB) live, 16 allocs/s ( 0.1 MiB/s) HugePageAware: 2 page info: 1828473 / 1254096 a/f, 574377 ( 8974.6 MiB) live, 5.03 allocs/s ( 0.1 MiB/s) HugePageAware: 3 page info: 1464568 / 1227253 a/f, 237315 ( 5562.1 MiB) live, 4.03 allocs/s ( 0.1 MiB/s) ... ``` -------------------------------- ### Per-CPU Cache Underflows, Overflows, and Reclaims Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Displays the total and per-CPU counts of cache underflows, overflows, and reclaims. High overflow to underflow ratios may indicate an undersized cache. ```text ------------------------------------------------ Number of per-CPU cache underflows, overflows, and reclaims ------------------------------------------------ Total : 242 underflows, 12 overflows, overflows / underflows: 0.05, 168 reclaims cpu 0: 69 underflows, 5 overflows, overflows / underflows: 0.07, 46 reclaims cpu 1: 58 underflows, 0 overflows, overflows / underflows: 0.00, 42 reclaims cpu 2: 62 underflows, 7 overflows, overflows / underflows: 0.11, 42 reclaims cpu 3: 40 underflows, 0 overflows, overflows / underflows: 0.00, 27 reclaims cpu 4: 13 underflows, 0 overflows, overflows / underflows: 0.00, 11 reclaims cpu 5: 0 underflows, 0 overflows, overflows / underflows: 0.00, 0 reclaims ``` -------------------------------- ### HugePageFiller Summary Statistics Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Provides an overview of the total, full, partial, released, and quarantined hugepages in the filler cache. Use this to understand the overall capacity and utilization of hugepages. ```text HugePageFiller: densely pack small requests into hugepages HugePageFiller: 19882 total, 8083 full, 11799 partial, 0 released (0 partially), 0 quarantined HugePageFiller: 120168 pages free in 19882 hugepages, 0.0236 free HugePageFiller: among non-fulls, 0.0398 free HugePageFiller: 499 used pages in subreleased hugepages (0 of them in partially released) HugePageFiller: 0 hugepages partially released, 0.0000 released HugePageFiller: 1.0000 of used pages hugepageable HugePageFiller: Since startup, 26159 pages subreleased, 345 hugepages broken ``` -------------------------------- ### Huge Page Aware Allocator Summary Statistics Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Displays a summary of contiguous page ranges, including the number of spans, mapped MiB, and unmapped MiB for each range size. Use this to understand the overall distribution of free and unmapped memory. ```text ------------------------------------------------ HugePageAware: 75 sizes; 938.8 MiB free; 1154.0 MiB unmapped ------------------------------------------------ 1 pages * 86655 spans ~ 677.0 MiB; 677.0 MiB cum; unmapped: 0.0 MiB; 0.0 MiB cum 2 pages * 3632 spans ~ 56.8 MiB; 733.7 MiB cum; unmapped: 0.0 MiB; 0.0 MiB cum 3 pages * 288 spans ~ 6.8 MiB; 740.5 MiB cum; unmapped: 0.0 MiB; 0.0 MiB cum 4 pages * 250 spans ~ 7.8 MiB; 748.3 MiB cum; unmapped: 0.0 MiB; 0.0 MiB cum ... ``` -------------------------------- ### Huge Page Aware Allocator Component Breakdown Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Provides a breakdown of used, free, and unmapped space across the different components of the Huge Page Aware Allocator: filler, region, cache, and alloc. Use this to identify memory usage patterns within each cache. ```text Huge page aware allocator components: ------------------------------------------------ HugePageAware: breakdown of free / unmapped / used space: HugePageAware: filler 38825.2 MiB used, 938.8 MiB free, 0.0 MiB unmapped HugePageAware: region 0.0 MiB used, 0.0 MiB free, 0.0 MiB unmapped HugePageAware: cache 908.0 MiB used, 0.0 MiB free, 0.0 MiB unmapped HugePageAware: alloc 0.0 MiB used, 0.0 MiB free, 1154.0 MiB unmapped ``` -------------------------------- ### C posix_memalign() function signature Source: https://github.com/google/tcmalloc/blob/master/docs/reference.md Allocates `size` bytes with `alignment` to `**memptr`. `alignment` must be a power of two multiple of `sizeof(void *)`. Returns a non-NULL zero-sized pointer for `size=0`. Returns an error code on failure. ```c int posix_memalign(void **memptr, size_t alignment, size_t size); ``` -------------------------------- ### Pageheap Per Number Of Pages In Range Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Provides detailed per-size information for pageheap allocations, including allocated/freed counts, live allocations, MiB usage, and allocation rates. Use this to identify memory usage by allocation size. ```text PageHeap: per-size information: PageHeap: 1 page info: 23978897 / 23762891 a/f, 216006 (6750.2 MiB) live, 2.43e+03 allocs/s ( 76.1 MiB/s) PageHeap: 2 page info: 21442844 / 21436331 a/f, 6513 ( 407.1 MiB) live, 2.18e+03 allocs/s (136.0 MiB/s) PageHeap: 3 page info: 2333686 / 2329225 a/f, 4461 ( 418.2 MiB) live, 237 allocs/s ( 22.2 MiB/s) PageHeap: 4 page info: 21509168 / 21508751 a/f, 417 ( 52.1 MiB) live, 2.18e+03 allocs/s (272.9 MiB/s) PageHeap: 5 page info: 3356076 / 3354188 a/f, 1888 ( 295.0 MiB) live, 341 allocs/s ( 53.2 MiB/s) PageHeap: 6 page info: 1718534 / 1718486 a/f, 48 ( 9.0 MiB) live, 174 allocs/s ( 32.7 MiB/s) ... ``` -------------------------------- ### Activate GWP-ASan Sampling Source: https://github.com/google/tcmalloc/blob/master/docs/gwp-asan.md Enable GWP-ASan's guarded sampling feature. This is the primary method to activate the utility for detecting heap memory errors in production. ```cpp tcmalloc::MallocExtension::ActivateGuardedSampling(); ``` -------------------------------- ### Generate Protobuf C++ Code Source: https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/CMakeLists.txt A custom CMake command to generate C++ source and header files from a protobuf definition. It specifies the output files, the protoc command, include paths, and dependencies. ```cmake add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/tcmalloc/internal/profile.pb.cc ${CMAKE_BINARY_DIR}/tcmalloc/internal/profile.pb.h COMMAND protobuf::protoc --cpp_out=${CMAKE_BINARY_DIR} -I${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/profile.proto DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/profile.proto ) ``` -------------------------------- ### Pageheap Summary Statistics Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Provides a summary of pageheap statistics, including live small allocations, slack on large allocations, and the largest allocation seen. Useful for understanding overall memory allocation patterns. ```text HugePageAware: stats on allocation sizes HugePageAware: 4969003 pages live small allocation HugePageAware: 659 pages of slack on large allocations HugePageAware: largest seen allocation 45839 pages ``` -------------------------------- ### Define tcmalloc_internal_percpu_state Library Source: https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/CMakeLists.txt Defines a C++ library for tcmalloc's internal per-CPU state management. It includes header and source files and lists its dependencies. ```cmake tcmalloc_cc_library( NAME tcmalloc_internal_percpu_state ALIAS tcmalloc::internal_percpu_state HDRS "percpu_state.h" SRCS "percpu_state.cc" DEPS "absl::base" "absl::core_headers" "absl::nullability" "tcmalloc::internal_allocation_guard" "tcmalloc::internal_config" ) ``` -------------------------------- ### HugeRegionSet Cache Summary Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Provides a summary of the HugeRegionSet cache, including the size of allocated slabs, total regions, and the status of backed hugepages and free space. ```text HugeRegionSet: 1 MiB+ allocations best-fit into 1024 MiB slabs HugeRegionSet: 0 total regions HugeRegionSet: 0 hugepages backed out of 0 total HugeRegionSet: 0 pages free in backed region, 0.0000 free ``` -------------------------------- ### Caching Four Objects in Span Source: https://github.com/google/tcmalloc/blob/master/docs/design.md Demonstrates how spare capacity within a span can be utilized to cache up to four small objects, optimizing memory access. ```c++ #include // ... implementation details ... ``` -------------------------------- ### Extensions: __size_returning_new() Source: https://github.com/google/tcmalloc/blob/master/docs/reference.md A prototype extension that returns both the allocated memory and its size in bytes. Can be freed with ::operator delete. ```APIDOC ## __size_returning_new() (Prototype Extension) ### Description This function returns both memory and the size of the allocation in bytes. It can be freed with `::operator delete`. ### Method Prototype Extension ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (Memory and size) - **void*** (pointer) - Pointer to the allocated memory. - **size_t** (size) - The size of the allocation in bytes. #### Response Example ```c++ // Assuming a suitable return type or mechanism to get both values // auto [ptr, size] = __size_returning_new(1024); // ::operator delete(ptr); ``` ``` -------------------------------- ### C calloc() function signature Source: https://github.com/google/tcmalloc/blob/master/docs/reference.md Allocates memory for an array of objects, zero-initializes it. Returns a non-NULL zero-sized pointer for `calloc(num, 0)` or `calloc(0, size)`. Returns NULL on failure. ```c void* calloc(size_t num, size_t size); ``` -------------------------------- ### Set GWP-ASan Sampling Rate Source: https://github.com/google/tcmalloc/blob/master/docs/gwp-asan.md Adjust the sampling rate for GWP-ASan. Lower values increase the chance of finding bugs but also increase CPU overhead. The default sampling rate is recommended if no CPU overhead is tolerable. ```cpp tcmalloc::MallocExtension::SetGuardedSamplingRate(8000000); // Example: Set sampling rate to 8MB ``` -------------------------------- ### Define tcmalloc_tcmalloc_256k_pages_numa_aware library Source: https://github.com/google/tcmalloc/blob/master/tcmalloc/CMakeLists.txt Defines a C++ library for tcmalloc supporting 256K pages with NUMA awareness. It includes header and source files and has extensive dependencies on Abseil and other tcmalloc internal libraries. ```cmake tcmalloc_cc_library( NAME tcmalloc_tcmalloc_256k_pages_numa_aware ALIAS tcmalloc::tcmalloc_256k_pages_numa_aware SRCS "libc_override.h" "tcmalloc.cc" "tcmalloc.h" COPTS "-DTCMALLOC_INTERNAL_256K_PAGES" "-DTCMALLOC_INTERNAL_NUMA_AWARE" DEPS "absl::base" "absl::bits" "absl::config" "absl::core_headers" "absl::dynamic_annotations" "absl::memory" "absl::span" "absl::stacktrace" "absl::status" "absl::statusor" "absl::str_format" "absl::strings" "absl::symbolize" "absl::time" "tcmalloc::alloc_at_least" "tcmalloc::common_256k_pages_numa_aware" "tcmalloc::experiment" "tcmalloc::internal_allocation_guard" "tcmalloc::internal_central_freelist_hooks" "tcmalloc::internal_config" "tcmalloc::internal_declarations" "tcmalloc::internal_linked_list" "tcmalloc::internal_logging" "tcmalloc::internal_memory_tag" "tcmalloc::internal_optimization" "tcmalloc::internal_overflow" "tcmalloc::internal_page_size" "tcmalloc::internal_percpu" "tcmalloc::internal_sampled_allocation" "tcmalloc::internal_system_allocator" "tcmalloc::malloc_extension" "tcmalloc::malloc_hook" "tcmalloc::malloc_tracing_extension" ) ``` -------------------------------- ### HugePageFiller Fullness Histograms Source: https://github.com/google/tcmalloc/blob/master/docs/stats.md Details the distribution of free pages and longest free ranges within regular, donated, and released hugepages. This helps in analyzing memory fragmentation and contiguous free space. ```text HugePageFiller: fullness histograms HugePageFiller: # of regular hps with a<= # of free pages // ... implementation details ... ``` -------------------------------- ### Clone TCMalloc Repository Source: https://github.com/google/tcmalloc/blob/master/docs/quickstart.md Clone the TCMalloc repository from GitHub to your local machine. Ensure you are in the desired directory before cloning. ```bash cd ~ mkdir Source; cd Source git clone https://github.com/google/tcmalloc.git Cloning into 'tcmalloc'... remote: Total 1935 (delta 1083), reused 1935 (delta 1083) Receiving objects: 100% (1935/1935), 1.06 MiB | 0 bytes/s, done. Resolving deltas: 100% (1083/1083), done. ``` -------------------------------- ### Define tcmalloc_internal_percpu_tcmalloc Library Source: https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/CMakeLists.txt Defines a C++ library for tcmalloc's internal per-CPU integration with tcmalloc. It lists header files and numerous dependencies. ```cmake tcmalloc_cc_library( NAME tcmalloc_internal_percpu_tcmalloc ALIAS tcmalloc::internal_percpu_tcmalloc HDRS "percpu_tcmalloc.h" DEPS "absl::base" "absl::bits" "absl::core_headers" "absl::dynamic_annotations" "absl::function_ref" "tcmalloc::internal_delay_injection" "tcmalloc::internal_logging" "tcmalloc::internal_mincore" "tcmalloc::internal_optimization" "tcmalloc::internal_percpu" "tcmalloc::internal_prefetch" "tcmalloc::internal_sysinfo" ) ```