Skip to content

Commit 9ced070

Browse files
gbaraldiKristofferC
authored andcommitted
Fix heapsize hint and use a line for max memory (#48747)
* Fix heapsize hint and use a line so that large machines utilize more of their ram (cherry picked from commit 51db8af)
1 parent e6249e7 commit 9ced070

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/gc.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3680,8 +3680,15 @@ void jl_gc_init(void)
36803680
uint64_t constrained_mem = uv_get_constrained_memory();
36813681
if (constrained_mem > 0 && constrained_mem < total_mem)
36823682
total_mem = constrained_mem;
3683-
max_total_memory = total_mem / 10 * 6;
3683+
double percent;
3684+
if (total_mem < 128e9)
3685+
percent = total_mem * 2.34375e-12 + 0.6; // 60% at 0 gigs and 90% at 128 to not
3686+
else // overcommit too much on memory contrained devices
3687+
percent = 0.9;
3688+
max_total_memory = total_mem * percent;
36843689
#endif
3690+
if (jl_options.heap_size_hint)
3691+
jl_gc_set_max_memory(jl_options.heap_size_hint);
36853692

36863693
jl_gc_mark_sp_t sp = {NULL, NULL, NULL, NULL};
36873694
gc_mark_loop(NULL, sp);
@@ -3695,6 +3702,11 @@ void jl_gc_set_max_memory(uint64_t max_mem) {
36953702
}
36963703
}
36973704

3705+
JL_DLLEXPORT uint64_t jl_gc_get_max_memory(void)
3706+
{
3707+
return max_total_memory;
3708+
}
3709+
36983710
// callback for passing OOM errors from gmp
36993711
JL_DLLEXPORT void jl_throw_out_of_memory_error(void)
37003712
{

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
XX(jl_gc_external_obj_hdr_size) \
174174
XX(jl_gc_find_taggedvalue_pool) \
175175
XX(jl_gc_get_total_bytes) \
176+
XX(jl_gc_get_max_memory) \
176177
XX(jl_gc_internal_obj_base_ptr) \
177178
XX(jl_gc_is_enabled) \
178179
XX(jl_gc_live_bytes) \

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_allocobj(size_t sz);
925925
JL_DLLEXPORT void *jl_malloc_stack(size_t *bufsz, struct _jl_task_t *owner) JL_NOTSAFEPOINT;
926926
JL_DLLEXPORT void jl_free_stack(void *stkbuf, size_t bufsz);
927927
JL_DLLEXPORT void jl_gc_use(jl_value_t *a);
928+
JL_DLLEXPORT uint64_t jl_gc_get_max_memory(void);
928929

929930
JL_DLLEXPORT void jl_clear_malloc_data(void);
930931

test/cmdlineargs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,4 +827,6 @@ end
827827
@test lines[3] == "foo"
828828
@test lines[4] == "bar"
829829
end
830+
#heap-size-hint
831+
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=500M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "524288000"
830832
end

0 commit comments

Comments
 (0)