-
Notifications
You must be signed in to change notification settings - Fork 355
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
Improve memory leak identification #1481
Comments
We can't really do this in miri, this would need to be a test-suite feature in the official rust test suite. What we can do is offer functions that you call at the beginning and end of a test and that record the set of allocations that are live and tell you what new allocations still exist at the second call. |
We could also (optionally) capture (parts of) the stack trace for each allocation; that could be sufficient here. The performance impact could be really bad though. |
cc #17 |
I would be quite happy with functions you can call at the start and end of tests to help you identify memory leaks better. |
# Objective Fixes #1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
# Objective Fixes bevyengine#1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
bevyengine/bevy#4959 contains a very nice snippet that helps identify which test in a test suite is leaking:
|
Would it be possible to detect leaks as they happen, that is as soon as the last pointer to the allocation goes out of scope? |
No that's not possible. You could have turned a pointer into a Basically a tracing garbage collector, but if you only enable it when you already know a leak is happening, could be ok. Or we add a way to bisect to leak via the basic block counter. |
[cargo-miri] support nextest Add the ability to run `cargo miri nextest list` and `cargo miri nextest run`. [cargo-nextest](https://nexte.st) is a new test runner for Rust maintained mostly by myself. It has several new features, but the most relevant to miri is the fact that it runs [each test in its own process](https://nexte.st/book/how-it-works.html#the-nextest-model). This gives miri users better leak detection (#1481) for free, for example. See nextest-rs/nextest#181 for discussion, including comments by `@eddyb` and `@RalfJung.` Future work might be to have miri read [the list of tests](https://docs.rs/nextest-metadata/latest/nextest_metadata/struct.TestListSummary.html) (or [test binaries](https://docs.rs/nextest-metadata/latest/nextest_metadata/struct.BinaryListSummary.html)) generated by `nextest list`. `@eddyb` thinks that might be useful. I tested `cargo miri nextest run` against smallvec, and it worked great. Note: Running tests out of archives is currently broken, as the comment in run-test.py explains.
FYI miri + nextest supports proper leak detection because it runs each test in its own process. https://nexte.st/book/miri.html has the instructions -- feel free to give it a whirl! |
I think nextest breaks in my environment for a different reason, but that's something I should raise directly. |
# Objective Fixes bevyengine#1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
Fixed in rust-lang/rust#109061 |
Miri is able to determine if memory leaks occur. The output is similar to:
The leaks are not associated to a specific test however. To aid leak isolation, it would be good if there was a way to see which test caused what leak.
Some ideas are potentially to have a test function associated with the leak line like:
Another option is to have bisection, so that when warnings or errors are omitted that the warnings can be traced to a minimum set of tests that create those errors.
Thanks!
The text was updated successfully, but these errors were encountered: