-
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
Higher memory usage on Rust 1.61.0 (compared to 1.60.0) leading to SIGKILL #97549
Comments
try reduce parallel job |
That ultimately does make it succeed, but lengthens build time quite a bit |
FWIW, I'm having this issue too. 1.61.0 seems to use substantially more memory during compilation (specifically, we are running into the issue with |
I think it's a insolvable problem, thus maybe we could at least be aware of memory increase consomption by rustc when we run crater for a new rustc release, with crater we could see rustc used more or less memory since last time, maybe... but in finite memory is always a hard problem, if you don't have enough memory to build your project the only solution is add memory, or reduce concurrent job, having cpu / 2 job for example. I don't think rustc will have enough contributor to guarantee stable memory usage, that a non goal I think. @rustbot labels: +regression-from-stable-to-stable -regression-untriaged (add label thus I'm not very used to this) |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. Ping to WG-compiler-performance for possible insights/suggestions to diagnose the source of the regression @rustbot label -I-prioritize +P-high +wg-compiler-performance |
@badboy Can you confirm that you have 3 CPUs? In the error message in your log, I see 9 process errors which implies that more than 3 processes were running concurrently. Usually, if Cargo is limited to building 3 jobs in parallel, and one of them fails, it will halt immediately and not try any more. 1.61 changed to use the standard library I'm not sure what the best way is to check. Perhaps you can compile a small program and run it to test: fn main() {
println!("{}", std::thread::available_parallelism().unwrap());
} Or if you want to get cargo to tell you directly, the only way I can think of is to create an empty project and get the timing data: cargo new foo
cd foo
cargo b --timings
grep ncpu target/cargo-timings/cargo-timing.html |
So: 36 cores visible, 70G of memory visible. Now on that same machine |
OK. My suspicion is that CircleCI's Docker uses cgroups v1 (as does my local system), and #92697 doesn't help. @the8472 is it feasible to support cgroups v1 in If not, I'm inclined to revert rust-lang/cargo#10427. cc @joshtriplett @weihanglo |
Should be feasible, yes. But taking a look at the |
The comments above make it sound like the memory problems are not the compiler's fault per se, but rather changes in how many compiler processes Cargo is spawning. https://perf.rust-lang.org/compare.html?start=2022-01-01&end=2022-06-06&stat=max-rss is a quick sanity check, comparing the max-rss measurement for the development compiler from Jan 1st (definitely before the 1.61 cutoff) and June 6th. Between those dates we upgraded most of the "primary" benchmarks so we don't have many results in that section, but we do have helloworld and lots of secondary benchmarks, which should be enough to give a rough idea. It shows that 201 benchmark runs saw max-rss reductions, some quite large, while only 2 runs saw increases. So this is pretty strong evidence that the compiler's memory usage has only gone down lately, adding weight to the theory that it's all about how the compiler is being invoked by Cargo. (BTW, I'm not dismissing the significance of this issue, just clarifying the likely cause.) |
Supporting cgroupv1 should still be possible without scanning /proc/mountinfo, by looking in the standard location where it's generally mounted. Could you post the output of |
FWIW, people like me who work on compiler performance certainly do care about memory usage. It's tracked continously and triaged weekly, and we're always happy to hear about regressions. |
|
Explicitly limiting cargo to 6 jobs ( |
Recent Rust/Cargo changed detection of available cores, which is probably the cause of earlier CPU/memory exhaustion kills. By manually limiting it to 6 jobs we stay within the limits, while keeping about the same runtime. Upstream bug: rust-lang/rust#97549
But hat's what I mean, there is not one standard location. The manpage says
Those are examples and cgroupv1 is meant to be flexible that one can arbitrarily combine the different controller hierarchies or given them different names. We could try a fixed list but then wouldn't we have to survey distros what they use as their default cgroup v1 setup? A single sample doesn't seem sufficient. |
We talked about this in today's @rust-lang/libs meeting. This isn't a libs regression (since libs never supported cgroupv1); it's a cargo regression. Three possibilities:
|
Regarding groupv1 support in libs: Since this is not the common case, and on most systems processes aren't in a cgroupv1, I think we should try to minimize the amount of time this takes, even if that means it's best-effort-only. I don't think we should make all the systems where processes aren't in a cgroup go through a (potentially very expensive) mountinfo scan. |
We can check But yeah, I guess I'll start with the fixed list and if someone still complains about cgroupv1 later with some non-standard configuration that can be another PR. |
I'm not sure I agree that most systems are using cgroups v2. My own system does not, and support has only recently been added. I posted rust-lang/cargo#10737 with a revert on beta. If we can get (however basic) cgroups v1 support in 1.63, that would make me feel a lot more comfortable with using the std implementation. |
[beta] Revert #10427: switch from num_cpus This temporarily reverts #10427 (Use available_parallelism instead of num_cpus) per the discussion at rust-lang/rust#97549. `available_parallelism` does not handle cgroups v1 on Linux unlike num_cpus. I am concerned that this potentially affects a significant percentage of users. For example, Docker just added cgroups v2 support last year. Various Linux distributions have only recently switched to it as the default. The following is what I can find on the web: * Fedora (since 31) * Arch Linux (since April 2021) * openSUSE Tumbleweed (since c. 2021) * Debian GNU/Linux (since 11) * Ubuntu (since 21.10) * RHEL and RHEL-like distributions (since 9) This also appears to affect CircleCI. The consequence is that Cargo ends up using too much parallelism and can run out of memory. I'm not sure what to do about 1.63. If std adds support for cgroups v1, then I don't think there is anything to do there. Otherwise I think we should revert similarly if that doesn't happen.
I am seeing the same symptom (builds failing due to enormously increased memory usage in 1.61.0) but in a non-Cargo environment. I am still investigating but I notice that rustc calls |
cgroupv1 PR: #97925 |
Recent Rust/Cargo changed detection of available cores, which is probably the cause of earlier CPU/memory exhaustion kills. By manually limiting it to 6 jobs we stay within the limits, while keeping about the same runtime. Upstream bug: rust-lang/rust#97549
Revert "remove num_cpus dependency" in rustc and update cargo Fixes rust-lang#97549. This PR reverts rust-lang#94524 and does a Cargo update to pull in rust-lang/cargo#10737. Rust 1.61.0 has a regression in which it misidentifies the number of available CPUs in some environments, leading to enormously increased memory usage and failing builds. In between Rust 1.60 and 1.61 both rustc and cargo replaced some uses of `num_cpus` with `available_parallelism`, which eliminated support for cgroupv1, still apparently in common use. This PR switches both rustc and cargo back to using `num_cpus` in order to support environments where the available parallelism is controlled by cgroupv1. Both can use `available_parallism` again once it handles cgroupv1 (if ever). I have confirmed that the rustc part of this PR fixes the memory usage regression in my non-Cargo environment, and others have confirmed in rust-lang#97549 that the Cargo regression was at fault for the memory usage regression in their environments.
Add cgroupv1 support to available_parallelism Fixes rust-lang#97549 My dev machine uses cgroup v2 so I was only able to test that code path. So the v1 code path is written only based on documentation. I could use some help testing that it works on a machine with cgroups v1: ``` $ x.py build --stage 1 # quota.rs fn main() { println!("{:?}", std::thread::available_parallelism()); } # assuming stage1 is linked in rustup $ rust +stage1 quota.rs # spawn a new cgroup scope for the current user $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS # should print Ok(3) $ ./quota ``` If it doesn't work as expected an strace, the contents of `/proc/self/cgroups` and the structure of `/sys/fs/cgroups` would help.
#97925 landed, so next nightly will have support for cgroupv1 quotas too. |
…=jyn514 Reland changes replacing num_cpus with available_parallelism Since rust-lang#97925 added cgroupv1 support the problem in rust-lang#97549 which lead to the previous revert should be addressed now. Cargo has reapplied the replacement too rust-lang/cargo#10969 Reverts 1ae4b25 (part of rust-lang#97911) Relands rust-lang#94524
…=jyn514 Reland changes replacing num_cpus with available_parallelism Since rust-lang#97925 added cgroupv1 support the problem in rust-lang#97549 which lead to the previous revert should be addressed now. Cargo has reapplied the replacement too rust-lang/cargo#10969 Reverts 1ae4b25 (part of rust-lang#97911) Relands rust-lang#94524
It seems that memory usage during compilation has increased between 1.60.0 and 1.61.0, enough to trigger an OOM kill on CircleCI when trying to build my project.
Running on a
medium+
instance (3 vCPUs, 6 GB RAM).Command used:
cargo test --all --verbose -- --nocapture
Example run: https://app.circleci.com/pipelines/github/mozilla/glean/9430/workflows/8c32e02e-6915-47ee-a587-a0ec098d9afd/jobs/175430
Same on nightly (
rustc 1.63.0-nightly (28b891916 2022-05-29)
)The same task runs just fine with Rust 1.60.0
I don't yet have a smaller example to showcase this, nor exact memory measurments. I'm willing to explore this further if you let me know how to best record memory usage.
The text was updated successfully, but these errors were encountered: