Skip to content

Conversation

@madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Sep 16, 2025

In the past, #[used] had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the symbols.o file in #95604, and more recently for Mach-O in #133832, which means that libraries can now implement the required workarounds themselves. This allows moving these #[used] declarations out of our main.rs.

Specifically, I have moved them into tikv-jemalloc-sys where they belong in tikv/jemallocator#109 and done the same for mimalloc in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day).

Test with:

./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true

# macOS
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b _rjem_je_zone_register
(lldb) run
# Should breakpoint, this means that the allocator was properly linked

# Linux
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b malloc
(lldb) run
# Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc`

try-job: aarch64-gnu
try-job: dist-aarch64-linux
try-job: dist-x86_64-musl
try-job: dist-x86_64-apple
try-job: dist-aarch64-apple

@madsmtm madsmtm added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 16, 2025
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Sep 16, 2025
@rust-log-analyzer

This comment has been minimized.

@madsmtm madsmtm added O-linux Operating system: Linux O-macos Operating system: macOS labels Sep 17, 2025
@madsmtm
Copy link
Contributor Author

madsmtm commented Oct 25, 2025

tikv-jemalloc-sys v0.6.1 has been released with the mentioned PR, so this is now ready. I'm less certain about the Linux parts here, so please double-check that.

Also, in the second commit, I fixed librustdoc and clippy building with --features jemalloc / ./x build --set rust.jemalloc=true, unclear to me how this wasn't caught by CI? Are these built differently there?

@rustbot ready
r? compiler
@bors try

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2025
rust-bors bot added a commit that referenced this pull request Oct 25, 2025
Simplify `jemalloc` setup

try-job: `aarch64-gnu`
try-job: `dist-aarch64-linux`
try-job: `dist-x86_64-musl`
try-job: `dist-x86_64-apple`
try-job: `dist-aarch64-apple`
@rust-bors

This comment has been minimized.

@madsmtm madsmtm marked this pull request as ready for review October 25, 2025 21:52
@rustbot
Copy link
Collaborator

rustbot commented Oct 25, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

The Miri subtree was changed

cc @rust-lang/miri

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@madsmtm madsmtm added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-allocators Area: Custom and system allocators and removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Oct 25, 2025
@rust-bors
Copy link

rust-bors bot commented Oct 26, 2025

☀️ Try build successful (CI)
Build commit: 8d39231 (8d39231d22563844d4088a7af200b6885c749c85, parent: 79966ae420f38c5861d177356a3446023c090d6d)

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

☔ The latest upstream changes (presumably #148412) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot

This comment has been minimized.

use rustc_middle::ty::TyCtxt;
use rustc_session::config::{ErrorOutputType, RustcOptGroup, make_crate_type_option};
use rustc_session::{EarlyDiagCtxt, getopts};
/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
Copy link
Contributor

Choose a reason for hiding this comment

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

could you also link to this PR here? It's much easier for someone to accidentally change something in rustc and this reference to go stale, while if you link to this PR the reasoning always stays clear.

r=me after that

@rustbot author

Copy link
Member

Choose a reason for hiding this comment

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

Or perhaps pin the reference to a commit?

Copy link
Contributor Author

@madsmtm madsmtm Nov 11, 2025

Choose a reason for hiding this comment

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

I went with:

/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement.

(There wasn't really a commit I could pin it to while changing the contents in the same commit).

@rustbot
Copy link
Collaborator

rustbot commented Nov 10, 2025

Error: shortcut handler unexpectedly failed in this comment: failed to remove Label { name: "S-waiting-on-review" }

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 11, 2025
…zelmann

Simplify `jemalloc` setup

In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang#95604, and more recently for Mach-O in rust-lang#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`.

Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day).

Test with:
```sh
./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true

# macOS
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b _rjem_je_zone_register
(lldb) run
# Should breakpoint, this means that the allocator was properly linked

# Linux
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b malloc
(lldb) run
# Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc`
```

try-job: `aarch64-gnu`
try-job: `dist-aarch64-linux`
try-job: `dist-x86_64-musl`
try-job: `dist-x86_64-apple`
try-job: `dist-aarch64-apple`
bors added a commit that referenced this pull request Nov 12, 2025
Rollup of 12 pull requests

Successful merges:

 - #146627 (Simplify `jemalloc` setup)
 - #147753 (Suggest add bounding value for RangeTo)
 - #147974 (Improve diagnostics for buffer reuse with borrowed references)
 - #148080 ([rustdoc] Fix invalid jump to def macro link generation)
 - #148424 (bootstrap: Add snapshot tests for path-to-step handling)
 - #148500 (Update git index before running diff-index)
 - #148536 (cmse: add test for `async` and `const` functions)
 - #148770 (implement `feature(c_variadic_naked_functions)`)
 - #148819 (Remove specialized warning for removed target)
 - #148830 (miri subtree update)
 - #148833 (Update rustbook dependencies)
 - #148841 (Remove more `#[must_use]` from portable-simd)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 12, 2025
…zelmann

Simplify `jemalloc` setup

In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang#95604, and more recently for Mach-O in rust-lang#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`.

Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day).

Test with:
```sh
./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true

# macOS
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b _rjem_je_zone_register
(lldb) run
# Should breakpoint, this means that the allocator was properly linked

# Linux
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b malloc
(lldb) run
# Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc`
```

try-job: `aarch64-gnu`
try-job: `dist-aarch64-linux`
try-job: `dist-x86_64-musl`
try-job: `dist-x86_64-apple`
try-job: `dist-aarch64-apple`
bors added a commit that referenced this pull request Nov 12, 2025
Rollup of 16 pull requests

Successful merges:

 - #146627 (Simplify `jemalloc` setup)
 - #147753 (Suggest add bounding value for RangeTo)
 - #147832 (rustdoc: Don't pass `RenderOptions` to `DocContext`)
 - #147974 (Improve diagnostics for buffer reuse with borrowed references)
 - #148080 ([rustdoc] Fix invalid jump to def macro link generation)
 - #148465 (Adjust spans into the `for` loops context before creating the new desugaring spans.)
 - #148500 (Update git index before running diff-index)
 - #148531 (rustc_target: introduce Abi, Env, Os)
 - #148536 (cmse: add test for `async` and `const` functions)
 - #148770 (implement `feature(c_variadic_naked_functions)`)
 - #148780 (fix filecheck typos in tests)
 - #148819 (Remove specialized warning for removed target)
 - #148830 (miri subtree update)
 - #148833 (Update rustbook dependencies)
 - #148834 (fix(rustdoc): Color doctest errors)
 - #148841 (Remove more `#[must_use]` from portable-simd)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5dc3c19 into rust-lang:main Nov 12, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 12, 2025
@bors
Copy link
Collaborator

bors commented Nov 12, 2025

⌛ Testing commit 65f0b7a with merge 0b329f8...

rust-timer added a commit that referenced this pull request Nov 12, 2025
Rollup merge of #146627 - madsmtm:jemalloc-simplify, r=jdonszelmann

Simplify `jemalloc` setup

In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in #95604, and more recently for Mach-O in #133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`.

Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day).

Test with:
```sh
./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true

# macOS
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b _rjem_je_zone_register
(lldb) run
# Should breakpoint, this means that the allocator was properly linked

# Linux
lldb -- ./build/host/stage1/bin/rustc -vV
(lldb) b malloc
(lldb) run
# Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc`
```

try-job: `aarch64-gnu`
try-job: `dist-aarch64-linux`
try-job: `dist-x86_64-musl`
try-job: `dist-x86_64-apple`
try-job: `dist-aarch64-apple`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Nov 12, 2025
Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#146627 (Simplify `jemalloc` setup)
 - rust-lang/rust#147753 (Suggest add bounding value for RangeTo)
 - rust-lang/rust#147832 (rustdoc: Don't pass `RenderOptions` to `DocContext`)
 - rust-lang/rust#147974 (Improve diagnostics for buffer reuse with borrowed references)
 - rust-lang/rust#148080 ([rustdoc] Fix invalid jump to def macro link generation)
 - rust-lang/rust#148465 (Adjust spans into the `for` loops context before creating the new desugaring spans.)
 - rust-lang/rust#148500 (Update git index before running diff-index)
 - rust-lang/rust#148531 (rustc_target: introduce Abi, Env, Os)
 - rust-lang/rust#148536 (cmse: add test for `async` and `const` functions)
 - rust-lang/rust#148770 (implement `feature(c_variadic_naked_functions)`)
 - rust-lang/rust#148780 (fix filecheck typos in tests)
 - rust-lang/rust#148819 (Remove specialized warning for removed target)
 - rust-lang/rust#148830 (miri subtree update)
 - rust-lang/rust#148833 (Update rustbook dependencies)
 - rust-lang/rust#148834 (fix(rustdoc): Color doctest errors)
 - rust-lang/rust#148841 (Remove more `#[must_use]` from portable-simd)

r? `@ghost`
`@rustbot` modify labels: rollup
@Zalathar
Copy link
Member

Bors, this has already been merged.

@bors r- retry

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 12, 2025
@madsmtm madsmtm deleted the jemalloc-simplify branch November 12, 2025 20:47
@Zalathar
Copy link
Member

Regressions in doc benchmarks across the board; this seems unintended?

@RalfJung
Copy link
Member

Maybe rustdoc accidentally is not using jemalloc any more?

@Kobzol
Copy link
Member

Kobzol commented Nov 13, 2025

Some allocation changes have definitely happened there:

  496,710,988  ???:
  -408,481,523    realloc
   261,159,975    do_rallocx
   253,281,882    _rjem_je_arena_ralloc
  -193,667,679    tcache_bin_flush_small
   159,404,361    _rjem_je_arena_ralloc_no_move
    96,036,695    _rjem_je_tcache_bin_flush_small
    81,229,215    tcache_bin_flush_edatas_lookup
   -76,118,340    malloc_default
    67,153,310    rtree_read
    64,297,968    rtree_metadata_read
   -54,428,351    pa_alloc
    51,577,458    _rjem_je_arena_cache_bin_fill_small
    29,630,447    _rjem_je_malloc_default
    18,729,715    _rjem_je_emap_update_edata_state
    17,881,154    _rjem_je_eset_fit
    13,595,487    emap_try_acquire_edata_neighbor_impl
    11,825,510    _rjem_je_te_event_trigger
   -10,311,127    free_default
   -10,132,168    ecache_evict
     8,316,595    _rjem_je_eset_remove
     8,300,824    _rjem_je_tcache_bin_flush_stashed
     8,176,825    _rjem_je_eset_insert
     8,124,547    emap_rtree_leaf_elms_lookup
     7,930,250    base_alloc_impl
    -7,411,000    tcache_bin_flush_stashed
     7,385,380    _rjem_je_hook_invoke_dalloc
     7,385,320    _rjem_je_hook_invoke_alloc
     7,226,602    extent_recycle
    -7,008,483    eset_remove

I would suggest perf. testing any PR that touches things like memory allocation, for the next time 😅

I will post a revert, so that we can figure out what happened here.

@Kobzol
Copy link
Member

Kobzol commented Nov 13, 2025

#148896

Kobzol added a commit to Kobzol/rust that referenced this pull request Nov 13, 2025
… r=jdonszelmann"

This reverts commit 5dc3c19, reversing
changes made to 11339a0.
rust-bors bot added a commit that referenced this pull request Nov 13, 2025
Revert "Rollup merge of #146627 - madsmtm:jemalloc-simplify, r=jdonszelmann"
@madsmtm
Copy link
Contributor Author

madsmtm commented Nov 13, 2025

Some allocation changes have definitely happened there:

[snip]

Could you tell me how you arrived at that table? I'm unfamiliar with Linux perf tooling.

I would suggest perf. testing any PR that touches things like memory allocation, for the next time 😅

Yeah, sorry about that, I should've done that!

@Kobzol
Copy link
Member

Kobzol commented Nov 13, 2025

Could you tell me how you arrived at that table? I'm unfamiliar with Linux perf tooling.

Yeah, sorry. If you open a benchmark row from the comparison table, it shows "Command for profiling locally", which you can copy paste in a checkout of https://github.com/rust-lang/rustc-perf to do a Cachegrind diff before/after the PR.

bors added a commit that referenced this pull request Nov 13, 2025
Revert "Rollup merge of #146627 - madsmtm:jemalloc-simplify, r=jdonszelmann"

This reverts commit 5dc3c19, reversing
changes made to 11339a0.

Reverts #146627 due to a [perf regression](#148851 (comment)).

r? `@Zalathar`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Nov 14, 2025
Revert "Rollup merge of #146627 - madsmtm:jemalloc-simplify, r=jdonszelmann"

This reverts commit 5dc3c19417d0fbfd979c5a1ecd8bebe2d8d9110e, reversing
changes made to 11339a0ef5ed586bb7ea4f85a9b7287880caac3a.

Reverts rust-lang/rust#146627 due to a [perf regression](rust-lang/rust#148851 (comment)).

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

Labels

A-allocators Area: Custom and system allocators A-linkage Area: linking into static, shared libraries and binaries O-linux Operating system: Linux O-macos Operating system: macOS S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants