Skip to content

Commit

Permalink
Fix heapsize hint and use a line for max memory (#48747)
Browse files Browse the repository at this point in the history
* Fix heapsize hint and use a line
so that large machines utilize more of their ram
  • Loading branch information
gbaraldi committed Mar 3, 2023
1 parent 48b4caa commit 51db8af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3228,8 +3228,6 @@ 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);
Expand All @@ -3253,8 +3251,15 @@ void jl_gc_init(void)
uint64_t constrained_mem = uv_get_constrained_memory();
if (constrained_mem > 0 && constrained_mem < total_mem)
total_mem = constrained_mem;
max_total_memory = total_mem / 10 * 6;
double percent;
if (total_mem < 128e9)
percent = total_mem * 2.34375e-12 + 0.6; // 60% at 0 gigs and 90% at 128 to not
else // overcommit too much on memory contrained devices
percent = 0.9;
max_total_memory = total_mem * percent;
#endif
if (jl_options.heap_size_hint)
jl_gc_set_max_memory(jl_options.heap_size_hint);

t_start = jl_hrtime();
}
Expand All @@ -3267,6 +3272,11 @@ JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem)
}
}

JL_DLLEXPORT uint64_t jl_gc_get_max_memory(void)
{
return max_total_memory;
}

// callback for passing OOM errors from gmp
JL_DLLEXPORT void jl_throw_out_of_memory_error(void)
{
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 @@ -172,6 +172,7 @@
XX(jl_gc_external_obj_hdr_size) \
XX(jl_gc_find_taggedvalue_pool) \
XX(jl_gc_get_total_bytes) \
XX(jl_gc_get_max_memory) \
XX(jl_gc_internal_obj_base_ptr) \
XX(jl_gc_is_enabled) \
XX(jl_gc_live_bytes) \
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ 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 uint64_t jl_gc_get_max_memory(void);

JL_DLLEXPORT void jl_clear_malloc_data(void);

Expand Down
2 changes: 2 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -901,4 +901,6 @@ end
@test lines[3] == "foo"
@test lines[4] == "bar"
end
#heap-size-hint
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=500M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "524288000"
end

0 comments on commit 51db8af

Please sign in to comment.