Does increasing gc.setstepmul alone prevent memory exhaustion in Lua's incremental GC?
0 reputation · 26 Aug 2020, 05:31 UTC
0 reputation · 26 Aug 2020, 05:31 UTC
Determine whether tuning only the step multiplier (gc.setstepmul) can keep the incremental garbage collector ahead of rapid table allocation bursts without adjusting the pause ratio (gc.setpause).
The incremental collector interleaves marking and sweeping based on the pause ratio, which defines how much memory may accumulate before a new cycle starts, while the step multiplier controls the amount of work performed per incremental step. If allocation rate exceeds the combined effect of these two parameters, memory may grow unchecked, yet it is unclear whether raising the step multiplier alone compensates for a high pause value or if both must be adjusted together.
gc.setstepmul and the effective reclamation rate when gc.setpause remains at its default?35275 reputation · 26 Aug 2020, 07:26 UTC
No. Increasing gc.setstepmul alone does not prevent memory exhaustion when gc.setpause remains at its default. Step multiplier changes how much work is done per incremental step; it does not change when a new GC cycle is allowed to start. With a high pause ratio the collector permits the heap to grow substantially between cycles, and a larger stepmul cannot close a sustained allocation-rate gap by itself.
gc.setpause sets the pause ratio that determines how much memory may be allocated before a new incremental cycle begins. Default is commonly 200 in Lua 5.2+ incremental collector implementations.gc.setstepmul sets the step multiplier that controls the amount of GC work performed per incremental step relative to allocation.With default pause, the collector allows a large accumulation of garbage between cycles. Raising stepmul increases work per step and can make steps more frequent in practice, but the cycle start condition is still governed by pause. If allocation bursts are sustained and exceed the reclamation rate that stepmul can provide, heap size will continue to grow between cycles.
Very high stepmul values also increase CPU time spent in GC steps. When step execution time approaches the allocation quantum, effective throughput falls and latency can increase, which can negate the benefit in high-allocation scenarios.
Empirical tuning for rapid table allocation bursts typically requires adjusting both pause and stepmul together. Stepmul alone is insufficient for extreme or sustained bursts.
-- sample monitoring loop
local before = collectgarbage('count')
-- run allocation burst
local after = collectgarbage('count')
print(after - before)
collectgarbage('setstepmul', 300), and re-measure heap growth and CPU time.One missing diagnostic detail that changes the recommendation: the Lua version you are running and whether the allocation burst is sustained over seconds or transient spikes. Version determines exact defaults and formulas, and burst duration determines whether pause adjustment is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.