Skip to content

Commit a748cf5

Browse files
committed
Auto merge of #10737 - ehuss:revert-num-cpus, r=weihanglo
[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.
2 parents 4751950 + 0cfdbc0 commit a748cf5

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ libc = "0.2"
4444
log = "0.4.6"
4545
libgit2-sys = "0.13.2"
4646
memchr = "2.1.3"
47+
num_cpus = "1.0"
4748
opener = "0.5"
4849
os_info = "3.0.7"
4950
pathdiff = "0.2"

src/cargo/core/compiler/build_config.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::core::compiler::CompileKind;
22
use crate::util::interning::InternedString;
33
use crate::util::{CargoResult, Config, RustfixDiagnosticServer};
4-
use anyhow::{bail, Context as _};
4+
use anyhow::bail;
55
use cargo_util::ProcessBuilder;
66
use serde::ser;
77
use std::cell::RefCell;
88
use std::path::PathBuf;
9-
use std::thread::available_parallelism;
109

1110
/// Configuration information for a rustc build.
1211
#[derive(Debug)]
@@ -74,12 +73,7 @@ impl BuildConfig {
7473
its environment, ignoring the `-j` parameter",
7574
)?;
7675
}
77-
let jobs = match jobs.or(cfg.jobs) {
78-
Some(j) => j,
79-
None => available_parallelism()
80-
.context("failed to determine the amount of parallelism available")?
81-
.get() as u32,
82-
};
76+
let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32);
8377
if jobs == 0 {
8478
anyhow::bail!("jobs may not be 0");
8579
}

src/cargo/core/compiler/timings.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use anyhow::Context as _;
1313
use cargo_util::paths;
1414
use std::collections::HashMap;
1515
use std::io::{BufWriter, Write};
16-
use std::thread::available_parallelism;
1716
use std::time::{Duration, Instant, SystemTime};
1817

1918
pub struct Timings<'cfg> {
@@ -381,9 +380,6 @@ impl<'cfg> Timings<'cfg> {
381380
};
382381
let total_time = format!("{:.1}s{}", duration, time_human);
383382
let max_concurrency = self.concurrency.iter().map(|c| c.active).max().unwrap();
384-
let num_cpus = available_parallelism()
385-
.map(|x| x.get().to_string())
386-
.unwrap_or_else(|_| "n/a".into());
387383
let max_rustc_concurrency = self
388384
.concurrency
389385
.iter()
@@ -446,7 +442,7 @@ impl<'cfg> Timings<'cfg> {
446442
self.total_fresh + self.total_dirty,
447443
max_concurrency,
448444
bcx.build_config.jobs,
449-
num_cpus,
445+
num_cpus::get(),
450446
self.start_str,
451447
total_time,
452448
rustc_info,

0 commit comments

Comments
 (0)