#3011·jemalloc

Add OpenTelemetry memory profiling support

Author: scottgerringCreated Sep 22, 2026Updated Sep 22, 2026

We are adding memory profiling to OpenTelemetry: an opt-in view of what drives memory growth in a process and which call stacks are responsible for it, emitted as OTLP heap profiles by the OpenTelemetry eBPF profiler.

As part of this we would love to add the otel_memory USDT contract to jemalloc, so jemalloc user's allocation samples can be consumed by external eBPF profilers without application code changes.

Sampling model

We have deliberately aligned the proposed sampling model with the existing sampling strategy used by jemalloc and tcmalloc as documented here. The USDT side is therefore simply firing behind the existing sampling decision rather than requiring some new sampling scheme.

Proposed behaviour

  • Two new probes in a single provider, matching the ADR contract:
    • otel_memory:alloc(void *ptr, uint64_t size, uint64_t weighted_bytes)
    • otel_memory:free(void *ptr)
  • Enabled and disabled at runtime via MALLOC_CONF (e.g. prof_usdt:true, or maybe prof_otel:true), which turns on the USDT hooks together with the existing observability/sampling hooks. Default off.
  • No in-process unwinding. A no-op backtrace hook is installed via the experimental.hooks.prof_backtrace mallctl, so jemalloc does not unwind on sampled allocations. The eBPF profiler captures stacks externally when the probe fires. jemalloc only supplies (ptr, size, weight) and pays nothing for stack capture.
  • free fires only for pointers that were previously sampled, keeping live-heap correlation keyed by (pid, ptr) on the consumer side.

Motivation

We are already doing this today with custom builds of jemalloc (observed-jemalloc) and would love for it to work upstream. Upstreaming the USDTs means users get memory profiling without replacing or interposing their allocator.