Skip to content

allocator: Make jemalloc code optional - #44032

Merged
jschwe merged 15 commits into
servo:mainfrom
jschwe:jschwender/jemalloc-feature
Aug 6, 2026
Merged

jschwe merged 15 commits into
servo:mainfrom
jschwe:jschwender/jemalloc-feature

Conversation

@jschwe

@jschwe jschwe commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

Add a feature, so we can avoid compiling the tikv-jemalloc crates, when they are not needed.
Reviewer feedback requested the jemalloc and and the system allocator backends to be mutually exclusive, meaning that use-system-allocator and the new use-jemalloc feature shouldn't be able to be used together.
That leads to the removal of the use-system-allocator feature, since we can also detect the absense of custom allocator features instead, which means we remove on error path.
For convenience purposes, this PR also adds feature groups, which bundle certain features: Our default web features, and bundled options. In servoshell we consolidate those into a default_without_allocator feature, so that in our ASAN build we can use the system allocator, while keeping other default dependencies.

These feature groups should also be more generally useful, e.g. if we start feature-gating more web-platform features.

Testing: Requires manual testing, to test the non-default allocator (system allocator) is still selected via ./mach build --no-default-features --features default_without_allocator.

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 8, 2026
@mrobinson

Copy link
Copy Markdown
Member

What is an example of a usecase that needs both use-jemalloc and use-system-allocator? It seems that this should be a binary thing?

@jschwe

jschwe commented Apr 8, 2026 •

Copy link
Copy Markdown
Member Author

This is mainly to keep compatibility with current behavior - It allows us to opt-in to using the system allocator by simply enabling that feature, without requiring --no-default-features and enabling all the other features again.

@jschwe

jschwe commented Apr 10, 2026 •

Copy link
Copy Markdown
Member Author

This is mainly to keep compatibility with current behavior - It allows us to opt-in to using the system allocator by simply enabling that feature, without requiring --no-default-features and enabling all the other features again.

Or to maybe rephrase that - since we want to default to jemalloc (on most systems), jemalloc needs to be a default feature. But if you want to profile memory usage / use ASAN etc., then being able to just enable one feature without needing to disable default features is quite a convenience win.

In the medium term I want to think more about how we can let the embedder define the allocator (see #44060), and in that case the problem would also go away.

@jschwe
jschwe requested a review from mrobinson April 14, 2026 11:38
@jschwe

jschwe commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

@mrobinson How can we proceed here? I could make the feature exclusive. If we added a new feature-group "standard-non-mutual-exclusive-features" (better name required), then switching allocators wouldn't be too bad flag wise.

@mrobinson

mrobinson commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

@jschwe Sorry for letting this sit so long -- it slipped off my plate. I think making the feature exclusive and starting to add feature groups sounds like a good option, rather than allowing contradictory build configurations.

@jschwe
jschwe force-pushed the jschwender/jemalloc-feature branch from a79e2aa to e0d764c Compare August 3, 2026 05:32
@servo-highfive servo-highfive added the S-needs-rebase There are merge conflict errors. label Aug 3, 2026
jschwe added 3 commits August 4, 2026 20:16
Add a feature, so we can avoid compiling the tikv-jemalloc crates,
when they are not needed.

Signed-off-by: Jonathan Schwender <[email protected]>
Signed-off-by: Jonathan Schwender <[email protected]>
Signed-off-by: Jonathan Schwender <[email protected]>
@jschwe
jschwe force-pushed the jschwender/jemalloc-feature branch from a078bf2 to 9001466 Compare August 4, 2026 18:16
@servo-highfive servo-highfive removed the S-needs-rebase There are merge conflict errors. label Aug 4, 2026
Comment thread python/servo/build_commands.py Resolved
Comment thread ports/servoshell/Cargo.toml Resolved
Signed-off-by: Jonathan Schwender <[email protected]>
@jschwe
jschwe force-pushed the jschwender/jemalloc-feature branch from f70fd3f to b33cefb Compare August 6, 2026 10:04
jschwe added 3 commits August 6, 2026 12:16
remainder of previous approach

Signed-off-by: Jonathan Schwender <[email protected]>
We want to fallback to libc if no allocator feature is selected.
That doesn't cost us anything.

Signed-off-by: Jonathan Schwender <[email protected]>
@jschwe
jschwe force-pushed the jschwender/jemalloc-feature branch from b33cefb to 41fdb44 Compare August 6, 2026 10:26
apparently it's broken.

Signed-off-by: Jonathan Schwender <[email protected]>
# configuration with `--no-default-features` build
#
# A convenience feature to enable all default web features servo has.
default_web_features = ["clipboard", "webgpu", "webxr"]

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.

It would be interesting to have a discussion on what should go in here (after this PR). I'd line towards almost everything? (gamepad is broken, I tried adding it, and linting failed.)

Comment thread Cargo.toml Resolved
Comment thread ports/servoshell/Cargo.toml Resolved
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Aug 6, 2026
jschwe added 2 commits August 6, 2026 13:26
Signed-off-by: Jonathan Schwender <[email protected]>
it was a default feature before, so lets keep it there.
We can later adjust default features if needed in a dedicated PR

Signed-off-by: Jonathan Schwender <[email protected]>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 6, 2026
jschwe added 2 commits August 6, 2026 14:18
Not needed anymore, after adding `default_without_allocator`.

Signed-off-by: Jonathan Schwender <[email protected]>
Signed-off-by: Jonathan Schwender <[email protected]>
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Aug 6, 2026
@jschwe
jschwe added this pull request to the merge queue Aug 6, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 6, 2026
Merged via the queue into servo:main with commit b29cc74 Aug 6, 2026
33 checks passed
@jschwe
jschwe deleted the jschwender/jemalloc-feature branch August 6, 2026 14:28
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 6, 2026
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
Add a feature, so we can avoid compiling the tikv-jemalloc crates, when
they are not needed.
Reviewer feedback requested the jemalloc and and the system allocator
backends to be mutually exclusive, meaning that `use-system-allocator`
and the new `use-jemalloc` feature shouldn't be able to be used
together.
That leads to the removal of the `use-system-allocator` feature, since
we can also detect the absense of custom allocator features instead,
which means we remove on error path.
For convenience purposes, this PR also adds feature groups, which bundle
certain features: Our default web features, and bundled options. In
servoshell we consolidate those into a `default_without_allocator`
feature, so that in our ASAN build we can use the system allocator,
while keeping other default dependencies.

These feature groups should also be more generally useful, e.g. if we
start feature-gating more web-platform features.


Testing: Requires manual testing, to test the non-default allocator
(system allocator) is still selected via `./mach build
--no-default-features --features default_without_allocator`.

---------

Signed-off-by: Jonathan Schwender <[email protected]>
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.

3 participants