Skip to content

Commit d946319

Browse files
committed
Add a CPU limit, raise example memory limit
The combination of no job limit and a low memory limit has been causing a lot of OOMs in crater runs. This adds a job limit and enforces it including for doctests, which are built by the test runner. If nothing else, setting this CPU limit provides reproducible OOMs because many crates have peak memory usage proportional to build parallelism.
1 parent 774de59 commit d946319

File tree

16 files changed

+61
-8
lines changed

16 files changed

+61
-8
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ctrlc = "3.1.3"
6464
prometheus = "0.7.0"
6565
cargo_metadata = "0.12.1"
6666
indexmap = "1.4.0"
67+
git2 = { version = "0.13", features = ["vendored-libgit2"] }
6768

6869
[dev-dependencies]
6970
assert_cmd = "1.0.2"

config.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ local-crates = []
2727

2828
[sandbox]
2929
# Maximum amount of RAM allowed during builds
30-
memory-limit = "1536M" # 1.5G
30+
memory-limit = "4096M" # 4G, 1G/cpu
31+
cpu-limit = 4
3132
# Restrictions on the amount of information stored in build logs
3233
build-log-max-size = "5M"
3334
build-log-max-lines = 10000

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub struct DemoCrates {
7474
#[serde(rename_all = "kebab-case")]
7575
pub struct SandboxConfig {
7676
pub memory_limit: Size,
77+
pub cpu_limit: u16,
7778
pub build_log_max_size: Size,
7879
pub build_log_max_lines: usize,
7980
}
@@ -256,6 +257,7 @@ impl Default for Config {
256257
local_crates: HashMap::new(),
257258
sandbox: SandboxConfig {
258259
memory_limit: Size::Gigabytes(2),
260+
cpu_limit: 1,
259261
build_log_max_size: Size::Megabytes(1),
260262
build_log_max_lines: 1000,
261263
},
@@ -308,6 +310,7 @@ mod tests {
308310
"local-crates = []\n",
309311
"[sandbox]\n",
310312
"memory-limit = \"2G\"\n",
313+
"cpu-limit = 1\n",
311314
"build-log-max-size = \"2M\"\n",
312315
"build-log-max-lines = 1000\n",
313316
"[crates]\n",

src/runner/test.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ fn run_cargo<DB: WriteResults>(
8989
rustflags.push(' ');
9090
rustflags.push_str(tc_rustflags);
9191
}
92+
// Limit debuginfo in an effort to decrease linker peak memory usage, while retaining enough
93+
// information to get useful backtraces.
94+
rustflags.push_str(" -Cdebuginfo=1");
9295

9396
let rustflags_env = if let Some(&"doc") = args.get(0) {
9497
"RUSTDOCFLAGS"
@@ -210,6 +213,7 @@ pub(super) fn run_test<DB: WriteResults>(
210213
);
211214
let sandbox = SandboxBuilder::new()
212215
.memory_limit(Some(ctx.config.sandbox.memory_limit.to_bytes()))
216+
.cpu_limit(Some(f32::from(ctx.config.sandbox.cpu_limit)))
213217
.enable_networking(false);
214218

215219
let krate = &ctx.krate.to_rustwide();
@@ -235,28 +239,51 @@ fn build<DB: WriteResults>(
235239
build_env: &Build,
236240
local_packages_id: &HashSet<PackageId>,
237241
) -> Fallible<()> {
242+
let cpus = ctx.config.sandbox.cpu_limit.to_string();
238243
run_cargo(
239244
ctx,
240245
build_env,
241-
&["build", "--frozen", "--message-format=json"],
246+
&[
247+
"build",
248+
"--frozen",
249+
"--message-format=json",
250+
"--jobs",
251+
&cpus,
252+
],
242253
true,
243254
local_packages_id,
244255
)?;
245256
run_cargo(
246257
ctx,
247258
build_env,
248-
&["test", "--frozen", "--no-run", "--message-format=json"],
259+
&[
260+
"test",
261+
"--frozen",
262+
"--no-run",
263+
"--message-format=json",
264+
"--jobs",
265+
&cpus,
266+
],
249267
true,
250268
local_packages_id,
251269
)?;
252270
Ok(())
253271
}
254272

255273
fn test<DB: WriteResults>(ctx: &TaskCtx<DB>, build_env: &Build) -> Fallible<()> {
274+
let cpus = ctx.config.sandbox.cpu_limit.to_string();
256275
run_cargo(
257276
ctx,
258277
build_env,
259-
&["test", "--frozen"],
278+
&[
279+
"test",
280+
"--frozen",
281+
"--jobs",
282+
&cpus,
283+
"--",
284+
"--test-threads",
285+
&cpus,
286+
],
260287
false,
261288
&HashSet::new(),
262289
)
@@ -299,6 +326,7 @@ pub(super) fn test_check_only<DB: WriteResults>(
299326
build_env: &Build,
300327
local_packages_id: &HashSet<PackageId>,
301328
) -> Fallible<TestResult> {
329+
let cpus = ctx.config.sandbox.cpu_limit.to_string();
302330
if let Err(err) = run_cargo(
303331
ctx,
304332
build_env,
@@ -308,6 +336,8 @@ pub(super) fn test_check_only<DB: WriteResults>(
308336
"--all",
309337
"--all-targets",
310338
"--message-format=json",
339+
"--jobs",
340+
&cpus,
311341
],
312342
true,
313343
local_packages_id,
@@ -323,6 +353,7 @@ pub(super) fn test_clippy_only<DB: WriteResults>(
323353
build_env: &Build,
324354
local_packages_id: &HashSet<PackageId>,
325355
) -> Fallible<TestResult> {
356+
let cpus = ctx.config.sandbox.cpu_limit.to_string();
326357
if let Err(err) = run_cargo(
327358
ctx,
328359
build_env,
@@ -332,6 +363,8 @@ pub(super) fn test_clippy_only<DB: WriteResults>(
332363
"--all",
333364
"--all-targets",
334365
"--message-format=json",
366+
"--jobs",
367+
&cpus,
335368
],
336369
true,
337370
local_packages_id,
@@ -347,6 +380,7 @@ pub(super) fn test_rustdoc<DB: WriteResults>(
347380
build_env: &Build,
348381
local_packages_id: &HashSet<PackageId>,
349382
) -> Fallible<TestResult> {
383+
let cpus = ctx.config.sandbox.cpu_limit.to_string();
350384
let res = run_cargo(
351385
ctx,
352386
build_env,
@@ -356,6 +390,8 @@ pub(super) fn test_rustdoc<DB: WriteResults>(
356390
"--no-deps",
357391
"--document-private-items",
358392
"--message-format=json",
393+
"--jobs",
394+
&cpus,
359395
],
360396
true,
361397
local_packages_id,

tests/check_config/bad-duplicate-crate.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = []
1717

1818
[sandbox]
1919
memory-limit = "1536M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/check_config/bad-missing-crate.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = []
1717

1818
[sandbox]
1919
memory-limit = "1536M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/check_config/bad-missing-repo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = []
1717

1818
[sandbox]
1919
memory-limit = "1536M"
20+
cpu-limit= 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/check_config/good.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = []
1717

1818
[sandbox]
1919
memory-limit = "1536M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/minicrater/blacklist/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local-crates = ["build-pass", "build-fail", "test-fail"]
1818

1919
[sandbox]
2020
memory-limit = "512M"
21+
cpu-limit = 1
2122
build-log-max-size = "2M"
2223
build-log-max-lines = 1000
2324

tests/minicrater/clippy/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = ["build-pass", "clippy-warn"]
1717

1818
[sandbox]
1919
memory-limit = "512M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/minicrater/full/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = []
1717

1818
[sandbox]
1919
memory-limit = "512M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/minicrater/ignore-blacklist/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = ["build-pass", "build-fail", "test-fail"]
1717

1818
[sandbox]
1919
memory-limit = "512M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/minicrater/missing-repo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = []
1717

1818
[sandbox]
1919
memory-limit = "512M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/minicrater/resource-exhaustion/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = ["build-pass", "memory-hungry"]
1717

1818
[sandbox]
1919
memory-limit = "512M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

tests/minicrater/small/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local-crates = ["build-pass", "beta-regression"]
1717

1818
[sandbox]
1919
memory-limit = "512M"
20+
cpu-limit = 1
2021
build-log-max-size = "2M"
2122
build-log-max-lines = 1000
2223

0 commit comments

Comments
 (0)