Skip to content

Commit 17679c7

Browse files
authored
Rollup merge of rust-lang#39583 - michaelwoerister:limit-llvm-threads, r=nikomatsakis
back: Limit the number of LLVM worker threads. This should fix issue rust-lang#39568. Also see rust-lang#39280. r? @nikomatsakis
2 parents 3189ee3 + fa0a728 commit 17679c7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/librustc_trans/back/write.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use errors::emitter::Emitter;
2727
use syntax_pos::MultiSpan;
2828
use context::{is_pie_binary, get_reloc_model};
2929

30+
use std::cmp;
3031
use std::ffi::CString;
3132
use std::fs;
3233
use std::path::{Path, PathBuf};
@@ -754,10 +755,13 @@ pub fn run_passes(sess: &Session,
754755
}
755756

756757
// Process the work items, optionally using worker threads.
757-
// NOTE: This code is not really adapted to incremental compilation where
758-
// the compiler decides the number of codegen units (and will
759-
// potentially create hundreds of them).
760-
let num_workers = work_items.len() - 1;
758+
// NOTE: We are hardcoding a limit of worker threads for now. With
759+
// incremental compilation we can run into situations where we would
760+
// open hundreds of threads otherwise -- which can make things slower
761+
// if things don't fit into memory anymore, or can cause the compiler
762+
// to crash because of too many open file handles. See #39280 for
763+
// some discussion on how to improve this in the future.
764+
let num_workers = cmp::min(work_items.len() - 1, 32);
761765
if num_workers <= 1 {
762766
run_work_singlethreaded(sess, &trans.exported_symbols, work_items);
763767
} else {

0 commit comments

Comments
 (0)