-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Valgrind doesn't report allocations with jemalloc on nightly #28224
Comments
This is actually an optimization that LLVM is doing, it realizes that the allocation isn't necessary so it's elided entirely. As a result I believe this is working as intended, so closing. |
I'm not sure that's the case. Consider this program: #![feature(test)]
extern crate test;
fn main() {
for i in 0..100 {
let foo = Box::new(i);
test::black_box(foo);
}
} The assembly clearly contains calls to
|
But Valgrind reports:
|
Hm something fishy may indeed be going on here, it looks like valgrind is no longer tracking jemalloc? If you use (also tweaking the title a bit) |
Using |
Sorry to jump in here, but how did you ever get valgrind to report jemalloc stats in the first place? On OS X, I've never successfully gotten any useful stats. |
I think the issue is that Valgrind can't track calls to jemalloc's |
jemalloc is apparently not being built with foo.c: #include <stdio.h>
#include <stdlib.h>
extern void je_mallctl(const char *, void *, size_t *, void *, size_t);
int main() {
int valgrind = 6;
size_t len = 1;
je_mallctl("config.valgrind", &valgrind, &len, NULL, 0);
printf("%d\n", valgrind);
} > gcc foo.c -L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/ -l:liballoc_jemalloc-35017696.rlib -lpthread
> ./a.out
0 |
Building nightly with JEMALLOC_FLAGS='--enable-valgrind' make results in the correct Valgrind behavior. Not sure how we want to address this, but providing multiple versions of |
FWIW, I ran your example program with
To my knowledge, I have not specified any custom flags when building. I also see that massif reports heap allocations over time, so I have some hope that things are just magically working together now! |
Valgrind on Ubuntu still indicates that this code, compiled with #![feature(alloc_jemalloc)]
#![feature(test)]
extern crate alloc_jemalloc;
extern crate test;
fn main() {
for i in 0..100 {
let foo = Box::new(i);
test::black_box(foo);
}
} Removing the allocator has the same effect, while changing to |
I think I reported this same issue on reddit: rust 1.8 stable lost valgrind support I have a mixed rust/extern "C" program. I know it leaks memory and use valgrind to verify behaviour. When I upgraded to rust stable 1.8, it proudly claims not to leak anymore, and even stops allocating memory altogether! While I'm impressed by rusts memory safety guarantees, this is a bit too much for me ;-) Anyone knows what happens and how to make it un-happen? I read somewhere they integrated jemalloc, so maybe that broke the monitoring allocator from valgrind? An example on debian 8.4, x86-64:
On rust 1.8:
On rust 1.7
|
The tools team discussed this issue during triage yesterday and the conclusion was that while not high priority we would very much like to see this issue fixed! The |
It seems that Valgrind support in jemalloc is going away: |
I have a mixed C/Rust project targeting windows, linux, & mac. Lots of codecs are involved, and valgrind is an essential tool for verifying that integration tests aren't exposing a new bug in libpng or another dependency (this is a very common occurrence). Does this change mean that I should move all of my integration tests to C++? Or is a custom build of rust required? |
I believe you just need to ask nightly rust to build your project with the system allocator rather than the bundled jemalloc. |
Or if you produce a shared library, it will use the system allocator instead of jemalloc by default, which should allow valgrind to work. |
@ssokolow You mean the 'official' nightly build would do this? What flags would I provide? (Building nightly from source means I can't do this in Travis, which is where I valgrind as part of CI). |
Thank you! The "--enable-valgrind" context led me to misunderstand @ssokolow. So to clarify, there's no compilation flag that can change this; I would need to inject source code |
Yes. As I understand the situation, compiling jemalloc with |
There is the problem that I'm running valgrind against a totally different executable, compiled by nightly instead of stable. Essentially this means I can't valgrind products of a stable rust build. |
@nathanaeljones I'm no expert, but you could look into making a custom rust build with an older jemalloc and/or |
@ssokolow Thanks! For now it looks like nightly will be a requirement for other reasons anyway :) Valgrind has been crucial for my work with unsafe Rust. As far as I can tell there's no way to make the generated test harnesses Valgrind-friendly; a standalone executable is required. |
As a quick update, since this is getting linked to, here's how I make the system allocator opt-in for nightly: First, add these lines to the top of main.rs: #![cfg_attr(feature="nightly", feature(alloc_system))]
#[cfg(feature="nightly")]
extern crate alloc_system; Then, add these to Cargo.toml... [features]
nightly = [] And, finally, use these commands for setup and building: rustup toolchain add nightly-x86_64-unknown-linux-gnu
cargo +nightly build --features=nightly For records purposes:
|
We're unlikely to really do anything to fix this, so I'm going to close this in favor of #27389. It's highly likely that all programs will start to link to |
Compiling the following code with
opt-level=0
, Valgrind reports 26 allocs forrustc 1.2.0 (082e47636 2015-08-03)
, but 5 allocs forrustc 1.4.0-nightly (cd138dc44 2015-09-02)
:Perhaps this has something to do with #27400? In any case, it's harder to use Valgrind to debug Rust programs because of this.
The text was updated successfully, but these errors were encountered: