File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -681,6 +681,7 @@ void jl_init_threading(void)
681681 }
682682 }
683683
684+ int cpu = jl_cpu_threads ();
684685 jl_n_markthreads = jl_options .nmarkthreads - 1 ;
685686 jl_n_sweepthreads = jl_options .nsweepthreads ;
686687 if (jl_n_markthreads == -1 ) { // --gcthreads not specified
@@ -709,8 +710,20 @@ void jl_init_threading(void)
709710 else {
710711 jl_n_markthreads = (nthreads / 2 ) - 1 ;
711712 }
713+ // if `--gcthreads` or ENV[NUM_GCTHREADS_NAME] was not specified,
714+ // cap the number of threads that may run the mark phase to
715+ // the number of CPU cores
716+ if (jl_n_markthreads + 1 >= cpu ) {
717+ jl_n_markthreads = cpu - 1 ;
718+ }
712719 }
713720 }
721+ // warn the user if they try to run with a number
722+ // of GC threads which is larger than the number
723+ // of physical cores
724+ if (jl_n_markthreads + 1 > cpu ) {
725+ jl_safe_printf ("WARNING: running Julia with %d GC threads on %d CPU cores\n" , jl_n_markthreads + 1 , cpu );
726+ }
714727 int16_t ngcthreads = jl_n_markthreads + jl_n_sweepthreads ;
715728
716729 jl_all_tls_states_size = nthreads + nthreadsi + ngcthreads ;
You can’t perform that action at this time.
0 commit comments