brpc
brpc copied to clipboard
allocator hangs that may occur after calling the C++ API `MallocExtension::instance()->ReleaseFreeMemory()` on some tcmalloc versions/distros.
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 callingReleaseFreeMemory()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.cppthat:- Alloc/free memory → call
MallocExtension_ReleaseFreeMemory(weakly referenced) → alloc/free again, with a 10s timeout guard to detect hangs.
- Alloc/free memory → call
- 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_trimon Linux.
- None at runtime; this PR is test-only. The existing runtime already calls the C API and falls back to
-
Breaking backward compatibility:
- None.