In Go 1.12, we changed the runtime to use MADV_FREE when available on Linux (falling back to MADV_DONTNEED) in CL 135395 to address issue #23687. While MADV_FREE is somewhat faster than MADV_DONTNEED, it doesn't affect many of the statistics that MADV_DONTNEED does until the memory is actually reclaimed. This generally leads to poor user experience, like confusing stats in top and other monitoring tools; and bad integration with management systems that respond to memory usage.
We've seen numerous issues about this user experience, including #41818, #39295, #37585, #33376, and #30904, many questions on Go mailing lists, and requests for mechanisms to change this behavior at run-time, such as #40870. There are also issues that may be a result of this, but root-causing it can be difficult, such as #41444 and #39174. And there's some evidence it may even be incompatible with Android's process management in #37569.
I propose we change the default to prefer MADV_DONTNEED over MADV_FREE, to favor user-friendliness and minimal surprise over performance. I think it's become clear that Linux's implementation of MADV_FREE ultimately doesn't meet our needs. We've also made many improvements to the scavenger since Go 1.12. In particular, it is now far more prompt and it is self-paced, so it will simply trickle memory back to the system a little more slowly with this change.
/cc @mknyszek @rsc
In Go 1.12, we changed the runtime to use
MADV_FREEwhen available on Linux (falling back toMADV_DONTNEED) in CL 135395 to address issue #23687. WhileMADV_FREEis somewhat faster thanMADV_DONTNEED, it doesn't affect many of the statistics thatMADV_DONTNEEDdoes until the memory is actually reclaimed. This generally leads to poor user experience, like confusing stats intopand other monitoring tools; and bad integration with management systems that respond to memory usage.We've seen numerous issues about this user experience, including #41818, #39295, #37585, #33376, and #30904, many questions on Go mailing lists, and requests for mechanisms to change this behavior at run-time, such as #40870. There are also issues that may be a result of this, but root-causing it can be difficult, such as #41444 and #39174. And there's some evidence it may even be incompatible with Android's process management in #37569.
I propose we change the default to prefer
MADV_DONTNEEDoverMADV_FREE, to favor user-friendliness and minimal surprise over performance. I think it's become clear that Linux's implementation ofMADV_FREEultimately doesn't meet our needs. We've also made many improvements to the scavenger since Go 1.12. In particular, it is now far more prompt and it is self-paced, so it will simply trickle memory back to the system a little more slowly with this change./cc @mknyszek @rsc