force garbage collect before crash

130 views
Skip to first unread message

robert engels

unread,
Oct 18, 2020, 4:24:50 PM10/18/20
to golang-nuts
Hi all,

If I set a low process memory limit, and then the OS refuses to grant more memory to a malloc request,. will the Go runtime “stop the world” and attempt a full garbage collection and try to get the memory from the heap and then only crashing the process if it can’t?

I understand that the “pacing” should limit (eliminate?) this situation, but I am thinking in cases when the heuristics don’t match the immediate allocations it would be beneficial.

Thanks.

Ian Lance Taylor

unread,
Oct 18, 2020, 10:13:58 PM10/18/20
to robert engels, golang-nuts
On Sun, Oct 18, 2020 at 1:24 PM robert engels <ren...@ix.netcom.com> wrote:
>
> If I set a low process memory limit, and then the OS refuses to grant more memory to a malloc request,. will the Go runtime “stop the world” and attempt a full garbage collection and try to get the memory from the heap and then only crashing the process if it can’t?
>
> I understand that the “pacing” should limit (eliminate?) this situation, but I am thinking in cases when the heuristics don’t match the immediate allocations it would be beneficial.

It does not work that way today, no.

The current Go memory allocator allocates address space and then
expects that address space to be available. Typical GNU/Linux systems
use overcommit, so there is often no system call reporting that memory
could not be obtained; instead, there is a SIGBUS signal when the
program first writes to a page that the kernel can no longer supply.
It might be tricky to safely run a garbage collection and then retry
the write.

Ian

Robert Engels

unread,
Oct 18, 2020, 11:54:39 PM10/18/20
to Ian Lance Taylor, golang-nuts
Makes sense. Thanks.

> On Oct 18, 2020, at 9:13 PM, Ian Lance Taylor <ia...@golang.org> wrote:
Reply all
Reply to author
Forward
0 new messages