Skip to content

Conversation

@ljluestc
Copy link

@ljluestc ljluestc commented Nov 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

weak MallocExtension::instance可能有问题

1 participant