Skip to content

Add profiling_libunwind feature#159

Open
ndr-ds wants to merge 1 commit intotikv:mainfrom
ndr-ds:ndr-ds/add-profiling-libunwind-feature
Open

Add profiling_libunwind feature#159
ndr-ds wants to merge 1 commit intotikv:mainfrom
ndr-ds:ndr-ds/add-profiling-libunwind-feature

Conversation

@ndr-ds
Copy link
Copy Markdown

@ndr-ds ndr-ds commented Mar 25, 2026

Configure jemalloc with --enable-prof-libunwind to use libunwind for heap profiling
backtraces. This avoids a known livelock in gcc's _Unwind_Backtrace in multi-threaded
programs (jemalloc/jemalloc#2282).

The feature implies profiling since jemalloc requires --enable-prof alongside
--enable-prof-libunwind. On Linux, the build emits cargo:rustc-link-lib=unwind to
link against libunwind. On Apple platforms no extra link is needed since unwind symbols
are part of libSystem.

As invited by @BusyJay in
#146 (comment).

Closes #146

Summary by CodeRabbit

  • New Features
    • Added profiling_libunwind feature flag to enable libunwind-based backtracing for heap profiling, addressing a known livelock issue in multi-threaded environments. Requires libunwind-dev or libunwind-devel on Linux systems.

Configure jemalloc with --enable-prof-libunwind to use libunwind for
heap profiling backtraces. This avoids a known livelock in gcc's
_Unwind_Backtrace in multi-threaded programs
(jemalloc/jemalloc#2282).

The feature implies profiling since jemalloc requires --enable-prof
alongside --enable-prof-libunwind. On Linux, the build emits
cargo:rustc-link-lib=unwind. On Apple platforms no extra link is
needed since unwind symbols are part of libSystem.

Closes tikv#146

Signed-off-by: Andre da Silva <andre.dasilva@linera.io>
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Mar 25, 2026

Welcome @ndr-ds! It looks like this is your first PR to tikv/jemallocator 🎉

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c06958ce-9f32-476f-83b5-e231311aeec2

📥 Commits

Reviewing files that changed from the base of the PR and between baae33d and 5cd1753.

📒 Files selected for processing (5)
  • jemalloc-ctl/Cargo.toml
  • jemalloc-sys/Cargo.toml
  • jemalloc-sys/README.md
  • jemalloc-sys/build.rs
  • jemallocator/Cargo.toml

📝 Walkthrough

Walkthrough

Adds a new profiling_libunwind Cargo feature across jemalloc-ctl, jemalloc-sys, and jemallocator crates. The feature configures jemalloc with --enable-prof-libunwind to use libunwind-based backtracing for heap profiling instead of default gcc-based unwinding, and automatically enables the profiling feature alongside optional library linking for supported platforms.

Changes

Cohort / File(s) Summary
Cargo Feature Declarations
jemalloc-ctl/Cargo.toml, jemalloc-sys/Cargo.toml, jemallocator/Cargo.toml
Added new profiling_libunwind feature flags across crates. In jemalloc-ctl and jemallocator, feature activates both tikv-jemalloc-sys/profiling_libunwind and profiling. In jemalloc-sys, feature serves as alias to profiling.
Documentation
jemalloc-sys/README.md
Documented new profiling_libunwind feature flag explaining it configures jemalloc with --enable-prof-libunwind for libunwind-based backtracing, avoids _Unwind_Backtrace livelock bug in multi-threaded programs, and includes platform-specific dependency details (libunwind-dev on Linux; system-provided unwind symbols on macOS/iOS).
Build Configuration
jemalloc-sys/build.rs
Added conditional build path gated on CARGO_FEATURE_PROFILING_LIBUNWIND. When enabled, passes --enable-prof-libunwind to configure and links unwind library on non-Apple and non-Windows targets.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 With libunwind in tow, profiling takes flight,
No more segfaults haunting the musl night,
Backtrace unwound by a gentler hand,
Across all the platforms, our heaps safely stand! 🧪✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new Cargo feature called profiling_libunwind across multiple crates.
Linked Issues check ✅ Passed The PR implements profiling_libunwind to address the segfault in issue #146 by enabling libunwind-based backtracing instead of gcc's default, avoiding the known livelock bug.
Out of Scope Changes check ✅ Passed All changes are focused on adding the profiling_libunwind feature across Cargo manifests, README, and build configuration—directly aligned with the issue objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@BusyJay
Copy link
Copy Markdown
Member

BusyJay commented Mar 25, 2026

Cool, but this requires libunwind installed on system, right? I remember rust itself also use libunwind, is it possible to reuse the package?

@ndr-ds
Copy link
Copy Markdown
Author

ndr-ds commented Mar 25, 2026

Rust uses libgcc_s for unwinding on glibc Linux (source), not libunwind. And either way, jemalloc's configure needs libunwind.h at build time, so the dev package seems to be unavoidable for this opt-in feature, AFAICT.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

x86_64-unknown-linux-musl + profiling = segmentation fault

2 participants