From 3f7742944bfc8f22cc59cce922d187d6ebc17dbe Mon Sep 17 00:00:00 2001 From: krasow Date: Fri, 5 Jun 2026 15:23:11 -0500 Subject: [PATCH 1/2] update GC memory.jl to only trigger if memory pressure is actually changing between GC iterations. --- src/memory.jl | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/memory.jl b/src/memory.jl index ca28d07f..f996c258 100644 --- a/src/memory.jl +++ b/src/memory.jl @@ -16,6 +16,11 @@ const current_host_bytes = Atomic{Int64}(0) # predicted host allocations const soft_frac = Ref{Float64}(0.80) const hard_frac = Ref{Float64}(0.90) const AUTO_GC_ENABLE = Ref{Bool}(false) +# memory measured right after the last GC +const post_gc_device_bytes = Atomic{Int64}(0) +const post_gc_host_bytes = Atomic{Int64}(0) +# how much new memory must accumulate before GC fires again +const gc_hysteresis_frac = Ref{Float64}(0.05) @doc""" init_gc!() @@ -90,15 +95,31 @@ end function maybe_collect() host_bytes = current_host_bytes[] device_bytes = current_device_bytes[] - if host_bytes > hard_limit() || device_bytes > hard_limit(; host=false) - # Aggressive - GC.gc(true) - recalibrate_allocator!() - elseif host_bytes > soft_limit() || device_bytes > soft_limit(; host=false) - # Gentle - GC.gc(false) - recalibrate_allocator!() + + # minimum growth above the post-GC floor needed to re-collect + dev_floor = post_gc_device_bytes[] + host_floor = post_gc_host_bytes[] + dev_delta = Int(round(gc_hysteresis_frac[] * total_device_bytes[])) + host_delta = Int(round(gc_hysteresis_frac[] * total_host_bytes[])) + grew = device_bytes > dev_floor + dev_delta || host_bytes > host_floor + host_delta + + if device_bytes > hard_limit(; host=false) || host_bytes > hard_limit() + grew && _collect!(true) + elseif device_bytes > soft_limit(; host=false) || host_bytes > soft_limit() + grew && _collect!(false) + else + # reset floors so the next spike is caught immediately + atomic_xchg!(post_gc_device_bytes, 0) + atomic_xchg!(post_gc_host_bytes, 0) end return nothing end + +function _collect!(full::Bool) + GC.gc(full) + recalibrate_allocator!() + atomic_xchg!(post_gc_device_bytes, current_device_bytes[]) + atomic_xchg!(post_gc_host_bytes, current_host_bytes[]) + return nothing +end From 16e663172f36bbbeeeed64682ac0bc5748ff567f Mon Sep 17 00:00:00 2001 From: David Krasowska Date: Fri, 5 Jun 2026 15:49:20 -0500 Subject: [PATCH 2/2] retrigger CI --- src/memory.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/memory.jl b/src/memory.jl index f996c258..2bf447dc 100644 --- a/src/memory.jl +++ b/src/memory.jl @@ -16,6 +16,7 @@ const current_host_bytes = Atomic{Int64}(0) # predicted host allocations const soft_frac = Ref{Float64}(0.80) const hard_frac = Ref{Float64}(0.90) const AUTO_GC_ENABLE = Ref{Bool}(false) + # memory measured right after the last GC const post_gc_device_bytes = Atomic{Int64}(0) const post_gc_host_bytes = Atomic{Int64}(0)