Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upValgrind doesn't report allocations with jemalloc on nightly #28224
Comments
This comment has been minimized.
This comment has been minimized.
|
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. |
alexcrichton
closed this
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
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
|
This comment has been minimized.
This comment has been minimized.
|
But Valgrind reports:
|
alexcrichton
changed the title
Valgrind doesn't report allocations with nightly
Valgrind doesn't report allocations with jemalloc on nightly
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
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) |
alexcrichton
reopened this
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
Using |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
I think the issue is that Valgrind can't track calls to jemalloc's |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Building nightly with JEMALLOC_FLAGS='--enable-valgrind' makeresults in the correct Valgrind behavior. Not sure how we want to address this, but providing multiple versions of |
This comment has been minimized.
This comment has been minimized.
|
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! |
This comment has been minimized.
This comment has been minimized.
|
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 |
steveklabnik
added
the
A-tools
label
Mar 11, 2016
This comment has been minimized.
This comment has been minimized.
Hansyperman
commented
Apr 20, 2016
|
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
|
alexcrichton
added
I-nominated
T-tools
labels
Apr 21, 2016
This comment has been minimized.
This comment has been minimized.
|
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 |
alexcrichton
added
P-medium
and removed
I-nominated
labels
May 4, 2016
This comment has been minimized.
This comment has been minimized.
|
It seems that Valgrind support in jemalloc is going away: |
This comment has been minimized.
This comment has been minimized.
lilith
commented
Aug 15, 2016
|
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? |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Aug 15, 2016
|
I believe you just need to ask nightly rust to build your project with the system allocator rather than the bundled jemalloc. |
This comment has been minimized.
This comment has been minimized.
|
Or if you produce a shared library, it will use the system allocator instead of jemalloc by default, which should allow valgrind to work. |
This comment has been minimized.
This comment has been minimized.
lilith
commented
Aug 15, 2016
•
|
@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). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
lilith
commented
Aug 15, 2016
|
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 |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Aug 15, 2016
|
Yes. As I understand the situation, compiling jemalloc with |
This comment has been minimized.
This comment has been minimized.
lilith
commented
Aug 18, 2016
|
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. |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Aug 18, 2016
•
|
@nathanaeljones I'm no expert, but you could look into making a custom rust build with an older jemalloc and/or |
This comment has been minimized.
This comment has been minimized.
lilith
commented
Sep 9, 2016
|
@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. |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Feb 22, 2017
|
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=nightlyFor records purposes:
|
steveklabnik
removed
the
A-tools
label
Mar 24, 2017
alexcrichton
added
T-libs
and removed
T-tools
labels
May 22, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
apasel422 commentedSep 4, 2015
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.