brpc icon indicating copy to clipboard operation
brpc copied to clipboard

allocator hangs that may occur after calling the C++ API `MallocExtension::instance()->ReleaseFreeMemory()` on some tcmalloc versions/distros.

Open ljluestc opened this issue 1 month ago • 0 comments

What problem does this PR solve?

  • Avoids allocator hangs that may occur after calling the C++ API MallocExtension::instance()->ReleaseFreeMemory() on some tcmalloc versions/distros.
  • Adds automated verification to ensure post-release allocations do not hang.

Issue Number: resolves #200

Problem Summary:

  • The weak C++ symbol for MallocExtension::instance() may not be reliably overridden in some environments (e.g., Fedora 26), and calling ReleaseFreeMemory() via that path has been observed to hang subsequent allocations on tcmalloc 1.7/2.5.
  • brpc already uses the stable C API MallocExtension_ReleaseFreeMemory() at runtime; this PR adds tests to prevent regressions and to make verification straightforward.

What is changed and the side effects?

Changed:

  • Add gtest test/brpc_tcmalloc_release_unittest.cpp that:
    • Alloc/free memory → call MallocExtension_ReleaseFreeMemory (weakly referenced) → alloc/free again, with a 10s timeout guard to detect hangs.
  • Optionally include the standalone smoke test tcmalloc_release_test.cc (uses a weak symbol so it runs with or without libtcmalloc).

Side effects:

  • Performance effects:

    • None at runtime; this PR is test-only. The existing runtime already calls the C API and falls back to malloc_trim on Linux.
  • Breaking backward compatibility:

    • None.

ljluestc avatar Nov 05 '25 07:11 ljluestc