From f86dd3c86a93c6c9d969ffec23426450f22e7464 Mon Sep 17 00:00:00 2001 From: kpamnany Date: Tue, 21 Jun 2022 14:31:46 -0400 Subject: [PATCH 1/2] Bug fix for `max_collect_interval` computation (#45727) Currently constrained to `totalmem / ncores / 2` for `_P64` which results in a very short collect interval when you're running with a smaller number of threads on a machine with many cores. Changes this to `totalmem / nthreads / 2` which, for two of our tests, resulted in 40% and 60% runtime reduction (!!) as well as GC time reduction from 46% to 10% and 64% to 11%. --- src/gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gc.c b/src/gc.c index 6942d153616b9..97669e0acfe61 100644 --- a/src/gc.c +++ b/src/gc.c @@ -3410,12 +3410,12 @@ void jl_gc_init(void) gc_num.allocd = 0; #ifdef _P64 - // on a big memory machine, set max_collect_interval to totalmem / ncores / 2 + // on a big memory machine, set max_collect_interval to totalmem / nthreads / 2 uint64_t total_mem = uv_get_total_memory(); uint64_t constrained_mem = uv_get_constrained_memory(); if (constrained_mem > 0 && constrained_mem < total_mem) total_mem = constrained_mem; - size_t maxmem = total_mem / jl_cpu_threads() / 2; + size_t maxmem = total_mem / jl_n_threads / 2; if (maxmem > max_collect_interval) max_collect_interval = maxmem; #endif From 42db85ff7527ead2f7e9716e37009823153da592 Mon Sep 17 00:00:00 2001 From: K Pamnany Date: Tue, 5 Jul 2022 09:32:45 -0400 Subject: [PATCH 2/2] Move GC init after threading init To allow use of `jl_n_threads` in GC initialization. --- src/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index 98d5081c1daaf..d2c76bac404e7 100644 --- a/src/init.c +++ b/src/init.c @@ -686,10 +686,10 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel) } jl_init_runtime_ccall(); - jl_gc_init(); jl_init_tasks(); jl_init_threading(); + jl_gc_init(); jl_ptls_t ptls = jl_init_threadtls(0); // warning: this changes `jl_current_task`, so be careful not to call that from this function jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi);