Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tikv-jemallocator in rustc/rustdoc in addition to jemalloc-sys when enabled. #83152

Merged
merged 1 commit into from
Apr 5, 2021

Conversation

guswynn
Copy link
Contributor

@guswynn guswynn commented Mar 15, 2021

In #81782 it was mentioned that one reason rustc may benefit from minimalloc is it doesn't use the sdallocx api from jemalloc.

Currently, on unix, rust uses jemalloc by importing its symbols to use them with the default, System (libc) global allocator.
This PR switches its global alloc to tikv-jemallocator, which correctly uses sized deallocation (https://docs.rs/tikv-jemallocator/0.4.1/src/tikv_jemallocator/lib.rs.html#121-126). tikv-jemallocator, as far as I can tell, is a more up-to-date set of bindings to jemalloc than jemallocator

The perf results of this pr are in large part due to the version upgrade of jemalloc, but sized deallocation has a non-trivial improvement, particularly to rustdoc.

This pr also includes changes to bootstrap to correctly pass the jemalloc feature through to the rustdoc build

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 15, 2021
@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 15, 2021
@bors
Copy link
Contributor

bors commented Mar 15, 2021

⌛ Trying commit 1b45a29fdf54f0ffae814c700149fd8f18b36442 with merge 0bcde55ea93243c9ca7a70e1c0a4ae9e5a8d5034...

@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 added I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 15, 2021
@guswynn
Copy link
Contributor Author

guswynn commented Mar 15, 2021

ci failure was just a tidy mistake (I ALWAYS forget to run that locally...)

@jyn514
Copy link
Member

jyn514 commented Mar 15, 2021

Do we have perf tests for error paths? My hunch is that, while the clean path of rustc is heavily arena-driven, the error paths are more alloc-heavy

I don't think so, historically we haven't worried much about compile time for errors (see also https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/perfbot/near/229630033). I'd expect rustdoc to show any changes though, it does a lot of allocations.

@guswynn
Copy link
Contributor Author

guswynn commented Mar 15, 2021

@jyn514 rustdoc doesn't appear to depend on this crate? In that case it may be using the libc allocator in all cases?

@jyn514
Copy link
Member

jyn514 commented Mar 15, 2021

Oh huh, I think you're right. Do you mind doing that here? You don't have to add jemalloc to cargo.toml, just load it from the sysroot (see the comment at the top of librustdoc/lib.rs).

@guswynn
Copy link
Contributor Author

guswynn commented Mar 15, 2021

(I also testing with "jemalloc = true" in config.toml locally as even tho im on osx, its ci that turns that on, as well as used the more-correct jemalloc feature in rustc_driver)

@guswynn
Copy link
Contributor Author

guswynn commented Mar 15, 2021

Does bor's need to re-queue with the new commits for rust-timer to catch up?

@jyn514
Copy link
Member

jyn514 commented Mar 15, 2021

Does bors need to re-queue with the new commits for rust-timer to catch up?

Yes, otherwise rust-timer will use the build artifacts from the old commit.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Mar 15, 2021

⌛ Trying commit dad03db36b50c9cc8e935a48d0d8bc5aec5f83c2 with merge 4f4b85262ea011b219ebd71d3da9ac82605df32e...

@LifeIsStrange
Copy link

It would probably be better to use this fork which is more up to date with Jemalloc:
https://github.com/tikv/jemallocator

@guswynn
Copy link
Contributor Author

guswynn commented Mar 15, 2021

@LifeIsStrange I'll take a look!

@bors
Copy link
Contributor

bors commented Mar 15, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2021
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 5, 2021

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing d322385 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 5, 2021
@bors bors merged commit d322385 into rust-lang:master Apr 5, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 5, 2021
@LifeIsStrange
Copy link

@guswynn hi, jemalloc is working on an unofficial release channel which would update every 1-3 months.
They promise to do a less extensive but best effort performance and stability testing, for the x86-64 Linux platform.
So for this platform it could make sense to use such pre-releases.

jemalloc/jemalloc#2060

bors bot added a commit to nervosnetwork/ckb that referenced this pull request Sep 9, 2021
3023: perf: switch global alloc to tikv-jemallocator r=doitian,driftluo a=zhangsoledad

<!--
Thank you for contributing to nervosnetwork/ckb!

If you haven't already, please read [CONTRIBUTING](https://github.com/nervosnetwork/ckb/blob/develop/CONTRIBUTING.md) document.

If you're unsure about anything, just ask; somebody should be along to answer within a day or two.

PR Title Format:
1. module [, module2, module3]: what's changed
2. *: what's changed
-->

### What problem does this PR solve?

gnzlbg/jemallocator#168
jemalloc/jemalloc#1497
see also: rust-lang/rust#83152

### What is changed and how it works?

Proposal:  switch global alloc to tikv-jemallocator which is more up-to-date

### Related changes


### Check List <!--REMOVE the items that are not applicable-->

Side effects

- Performance regression
- Breaking backward compatibility

### Release note <!-- Choose from None, Title Only and Note. Bugfixes or new features need a release note. -->

```release-note
Title Only: Include only the PR title in the release note.
```



Co-authored-by: zhangsoledad <[email protected]>
@guswynn guswynn deleted the jemallocator_part2 branch September 26, 2021 18:51
nnethercote added a commit to nnethercote/rust that referenced this pull request Dec 23, 2021
This was added in rust-lang#83152, which has several errors in its comments.

This commit also fix up the comments, which are quite wrong and
misleading.
@nnethercote
Copy link
Contributor

Currently, on unix, rust uses jemalloc by importing its symbols to use them with the default, System (libc) global allocator. This PR switches its global alloc to tikv-jemallocator, which correctly uses sized deallocation (https://docs.rs/tikv-jemallocator/0.4.1/src/tikv_jemallocator/lib.rs.html#121-126). tikv-jemallocator, as far as I can tell, is a more up-to-date set of bindings to jemalloc than jemallocator

I know I'm late to the party, but: the first and third sentences here are correct, but the second sentence is mostly incorrect. Although this PR added a #[global_allocator], it has no effect, and the mechanism described in the first sentence is still the one that causes jemalloc to be used.

The perf results of this pr are in large part due to the version upgrade of jemalloc, but sized deallocation has a non-trivial improvement, particularly to rustdoc.

Sized deallocation doesn't come into the picture; the improvement was all because tikv-jemalloc-sys uses a newer version of jemalloc than jemalloc-sys. See #92222 for more details.

@guswynn
Copy link
Contributor Author

guswynn commented Dec 23, 2021

@nnethercote One of the earlier perf runs up above in this pr used jemallocator (non-tikv) and more closely captured the much smaller, but still measurable effect of sized deallocation. The larger wins were the upgrade, as you mentioned; the pr description is likely outdated. Hearing that those sized dealloc apis are not being used, which led to #92222 Is very concerning to me, and I would need to dig deeper into why the #[global_allocator] attribute is not causing the sized apis to be used, if that is the case.

@nnethercote
Copy link
Contributor

@nnethercote One of the earlier perf runs up above in this pr used jemallocator (non-tikv) and more closely captured the much smaller, but still measurable effect of sized deallocation.

That perf run is here and you'll see that almost every significant change is a doc build. (The two non-doc ones are likely noise.) You did add the use of jemalloc to rustdoc, but it's the extern stuff in main that has the effect of incorporating jemalloc, not the #[global_allocator].

I would need to dig deeper into why the #[global_allocator] attribute is not causing the sized apis to be used, if that is the case.

#92222's comment points to #81782 (comment), which has an explanation.

@nnethercote
Copy link
Contributor

nnethercote commented Dec 23, 2021

BTW, this was still a great PR! Switching to tikv-jemallocator (well, tikv-jemalloc-sys, because tikv-jemallocator is bypassed) was a huge win, and adding it to rustdoc was also good. It's just that what actually happened and what everyone thought happened didn't quite match 😀

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2021
…-rustdoc, r=alexcrichton

Remove useless `#[global_allocator]` from rustc and rustdoc.

This was added in rust-lang#83152, which has several errors in its comments.

This commit also fix up the comments, which are quite wrong and
misleading.

r? `@alexcrichton`
@guswynn
Copy link
Contributor Author

guswynn commented Dec 27, 2021

@nnethercote oh WOW did not know about the complexity of how rustc is build

is decoupling librustc_driver.so and libstd.so something that anyone is looking at?

@nnethercote
Copy link
Contributor

is decoupling librustc_driver.so and libstd.so something that anyone is looking at?

Not that I know of. And given that sized deallocation doesn't appear to be a win, there's not much motivation for it.

ghuls added a commit to ghuls/frawk that referenced this pull request Jan 13, 2022
Switch to maintained version of jemallocator like rustc did in:
  rust-lang/rust#83152
ghuls added a commit to ghuls/frawk that referenced this pull request Jan 13, 2022
Switch to maintained version of jemallocator like rustc did in:
  rust-lang/rust#83152
ezrosent pushed a commit to ezrosent/frawk that referenced this pull request Jan 15, 2022
* Update clap to 3.0 and improve argument parsing and help output.

Update clap to 3.0 and improve argument parsing and help output:
  - Update clap from 3.0.0-beta4 to 3.0.
  - Update help output text.
  - Allow easy specifying of "-1" for -O option (allow_hyphen_values(true)).
  - Make -v var=value as last argument before program work
    without need for "--" or other argument after.
  - Make -i and -F mutually exclusive as specified field
    separator as -F is not used when parsing input files
    as CSV or TSV.

* Update itoa from 0.4 to 1.0.

Update itoa from 0.4 to 1.0.
itoa::Buffer::new() allocates the necessary space on the stack
automatically, and usage is similar to ryu now.

* Update other dependencies.

Update other dependencies.

* Switch to maintained version of jemallocator.

Switch to maintained version of jemallocator like rustc did in:
  rust-lang/rust#83152
joseluisq added a commit to static-web-server/static-web-server that referenced this pull request Apr 21, 2022
msmouse added a commit to aptos-labs/aptos-core that referenced this pull request Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-compiletime Issue: Problems and improvements with respect to compile times. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-perf Status: Waiting on a perf run to be completed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.