Skip to content

Commit

Permalink
cap the number of GC threads to number of cpu cores
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Nov 16, 2023
1 parent 4689850 commit 303bbf7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ void jl_init_threading(void)
}
}

int cpu = jl_cpu_threads();
jl_n_markthreads = jl_options.nmarkthreads - 1;
jl_n_sweepthreads = jl_options.nsweepthreads;
if (jl_n_markthreads == -1) { // --gcthreads not specified
Expand Down Expand Up @@ -709,8 +710,20 @@ void jl_init_threading(void)
else {
jl_n_markthreads = (nthreads / 2) - 1;
}
// if `--gcthreads` or ENV[NUM_GCTHREADS_NAME] was not specified,
// cap the number of threads that may run the mark phase to
// the number of CPU cores
if (jl_n_markthreads + 1 >= cpu) {
jl_n_markthreads = cpu - 1;
}
}
}
// warn the user if they try to run with a number
// of GC threads which is larger than the number
// of physical cores
if (jl_n_markthreads + 1 > cpu) {
jl_safe_printf("WARNING: running Julia with %d GC threads on %d CPU cores\n", jl_n_markthreads + 1, cpu);
}
int16_t ngcthreads = jl_n_markthreads + jl_n_sweepthreads;

jl_all_tls_states_size = nthreads + nthreadsi + ngcthreads;
Expand Down

0 comments on commit 303bbf7

Please sign in to comment.