Skip to content

Commit 990c21a

Browse files
Christine FloodChristine H. FloodvtjnashDilumAluthge
authored
Updated 32 bit heuristics (#44805)
Co-authored-by: Christine H. Flood <[email protected]> Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Dilum Aluthge <[email protected]>
1 parent 0c2722e commit 990c21a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/gc.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,20 @@ static void gc_sweep_foreign_objs(void)
585585
// GC knobs and self-measurement variables
586586
static int64_t last_gc_total_bytes = 0;
587587

588+
// max_total_memory is a suggestion. We try very hard to stay
589+
// under this limit, but we will go above it rather than halting.
588590
#ifdef _P64
589591
#define default_collect_interval (5600*1024*sizeof(void*))
590592
static size_t max_collect_interval = 1250000000UL;
593+
// Eventually we can expose this to the user/ci.
594+
static uint64_t max_total_memory = (uint64_t) 2 * 1024 * 1024 * 1024 * 1024 * 1024;
591595
#else
592596
#define default_collect_interval (3200*1024*sizeof(void*))
593597
static size_t max_collect_interval = 500000000UL;
598+
// Work really hard to stay within 2GB
599+
// Alternative is to risk running out of address space
600+
// on 32 bit architectures.
601+
static uint32_t max_total_memory = (uint32_t) 2 * 1024 * 1024 * 1024;
594602
#endif
595603

596604
// global variables for GC stats
@@ -3158,6 +3166,13 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
31583166
gc_num.interval = max_collect_interval;
31593167
}
31603168
}
3169+
3170+
// If the live data outgrows the suggested max_total_memory
3171+
// we keep going with minimum intervals and full gcs until
3172+
// we either free some space or get an OOM error.
3173+
if (live_bytes > max_total_memory) {
3174+
sweep_full = 1;
3175+
}
31613176
if (gc_sweep_always_full) {
31623177
sweep_full = 1;
31633178
}
@@ -3237,6 +3252,17 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
32373252
if (gc_num.interval < default_collect_interval) gc_num.interval = default_collect_interval;
32383253
}
32393254

3255+
// We need this for 32 bit but will be useful to set limits on 64 bit
3256+
if (gc_num.interval + live_bytes > max_total_memory) {
3257+
if (live_bytes < max_total_memory) {
3258+
gc_num.interval = max_total_memory - live_bytes;
3259+
} else {
3260+
// We can't stay under our goal so let's go back to
3261+
// the minimum interval and hope things get better
3262+
gc_num.interval = default_collect_interval;
3263+
}
3264+
}
3265+
32403266
gc_time_summary(sweep_full, t_start, gc_end_t, gc_num.freed, live_bytes, gc_num.interval, pause);
32413267

32423268
prev_sweep_full = sweep_full;

0 commit comments

Comments
 (0)