Austin Clements would like Alex Brainman to review this 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.
Gobot Gobot posted comments on this change.
Patch set 1:
TryBots beginning. Status page: https://farmer.golang.org/try?commit=284e5ca7
Gobot Gobot posted comments on this change.
Patch set 1:TryBot-Result +1
TryBots are happy.
Brad Fitzpatrick posted comments on this change.
Patch set 1:Code-Review +2
Alex Brainman posted comments on this 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.
Austin Clements posted comments on this change.
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". "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.
Austin Clements merged this change.
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>
Alex Brainman posted comments on this 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,
Normally errors are explained in the API description, but https://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx does not mention errors except ERROR_INVALID_ADDRESS. Alternatively you could call Windows FormatMessage to convert error number into an error message string https://github.com/golang/go/blob/master/src/syscall/syscall_windows.go#L90 But I am hesitant to complicate this code, especially since process memory might be low at that time.
To view, visit change 49611. To unsubscribe, visit settings.