Skip to content

Commit

Permalink
export jl_gc_set_max_memory (#47545)
Browse files Browse the repository at this point in the history
Also initialize it later, outside option parsing, so that modifying jl_options
before calling jl_init works.
  • Loading branch information
JeffBezanson committed Nov 15, 2022
1 parent 9413050 commit 9b3f5c3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3652,6 +3652,9 @@ void jl_init_thread_heap(jl_ptls_t ptls)
// System-wide initializations
void jl_gc_init(void)
{
if (jl_options.heap_size_hint)
jl_gc_set_max_memory(jl_options.heap_size_hint);

JL_MUTEX_INIT(&heapsnapshot_lock);
JL_MUTEX_INIT(&finalizers_lock);
uv_mutex_init(&gc_cache_lock);
Expand Down Expand Up @@ -3688,7 +3691,8 @@ void jl_gc_init(void)
t_start = jl_hrtime();
}

void jl_gc_set_max_memory(uint64_t max_mem) {
JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem)
{
if (max_mem > 0
&& max_mem < (uint64_t)1 << (sizeof(memsize_t) * 8 - 1)) {
max_total_memory = max_mem;
Expand Down
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
XX(jl_gc_set_cb_pre_gc) \
XX(jl_gc_set_cb_root_scanner) \
XX(jl_gc_set_cb_task_scanner) \
XX(jl_gc_set_max_memory) \
XX(jl_gc_sync_total_bytes) \
XX(jl_gc_total_hrtime) \
XX(jl_gdblookup) \
Expand Down
2 changes: 0 additions & 2 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,6 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
break;
}
jl_options.heap_size_hint = (uint64_t)(value * multiplier);

jl_gc_set_max_memory(jl_options.heap_size_hint);
}
}
if (jl_options.heap_size_hint == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@ JL_DLLEXPORT jl_value_t *jl_gc_allocobj(size_t sz);
JL_DLLEXPORT void *jl_malloc_stack(size_t *bufsz, struct _jl_task_t *owner) JL_NOTSAFEPOINT;
JL_DLLEXPORT void jl_free_stack(void *stkbuf, size_t bufsz);
JL_DLLEXPORT void jl_gc_use(jl_value_t *a);
// Set GC memory trigger in bytes for greedy memory collecting
JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem);

JL_DLLEXPORT void jl_clear_malloc_data(void);

Expand Down
3 changes: 0 additions & 3 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,6 @@ void jl_gc_run_all_finalizers(jl_task_t *ct);
void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task);
void jl_gc_add_finalizer_(jl_ptls_t ptls, void *v, void *f) JL_NOTSAFEPOINT;

// Set GC memory trigger in bytes for greedy memory collecting
void jl_gc_set_max_memory(uint64_t max_mem);

JL_DLLEXPORT void jl_gc_queue_binding(jl_binding_t *bnd) JL_NOTSAFEPOINT;
void gc_setmark_buf(jl_ptls_t ptls, void *buf, uint8_t, size_t) JL_NOTSAFEPOINT;

Expand Down

0 comments on commit 9b3f5c3

Please sign in to comment.