Skip to content

Adds comptime option to link jemalloc instead of tcmalloc#44113

Merged
phlax merged 15 commits into
envoyproxy:mainfrom
mathetake:jemalloc
Mar 28, 2026
Merged

Adds comptime option to link jemalloc instead of tcmalloc#44113
phlax merged 15 commits into
envoyproxy:mainfrom
mathetake:jemalloc

Conversation

@mathetake
Copy link
Copy Markdown
Member

@mathetake mathetake commented Mar 25, 2026

Commit Message: Adds comptime option to link jemalloc instead of tcmalloc
Additional Description:

This adds a new comptime option to use jemalloc instead of tcmalloc.

Risk Level: none (not enabled by default)
Testing: existing tests are run on comptime option CI
Docs Changes: follow up once it becomes stable
Release Notes: n/a
Platform Specific Features: n/a

I declare that this is mostly written by Claude with some guidance from me on how to test on CI.

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #44113 was opened by mathetake.

see: more, trace.

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Comment thread .bazelrc
build:compile-time-options --define=log_debug_assert_in_release=enabled
build:compile-time-options --define=path_normalization_by_default=true
build:compile-time-options --define=deprecated_features=disabled
build:compile-time-options --define=tcmalloc=gperftools
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to be able to run jemalloc enabled tests since gperftools will conflict with jemalloc. Instead, added gperftools option explicitly in the CI script

@repokitteh-read-only repokitteh-read-only Bot added the deps Approval required for changes to Envoy's external dependencies label Mar 26, 2026
Comment on lines +28 to +32
// Purge all arenas to release dirty pages back to the OS.
// MALLCTL_ARENAS_ALL is jemalloc's pseudo-index for addressing all arenas at once.
char purge_cmd[32];
snprintf(purge_cmd, sizeof(purge_cmd), "arena.%u.purge", MALLCTL_ARENAS_ALL);
mallctl(purge_cmd, nullptr, nullptr, nullptr, 0);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only place I need to learn things more about jemalloc, but it looks correct too me

@mathetake mathetake marked this pull request as ready for review March 26, 2026 15:25
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).
envoyproxy/dependency-shepherds assignee is @jwendell

🐱

Caused by: #44113 was ready_for_review by mathetake.

see: more, trace.

Comment thread ci/do_ci.sh
Comment thread tools/spelling/spelling_dictionary.txt Outdated
lyft
maglev
malloc
mallctl
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't need to be in the dictionary. But backticks around them in comments. Same for jemalloc above

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep jemalloc as tcmalloc exists here - removing others

Comment thread bazel/foreign_cc/BUILD
Comment thread bazel/BUILD
)

bool_flag(
name = "jemalloc",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be tcmalloc=jemalloc instead for consistency with gperftools?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i did that initially, and thought it's just weird. Either works for me but will leave it to @phlax for the final call

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use a string_flag similar to how the define works - ie something like --//bazel:alloc=jemalloc/tcmalloc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would rather keep the bool flag as is for this PR, then refactor the flags in a follow. wdyt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@mathetake
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the jemalloc memory allocator as an alternative to tcmalloc. It includes the necessary Bazel build configurations, dependency management, and CI updates to enable jemalloc. Additionally, it implements memory statistics and heap management utilities for jemalloc within the Envoy codebase. The review feedback highlights several instances where a call to refreshJemallocEpoch() is required before querying jemalloc statistics to ensure the returned values are up-to-date, and suggests using stats.mapped instead of stats.resident for consistency with existing memory reservation metrics.

Comment thread source/common/memory/stats.cc Outdated
Comment thread source/common/memory/stats.cc
Comment thread source/common/memory/stats.cc
Comment thread source/common/memory/stats.cc
mathetake and others added 3 commits March 26, 2026 20:15
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
@mathetake
Copy link
Copy Markdown
Member Author

ok i think ready

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 27, 2026

/retest possible flakes

@mathetake
Copy link
Copy Markdown
Member Author

Good to go ?

Copy link
Copy Markdown
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks @mathetake - sorry - i thought i approved

@repokitteh-read-only repokitteh-read-only Bot removed the deps Approval required for changes to Envoy's external dependencies label Mar 28, 2026
@phlax phlax merged commit 810f3ed into envoyproxy:main Mar 28, 2026
34 checks passed
TAOXUY pushed a commit to TAOXUY/envoy that referenced this pull request Apr 1, 2026
…#44113)

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Xuyang Tao <taoxuy@google.com>
citrus7 pushed a commit to citrus7/envoy that referenced this pull request Apr 1, 2026
…#44113)

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Jonathan Wu <jtwu@google.com>
nshipilov pushed a commit to nshipilov/envoy that referenced this pull request Apr 13, 2026
…#44113)

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
…#44113)

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

5 participants