raulk / go-watchdog

a library to curb OOMs by running Go GC according to a user-defined policy.
Other
80 stars 15 forks source link

Consider using debug.FreeOsMemory() instead of runtime.GC() #11

Open ribasushi opened 3 years ago

ribasushi commented 3 years ago

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.

raulk commented 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.

raulk commented 3 years ago

I don't have the bandwidth for this right now, so feel free to submit a PR. What I would do is: