Skip to content

perf(build): set jemalloc narenas:1 to trim init metadata + RSS#1272

Draft
duncanista wants to merge 1 commit into
jordan.gonzalez/cold-start-instrumentation/featurefrom
jordan.gonzalez/jemalloc-narenas/feature
Draft

perf(build): set jemalloc narenas:1 to trim init metadata + RSS#1272
duncanista wants to merge 1 commit into
jordan.gonzalez/cold-start-instrumentation/featurefrom
jordan.gonzalez/jemalloc-narenas/feature

Conversation

@duncanista

Copy link
Copy Markdown
Contributor

Jira: none yet — add before marking ready.

⚠️ DRAFT — stacked on top of #1271 (jordan.gonzalez/cold-start-instrumentation/feature). Base will be retargeted to main once #1271 merges. Needs benchmarking and was NOT docker-built locally.

Overview

Tune jemalloc at compile time to a single arena (narenas:1) in both compile Dockerfiles:

  • images/Dockerfile.bottlecap.compile (GNU / AL2)
  • images/Dockerfile.bottlecap.alpine.compile (musl / Alpine)
ENV JEMALLOC_SYS_WITH_MALLOC_CONF="narenas:1"

Why compile-time, and not a MALLOC_CONF env var

The binary allocates through tikv-jemallocator, which links jemalloc with the _rjem_ symbol prefix. With that prefix, jemalloc does not read the standard runtime MALLOC_CONF environment variable (nor the malloc_conf weak symbol under the unprefixed name), so setting MALLOC_CONF at runtime is silently ignored — a footgun. The robust way to configure a prefixed build is the compile-time env JEMALLOC_SYS_WITH_MALLOC_CONF, which jemalloc-sys bakes into the build. Hence the change lives in the Dockerfiles rather than in the Lambda runtime environment.

Mechanism / expected effect

  • jemalloc pre-maps per-arena metadata at init; the default arena count scales with CPU count. Forcing narenas:1 cuts that to a single arena, reducing the metadata mapped at initialization and lowering steady-state RSS.
  • The extension is not allocation-throughput-bound — it is an async I/O-bound telemetry forwarder — so the usual reason for many arenas (reducing cross-thread allocator contention) does not apply here. Arena contention is a non-issue for this workload.

Testing

  • Benchmark cold-start init time and RSS before/after (primary validation — not yet done).
  • Confirm both images build (GNU + Alpine). Not docker-built locally.

Dockerfile-only change — no Rust source touched, no cargo run required.

tikv-jemallocator links jemalloc with the _rjem_ symbol prefix, so a runtime MALLOC_CONF env var is never read. Set the compile-time JEMALLOC_SYS_WITH_MALLOC_CONF instead, in both the GNU and Alpine compile Dockerfiles. A single arena reduces the metadata jemalloc maps at init and lowers RSS; the extension is not allocation-throughput-bound, so arena contention is not a concern.

Dockerfile-only change; not docker-built locally and pending benchmarking.
@datadog-official

datadog-official Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 9 Pipeline jobs failed

DataDog/datadog-lambda-extension | integration-suite: [oom]   View in Datadog   GitLab

DataDog/datadog-lambda-extension | integration-suite: [payload-size]   View in Datadog   GitLab

DataDog/datadog-lambda-extension | bottlecap (amd64, alpine)   View in Datadog   GitLab

View all 9 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 81e6985 | Docs | Datadog PR Page | Give us feedback!

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.

1 participant