New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syscall: memoize convT2I from creating errors in WSARecv, WSASend, etc? #16988
Comments
Hi brad, Thanks for your changing of the title. Yes, the conversion of error code e1 to error should not be repeated. "A blocking operation is currently executing. Windows Sockets only allows a single blocking operation—per- task or thread—to be outstanding, and if any other function call is made (whether or not it references that or any other socket) the function fails with the WSAEINPROGRESS error." This might be the cause. |
These come from func (r *Rets) useLongHandleErrorCode(retvar string) string {
const code = `if %s {
if e1 != 0 {
err = error(e1)
} else {
err = %sEINVAL
}
}`
cond := retvar + " == 0"
if r.FailCond != "" {
cond = strings.Replace(r.FailCond, "failretval", retvar, 1)
}
return fmt.Sprintf(code, cond, syscalldot())
} Maybe we should change |
SGTM. IIRC we did something similar on the *nix side to remove allocations for common, static errors. |
CL https://golang.org/cl/28484 mentions this issue. |
Hi Brad, Sorry to have misled you, but the correct error code here is not WSAEINPROGRESS, it is WSA_IO_PENDING (code 997), see: https://msdn.microsoft.com/en-us/library/ms740668(v=vs.85).aspx#WSA_IO_PENDING I apologize for the misleading again! |
I will look into this. Alex |
What is "common" here? Can we add all that run of all.bat reports? Would adding them all slow things down in errnoErr?
How would I do that? Write some code in runtime to dump all encountered in errnoErr errors into a global file? Then sort and uniq? Alex |
Or the top N frequently occurring. Use some judgement. I don't know.
It shouldn't. Let that be the compiler's problem. Switching on ints is on the TODO list to optimize more anyway. Plus: it's an error path. How fast does it have to be?
Sounds good. |
I was hoping you would come up with some inventive way. Like me using video recorders or something. :-( Alex |
CL https://golang.org/cl/28990 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7 windows/amd64
What operating system and processor architecture are you using (
go env
)?Windows 7 SP1 Ultimate X64, Intel i7-3770K + Z77 chipset, go env prints:
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=
set GORACE=
set GOROOT=D:\port\go
set GOTOOLDIR=D:\port\go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\diogin\AppData\Local\Temp\go-build701008446=/tmp/go
-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
What did you do?
A runnable server.go is at https://play.golang.org/p/Jg7xSHU3B4
A runnable client.go is at https://play.golang.org/p/8u0y0j9IHh
First, build and run server.go, and then client.go.
After the server prints EOF, run:
go tool pprof -alloc_objects server.exe heap.pprof
Then, run top in pprof:
(pprof) top
327685 of 327685 total ( 100%)
Dropped 3 nodes (cum <= 1638)
flat flat% sum% cum cum%
327685 100% 100% 327685 100% syscall.WSARecv
0 0% 100% 327685 100% main.main
0 0% 100% 327685 100% net.(_conn).Read
0 0% 100% 327685 100% net.(_ioSrv).ExecIO
0 0% 100% 327685 100% net.(_netFD).Read
0 0% 100% 327685 100% net.(_netFD).Read.func1
0 0% 100% 327685 100% runtime.goexit
0 0% 100% 327685 100% runtime.main
We see syscall.WSARecv allocates a lot of memory. Then list WS:
(pprof) list WS
Total: 327685
ROUTINE ======================== syscall.WSARecv in D:/port/go/src/syscall/zsyscall_windows.go
327685 327685 (flat, cum) 100% of Total
. . 1518:
. . 1519:func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overl
apped, croutine *byte) (err error) {
. . 1520: r1, _, e1 := Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(
bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Poi
nter(croutine)), 0, 0)
. . 1521: if r1 == socket_error {
. . 1522: if e1 != 0 {
327685 327685 1523: err = error(e1)
. . 1524: } else {
. . 1525: err = EINVAL
. . 1526: }
. . 1527: }
. . 1528: return
And disasm WS:
So line 1523 allocates a lot of memory, only to make a useless error, which means "overlapped i/o operation is in progress".
What did you expect to see?
The memory consumption don't increase.
What did you see instead?
It allocates a lot of memory.
The text was updated successfully, but these errors were encountered: