[go] runtime: improve out-of-memory message when VirtualAlloc fails

340 views
Skip to first unread message

Austin Clements (Gerrit)

unread,
Jul 18, 2017, 11:16:25 AM7/18/17
to Alex Brainman, Ian Lance Taylor, Austin Clements, golang-co...@googlegroups.com

Austin Clements would like Alex Brainman to review this change.

View Change

runtime: improve out-of-memory message when VirtualAlloc fails

Fixes #19514.

Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
---
M src/runtime/mem_windows.go
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/runtime/mem_windows.go b/src/runtime/mem_windows.go
index 2c338c8..c37c82a 100644
--- a/src/runtime/mem_windows.go
+++ b/src/runtime/mem_windows.go
@@ -16,6 +16,9 @@

_PAGE_READWRITE = 0x0004
_PAGE_NOACCESS = 0x0001
+
+ _ERROR_NOT_ENOUGH_MEMORY = 8
+ _ERROR_COMMITMENT_LIMIT = 1455
)

// Don't split the stack as this function may be invoked without a valid G,
@@ -112,7 +115,13 @@
mSysStatInc(sysStat, n)
p := stdcall4(_VirtualAlloc, uintptr(v), n, _MEM_COMMIT, _PAGE_READWRITE)
if p != uintptr(v) {
- print("runtime: VirtualAlloc of ", n, " bytes failed with errno=", getlasterror(), "\n")
- throw("runtime: cannot map pages in arena address space")
+ errno := getlasterror()
+ print("runtime: VirtualAlloc of ", n, " bytes failed with errno=", errno, "\n")
+ switch errno {
+ case _ERROR_NOT_ENOUGH_MEMORY, _ERROR_COMMITMENT_LIMIT:
+ throw("out of memory")
+ default:
+ throw("runtime: cannot map pages in arena address space")
+ }
}
}

To view, visit change 49611. To unsubscribe, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
Gerrit-Change-Number: 49611
Gerrit-PatchSet: 1
Gerrit-Owner: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>

Gobot Gobot (Gerrit)

unread,
Jul 18, 2017, 11:17:19 AM7/18/17
to Austin Clements, Alex Brainman, golang-co...@googlegroups.com

Gobot Gobot posted comments on this change.

View Change

Patch set 1:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=284e5ca7

    To view, visit change 49611. To unsubscribe, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-MessageType: comment
    Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
    Gerrit-Change-Number: 49611
    Gerrit-PatchSet: 1
    Gerrit-Owner: Austin Clements <aus...@google.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Austin Clements <aus...@google.com>
    Gerrit-CC: Gobot Gobot <go...@golang.org>
    Gerrit-Comment-Date: Tue, 18 Jul 2017 15:17:16 +0000
    Gerrit-HasComments: No
    Gerrit-HasLabels: No

    Gobot Gobot (Gerrit)

    unread,
    Jul 18, 2017, 11:27:41 AM7/18/17
    to Austin Clements, Alex Brainman, golang-co...@googlegroups.com

    Gobot Gobot posted comments on this change.

    View Change

    Patch set 1:TryBot-Result +1

    TryBots are happy.

      To view, visit change 49611. To unsubscribe, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-MessageType: comment
      Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
      Gerrit-Change-Number: 49611
      Gerrit-PatchSet: 1
      Gerrit-Owner: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
      Gerrit-Comment-Date: Tue, 18 Jul 2017 15:27:38 +0000
      Gerrit-HasComments: No
      Gerrit-HasLabels: Yes

      Brad Fitzpatrick (Gerrit)

      unread,
      Jul 18, 2017, 12:04:54 PM7/18/17
      to Austin Clements, Brad Fitzpatrick, Gobot Gobot, Alex Brainman, golang-co...@googlegroups.com

      Brad Fitzpatrick posted comments on this change.

      View Change

      Patch set 1:Code-Review +2

        To view, visit change 49611. To unsubscribe, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-MessageType: comment
        Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
        Gerrit-Change-Number: 49611
        Gerrit-PatchSet: 1
        Gerrit-Owner: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Comment-Date: Tue, 18 Jul 2017 16:04:50 +0000
        Gerrit-HasComments: No
        Gerrit-HasLabels: Yes

        Alex Brainman (Gerrit)

        unread,
        Jul 18, 2017, 9:59:07 PM7/18/17
        to Austin Clements, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com

        Alex Brainman posted comments on this change.

        View Change

        Patch set 1:

        (1 comment)

        • File src/runtime/mem_windows.go:

          • Patch Set #1, Line 122: out of memory

            I do not see how "out of memory" error message is better then "cannot map pages in arena address space". Either of them is too general for the user to act upon. Windows memory is a complicated subject, maybe we should not try to be helpful here. We provide error number, that should be enough for the user to get started.

            Maybe we should replace "cannot map pages in arena address space" with "out of memory"?

        To view, visit change 49611. To unsubscribe, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-MessageType: comment
        Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
        Gerrit-Change-Number: 49611
        Gerrit-PatchSet: 1
        Gerrit-Owner: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Comment-Date: Wed, 19 Jul 2017 01:59:02 +0000
        Gerrit-HasComments: Yes
        Gerrit-HasLabels: No

        Austin Clements (Gerrit)

        unread,
        Jul 19, 2017, 10:58:08 AM7/19/17
        to Austin Clements, Alex Brainman, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com

        Austin Clements posted comments on this change.

        View Change

        Patch set 1:

        (1 comment)

          • Understanding "cannot map pages in arena address space" requires a great deal more knowledge of memory management and the internal implementation of Go to understand than "out of memory". "Out of memory" is absolutely actionable, whereas acting on "cannot map pages in arena address space" requires knowing what mapping is, what pages are, what an arena is, what an address space is, and what you can do to free up some of these. Nothing here even say it's about memory (which would at least suggest that maybe you need to free up memory).

          • Maybe we should replace "cannot map pages in arena address space" with "out of memory"?

          • I'd be fine with that if that's a reasonable thing to do. I couldn't find a list of failure modes of VirtualAlloc anywhere, which is why I called out the two that were clearly caused by low memory. We do much the same thing with the POSIX memory interfaces where we give a specific failure for "out of memory" and otherwise a more general error.

        To view, visit change 49611. To unsubscribe, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-MessageType: comment
        Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
        Gerrit-Change-Number: 49611
        Gerrit-PatchSet: 1
        Gerrit-Owner: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Comment-Date: Wed, 19 Jul 2017 14:58:05 +0000
        Gerrit-HasComments: Yes
        Gerrit-HasLabels: No

        Austin Clements (Gerrit)

        unread,
        Jul 20, 2017, 9:00:36 PM7/20/17
        to Austin Clements, golang-...@googlegroups.com, Alex Brainman, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com

        Austin Clements merged this change.

        View Change

        Approvals: Brad Fitzpatrick: Looks good to me, approved Austin Clements: Run TryBots Gobot Gobot: TryBots succeeded
        runtime: improve out-of-memory message when VirtualAlloc fails

        Fixes #19514.

        Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
        Reviewed-on: https://go-review.googlesource.com/49611
        Run-TryBot: Austin Clements <aus...@google.com>
        TryBot-Result: Gobot Gobot <go...@golang.org>
        Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-MessageType: merged
        Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
        Gerrit-Change-Number: 49611
        Gerrit-PatchSet: 2
        Gerrit-Owner: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>

        Alex Brainman (Gerrit)

        unread,
        Jul 26, 2017, 6:50:16 AM7/26/17
        to Austin Clements, Brad Fitzpatrick, Gobot Gobot, golang-co...@googlegroups.com

        Alex Brainman posted comments on this change.

        View Change

        Patch set 1:

        LGTM

        Thank you.

        Alex

        (1 comment)

          • Patch Set #1, Line 122: out of memory

            Understanding "cannot map pages in arena address space" requires a
            great deal more knowledge of memory management and the internal
            implementation of Go to understand than "out of memory".

          • Fair enough.

          • Maybe we should replace "cannot map pages in arena address space"
            with "out of memory"?

            I'd be fine with that if that's a reasonable thing to do.

          • I think it is a reasonable thing to do. As you have explained yourself, "cannot map pages in arena address space" might be confusing for an average programmer.

          • I
            couldn't find a list of failure modes of VirtualAlloc anywhere,

        To view, visit change 49611. To unsubscribe, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-MessageType: comment
        Gerrit-Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e
        Gerrit-Change-Number: 49611
        Gerrit-PatchSet: 1
        Gerrit-Owner: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Comment-Date: Wed, 26 Jul 2017 10:50:09 +0000
        Gerrit-HasComments: Yes
        Gerrit-HasLabels: No
        Reply all
        Reply to author
        Forward
        0 new messages