Open ribasushi opened 3 years ago
Go 1.16 uses MADV_DONTNEED by default, which should (in theory) returned memory quicker to the OS. That said, I'm happy putting this behind an env var feature flag, because it can cause memory fragmentation in the long run, so it should be used with care.
I don't have the bandwidth for this right now, so feel free to submit a PR. What I would do is:
var ReleaseFn func() = runtime.GC
debug.FreeOSMemory
if env HEAPDOG_FREEOSMEMORY=1
.runtime.GC()
with ReleaseFn()
.
go-watchdog currently uses runtime.GC(), which does force an internal GC run but does not immediately force OS-visible memory release. Replacing that line with
debug.FreeOsMemory()
is likely to lead to less frequent OOM-killer sprees and to better observability by monitoring tools etc.