Skip to content

cap the number of GC threads to number of cpu cores #52192

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

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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