File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 33#include "gc.h"
44#include "julia_gcext.h"
55#include "julia_assert.h"
6+ #ifdef __GLIBC__
7+ #include <malloc.h> // for malloc_trim
8+ #endif
69
710#ifdef __cplusplus
811extern "C" {
@@ -568,6 +571,10 @@ static int prev_sweep_full = 1;
568571// Full collection heuristics
569572static int64_t live_bytes = 0 ;
570573static int64_t promoted_bytes = 0 ;
574+ #ifdef __GLIBC__
575+ // maxrss at last malloc_trim
576+ static int64_t last_trim_maxrss = 0 ;
577+ #endif
571578
572579static int64_t last_full_live_ub = 0 ;
573580static int64_t last_full_live_est = 0 ;
@@ -2725,6 +2732,8 @@ static void jl_gc_queue_bt_buf(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp
27252732 }
27262733}
27272734
2735+ size_t jl_maxrss (void );
2736+
27282737// Only one thread should be running in this function
27292738static int _jl_gc_collect (jl_ptls_t ptls , int full )
27302739{
@@ -2883,6 +2892,18 @@ static int _jl_gc_collect(jl_ptls_t ptls, int full)
28832892 }
28842893 }
28852894
2895+ #ifdef __GLIBC__
2896+ if (sweep_full ) {
2897+ // issue #30653
2898+ // empirically, the malloc runaway seemed to occur within a growth gap
2899+ // of about 20-25%
2900+ if (jl_maxrss () > (last_trim_maxrss /4 )* 5 ) {
2901+ malloc_trim (0 );
2902+ last_trim_maxrss = jl_maxrss ();
2903+ }
2904+ }
2905+ #endif
2906+
28862907 uint64_t gc_end_t = jl_hrtime ();
28872908 uint64_t pause = gc_end_t - t0 ;
28882909 gc_final_pause_end (t0 , gc_end_t );
You can’t perform that action at this time.
0 commit comments