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 the jemallocator crate from crates.io instead of alloc_jemalloc #18836

Closed
wants to merge 1 commit into from

Conversation

@SimonSapin
Copy link
Member

SimonSapin commented Oct 11, 2017

This compiles a new copy of jemalloc in addition to the one brought by the Rust standard library, but:

  • Only one of those ends up being linked
  • The increase in compile times is small (20 seconds on my laptop)

This commit also adds an use of #[global_allocator] to select jemallocator as the default. extern crate alloc_jemalloc; used to decide the default, but it hasn’t since the #[global_allocator] attribute was introduced.

mallctl_set(b"epoch\0", 0_u64) ends up calling mallctl with null pointers for the "old" value and its length, which isn’t the same as what we were doing before (passing the same pointer to both "old" and "new" parameters). My understanding is that this works too, since the important part is passing a new value:

http://jemalloc.net/jemalloc.3.html#epoch

epoch (uint64_t) rw

If a value is passed in, refresh the data from which the mallctl*() functions report values, and increment the epoch. Return the current epoch. This is useful for detecting whether another thread caused a refresh.


This change is Reviewable

@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 11, 2017

@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 12, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Oct 12, 2017

Trying commit b45e4ff with merge 288adfc7bf26eac223a40663b47011e82a586920...

@bors-servo
Copy link
Contributor

bors-servo commented Oct 12, 2017

💔 Test failed - windows-msvc-dev

// Before we request the measurement of interest, we first send an "epoch"
// request. Without that jemalloc gives cached statistics(!) which can be
// highly inaccurate.
if let Err(_) = ::jemallocator::mallctl_set(b"epoch\0", 0_u64) {

This comment has been minimized.

Copy link
@emilio

emilio Oct 12, 2017

Member

is_err(), here and below?

@emilio
Copy link
Member

emilio commented Oct 12, 2017

Just curious, what's the benefit of this?

@nnethercote
Copy link
Contributor

nnethercote commented Oct 12, 2017

Sorry, I don't think I'm a good person to review this. I don't know much about all these Rust/jemalloc plumbing details.

One thing I will note is that you've explained the "what" for this patch, but not the "why". Why is this change a good thing?

@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 12, 2017

Sorry, I should have said more in the original message. @nnethercote I asked you since you wrote the initial version of memory profiling. In particular it’s the modified mallctl call for the epoch that I’m less confident about.

As to why this change:

  • As mentioned in the PR message, extern crate alloc_jemalloc; doesn’t have the effect it once had but we still have it in the code base. Isn’t that a bug?
  • That crate has no path to stabilization and will likely be removed at some point: rust-lang/rust#33082 (comment), so this is a step toward using less unstable features: #13770

Now, I’ve just realized that this PR probably breaks the heapsize crate so it might not be a good idea to land this (if we can even make it work) until #[global_allocator] is stable.

@nnethercote
Copy link
Contributor

nnethercote commented Oct 12, 2017

I know a lot about heapsize but nothing about jemalloc/Rust integration, alloc_jemalloc, global_allocator, etc.

The mallctl epoch change sounds ok, e.g. see here: https://github.com/jemalloc/jemalloc/blob/0eae838b0d4343b09d80dee00f20a39ce709ca8f/test/unit/stats.c#L39

Now, I’ve just realized that this PR probably breaks the heapsize crate

In what way? Right now I'm working on removing heapsize usage in Servo in favour of malloc_size_of...

@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 12, 2017

In what way?

heapsize links to a malloc_usable_size or je_malloc_usable_size symbol, but this crate compiles a separate copy of jemalloc with a different symbol prefix.

Right now I'm working on removing heapsize usage in Servo in favour of malloc_size_of...

Oh that’s right. Good. Then this PR should wait for that.

This compiles a new copy of jemalloc in addition to the one brought
by the Rust standard library, but:

* Only one of those ends up being linked
* The increase in compile times is small (20 seconds on my laptop)

This commit also adds an use of `#[global_allocator]` to select
`jemallocator` as the default.
`extern crate alloc_jemalloc;` used to decide the default,
but it hasn’t since the `#[global_allocator]` attribute was introduced.

`mallctl_set(b"epoch\0", 0_u64)` ends up calling `mallctl`
with null pointers for the "old" value and its length,
which isn’t the same as what we were doing before
(passing the same pointer to both "old" and "new" parameters).
My understanding is that this works too,
since the important part is passing a new value:

http://jemalloc.net/jemalloc.3.html#epoch
>  epoch (uint64_t) rw
>
> If a value is passed in, refresh the data from which
> the mallctl*() functions report values, and increment the epoch.
> Return the current epoch. This is useful for detecting whether
> another thread caused a refresh.
@SimonSapin SimonSapin force-pushed the jemallocator branch from b45e4ff to 15687b4 Oct 12, 2017
@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 12, 2017

@bors-servo try

(Do we run the profiling code on CI?)

@bors-servo
Copy link
Contributor

bors-servo commented Oct 12, 2017

Trying commit 15687b4 with merge 614be36...

bors-servo added a commit that referenced this pull request Oct 12, 2017
Use the jemallocator crate from crates.io instead of alloc_jemalloc

This compiles a new copy of jemalloc in addition to the one brought by the Rust standard library, but:

* Only one of those ends up being linked
* The increase in compile times is small (20 seconds on my laptop)

This commit also adds an use of `#[global_allocator]` to select `jemallocator` as the default. `extern crate alloc_jemalloc;` used to decide the default, but it hasn’t since the `#[global_allocator]` attribute was introduced.

`mallctl_set(b"epoch\0", 0_u64)` ends up calling `mallctl` with null pointers for the "old" value and its length, which isn’t the same as what we were doing before (passing the same pointer to both "old" and "new" parameters). My understanding is that this works too, since the important part is passing a new value:

http://jemalloc.net/jemalloc.3.html#epoch
>  epoch (uint64_t) rw
>
> If a value is passed in, refresh the data from which the mallctl*() functions report values, and increment the epoch. Return the current epoch. This is useful for detecting whether another thread caused a refresh.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18836)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 12, 2017

💔 Test failed - mac-rel-wpt1

@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 12, 2017

As expected:

  = note: Undefined symbols for architecture x86_64:
            "_je_malloc_usable_size", referenced from:
                heapsize::heap_size_of_impl::ha1bd1791b849e267 in libheapsize-4050d473e23561dd.rlib(heapsize-4050d473e23561dd.0.o)
                _$LT$alloc..string..String$u20$as$u20$heapsize..HeapSizeOf$GT$::heap_size_of_children::h8d89a9daf4359604 in libheapsize-4050d473e23561dd.rlib(heapsize-4050d473e23561dd.0.o)
          ld: symbol(s) not found for architecture x86_64
@bors-servo
Copy link
Contributor

bors-servo commented Oct 12, 2017

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

@SimonSapin
Copy link
Member Author

SimonSapin commented Oct 18, 2017

Replaced by #18944.

@SimonSapin SimonSapin closed this Oct 18, 2017
@SimonSapin SimonSapin deleted the jemallocator branch Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.