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

Miri: GC the dead_alloc_map too #118073

Merged
merged 1 commit into from
Nov 23, 2023
Merged

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Nov 19, 2023

dead_alloc_map is the last piece of state in the interpreter I can find that leaks. With this PR, all of the long-term memory growth I can find in Miri with programs that do things like run a big loop { or run property tests is attributable to some data structure properties in borrow tracking, and is extremely slow.

My only gripe with the commit in this PR is that I don't have a new test for it. I'd like to have a regression test for this, but it would have to be statistical I think because the peak memory of a process that Linux reports is not exactly the same run-to-run. Which means it would have to not be very sensitive to slow leaks (some guesswork suggests for acceptable CI time we would be checking for like 10% memory growth over a minute or two, which is still pretty fast IMO).

Unless someone has a better idea for how to detect a regression, I think on balance I'm fine with manually keeping an eye on the memory use situation.

r? RalfJung

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Nov 19, 2023
@saethlin saethlin added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed A-testsuite Area: The testsuite used to check the correctness of rustc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Nov 19, 2023
@bors
Copy link
Contributor

bors commented Nov 21, 2023

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

@saethlin saethlin marked this pull request as ready for review November 21, 2023 20:13
@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2023

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

The Miri subtree was changed

cc @rust-lang/miri

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does make me rather nervous since we're generally relying on the dead_alloc_map having information about all past allocations. But I guess if an AllocId cannot be found anywhere in the machine state then we cannot possibly care about it in the dead_alloc_map, either...

compiler/rustc_const_eval/src/interpret/memory.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

Thanks. :)
@bors r+

@bors
Copy link
Contributor

bors commented Nov 23, 2023

📌 Commit f5dae8e has been approved by RalfJung

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 23, 2023
@RalfJung
Copy link
Member

is attributable to some data structure properties in borrow tracking

Do you know which data structures?

@bors
Copy link
Contributor

bors commented Nov 23, 2023

⌛ Testing commit f5dae8e with merge 38eecca...

@saethlin
Copy link
Member Author

Do you know which data structures?

Stack and Tree if I recall. It's not a particularly challenging profiling to do again.

@RalfJung
Copy link
Member

Well yeah that is not very specific. But when we're just creating and removing allocations, I don't see why any stacks or trees would keep growing.

@bors
Copy link
Contributor

bors commented Nov 23, 2023

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 38eecca to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 23, 2023
@bors bors merged commit 38eecca into rust-lang:master Nov 23, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 23, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (38eecca): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.3% [3.3%, 3.3%] 1
Regressions ❌
(secondary)
2.2% [1.9%, 2.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.3% [3.3%, 3.3%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 676.494s -> 677.592s (0.16%)
Artifact size: 313.75 MiB -> 313.72 MiB (-0.01%)

@saethlin saethlin deleted the gc-dead-allocs branch November 23, 2023 14:40
@saethlin
Copy link
Member Author

saethlin commented Nov 23, 2023

Well yeah that is not very specific.

Yeah, I think I'll need to cook up some special profiling to understand what's going on. All the existing tools just tell you "this call stack allocated" which is not enlightening.

But when we're just creating and removing allocations, I don't see why any stacks or trees would keep growing.

Ah! I'm observing such behavior in property tests or other long running test suites, which surely do more than just create and remove allocations. I suspect there is some global data structure that is accessed or aliased constantly over the tests, and it accumulates dead state that the GC doesn't know how to remove. Or perhaps all the state is live. In either case, I'll need to do some custom tooling to understand it.

But I don't think the remaining memory growth is a big concern. With the rate it's at now, I think I'm running out of patience long before I run out of memory. So I might just post an issue about what's going on here then not work on it unless I can find a test suite where the memory growth is concerning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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.

5 participants