Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Issue 12418043: code review 12418043: net: add special netFD mutex (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 7 months ago by dvyukov
Modified:
11 years, 7 months ago
Reviewers:
iant, bradfitz
CC:
golang-dev, bradfitz, brainman, iant, mikio
Visibility:
Public.

Description

net: add special netFD mutex The mutex, fdMutex, handles locking and lifetime of sysfd, and serializes Read and Write methods. This allows to strip 2 sync.Mutex.Lock calls, 2 sync.Mutex.Unlock calls, 1 defer and some amount of misc overhead from every network operation. On linux/amd64, Intel E5-2690: benchmark old ns/op new ns/op delta BenchmarkTCP4Persistent 9595 9454 -1.47% BenchmarkTCP4Persistent-2 8978 8772 -2.29% BenchmarkTCP4ConcurrentReadWrite 4900 4625 -5.61% BenchmarkTCP4ConcurrentReadWrite-2 2603 2500 -3.96% In general it strips 70-500 ns from every network operation depending on processor model. On my relatively new E5-2690 it accounts to ~5% of network op cost. Fixes issue 6074.

Patch Set 1 #

Patch Set 2 : diff -r bf1cd157b3e0 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r bf1cd157b3e0 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r adc2b4f10096 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 5 : diff -r adc2b4f10096 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 6 : diff -r 01d672e76b57 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 7 : diff -r 50c9f3544eed https://go.googlecode.com/hg/ #

Patch Set 8 : diff -r 2585605c42c0 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 9 : diff -r 1169c3ec0059 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 10 : diff -r 1169c3ec0059 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 11 : diff -r 1169c3ec0059 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 12 : diff -r 1169c3ec0059 https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 24

Patch Set 13 : diff -r 97ea81ad7455 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 14 : diff -r 97ea81ad7455 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 15 : diff -r 97ea81ad7455 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 16 : diff -r 23e06fccd3b9 https://go.googlecode.com/hg/ #

Total comments: 13

Patch Set 17 : diff -r 70d8d820bfe6 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 18 : diff -r 70d8d820bfe6 https://go.googlecode.com/hg/ #

Patch Set 19 : diff -r 21ae2c5817da https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 8

Patch Set 20 : diff -r 5a51d54e34bb https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 21 : diff -r 5a51d54e34bb https://dvyukov%40google.com@code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+553 lines, -179 lines) Patch
A src/pkg/net/fd_mutex.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 chunk +184 lines, -0 lines 0 comments Download
A src/pkg/net/fd_mutex_test.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +186 lines, -0 lines 0 comments Download
M src/pkg/net/fd_poll_runtime.go View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/fd_unix.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 13 chunks +69 lines, -66 lines 0 comments Download
M src/pkg/net/fd_windows.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 11 chunks +69 lines, -65 lines 0 comments Download
M src/pkg/net/sendfile_freebsd.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 chunk +2 lines, -4 lines 0 comments Download
M src/pkg/net/sendfile_linux.go View 1 2 3 1 chunk +2 lines, -4 lines 0 comments Download
M src/pkg/net/sendfile_windows.go View 1 2 3 4 5 6 1 chunk +3 lines, -4 lines 0 comments Download
M src/pkg/net/sockopt_posix.go View 1 2 3 4 5 6 7 8 4 chunks +4 lines, -4 lines 0 comments Download
M src/pkg/net/sockoptip_bsd.go View 1 2 3 4 5 6 7 8 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/net/sockoptip_linux.go View 1 2 3 4 5 6 7 8 9 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/net/sockoptip_posix.go View 1 2 3 4 5 6 7 8 4 chunks +4 lines, -4 lines 0 comments Download
M src/pkg/net/sockoptip_windows.go View 1 2 3 4 5 6 7 8 9 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/net/tcpsockopt_darwin.go View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/tcpsockopt_openbsd.go View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/tcpsockopt_posix.go View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/tcpsockopt_unix.go View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/tcpsockopt_windows.go View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/mgc0.c View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/runtime/mprof.goc View 1 2 3 4 5 6 7 8 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/runtime/netpoll.goc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +8 lines, -0 lines 0 comments Download
M src/pkg/runtime/proc.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/race.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/runtime.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/sema.goc View 1 2 3 4 5 6 7 8 3 chunks +3 lines, -9 lines 0 comments Download

Messages

Total messages: 21
dvyukov
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://dvyukov%40google.com@code.google.com/p/go/
11 years, 7 months ago (2013-08-06 18:32:59 UTC) #1
dvyukov
If we generally agree on this, then 2 refactorings can go separately (the first is ...
11 years, 7 months ago (2013-08-06 18:35:53 UTC) #2
dvyukov
Just in case, if you are not sure where to start :) start at fd_mutex.go ...
11 years, 7 months ago (2013-08-06 19:11:18 UTC) #3
bradfitz
Is this worse on ARM, with the 64-bit atomics? On Tue, Aug 6, 2013 at ...
11 years, 7 months ago (2013-08-06 19:13:45 UTC) #4
dvyukov
On Tue, Aug 6, 2013 at 11:13 PM, Brad Fitzpatrick <bradfitz@golang.org> wrote: > Is this ...
11 years, 7 months ago (2013-08-06 20:11:53 UTC) #5
brainman
Sounds like a good idea to me. Makes all different OSes to behave the same. ...
11 years, 7 months ago (2013-08-07 00:02:17 UTC) #6
iant
https://codereview.appspot.com/12418043/diff/27001/src/pkg/net/fd_mutex.go File src/pkg/net/fd_mutex.go (right): https://codereview.appspot.com/12418043/diff/27001/src/pkg/net/fd_mutex.go#newcode37 src/pkg/net/fd_mutex.go:37: // Read operations must do ReadLock/ReadUnlock. Why are these ...
11 years, 7 months ago (2013-08-07 00:45:26 UTC) #7
dvyukov
PTAL https://codereview.appspot.com/12418043/diff/27001/src/pkg/net/fd_mutex.go File src/pkg/net/fd_mutex.go (right): https://codereview.appspot.com/12418043/diff/27001/src/pkg/net/fd_mutex.go#newcode37 src/pkg/net/fd_mutex.go:37: // Read operations must do ReadLock/ReadUnlock. On 2013/08/07 ...
11 years, 7 months ago (2013-08-07 21:41:39 UTC) #8
iant
https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_mutex.go File src/pkg/net/fd_mutex.go (right): https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_mutex.go#newcode45 src/pkg/net/fd_mutex.go:45: // All lock operations return false if fd is ...
11 years, 7 months ago (2013-08-09 00:01:26 UTC) #9
mikio
pls don't make sendfile_freebsd.go a black sheep.
11 years, 7 months ago (2013-08-09 04:35:26 UTC) #10
dvyukov
PTAL https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_mutex.go File src/pkg/net/fd_mutex.go (right): https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_mutex.go#newcode45 src/pkg/net/fd_mutex.go:45: // All lock operations return false if fd ...
11 years, 7 months ago (2013-08-09 09:44:03 UTC) #11
dvyukov
On 2013/08/09 04:35:26, mikio wrote: > pls don't make sendfile_freebsd.go a black sheep. oops, it ...
11 years, 7 months ago (2013-08-09 09:44:49 UTC) #12
iant
https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_windows.go File src/pkg/net/fd_windows.go (left): https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_windows.go#oldcode335 src/pkg/net/fd_windows.go:335: o.mu.Lock() On 2013/08/09 09:44:04, dvyukov wrote: > On 2013/08/09 ...
11 years, 7 months ago (2013-08-09 13:20:42 UTC) #13
dvyukov
On 2013/08/09 13:20:42, iant wrote: > https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_windows.go > File src/pkg/net/fd_windows.go (left): > > https://codereview.appspot.com/12418043/diff/53001/src/pkg/net/fd_windows.go#oldcode335 > ...
11 years, 7 months ago (2013-08-09 14:14:32 UTC) #14
iant
LGTM Thanks.
11 years, 7 months ago (2013-08-09 15:48:34 UTC) #15
dvyukov
anybody else?
11 years, 7 months ago (2013-08-09 16:10:51 UTC) #16
bradfitz
LGTM It's now cleaner overall. I don't see why the semacquire(profile false) stuff is necessarily ...
11 years, 7 months ago (2013-08-09 16:26:53 UTC) #17
dvyukov
https://codereview.appspot.com/12418043/diff/77001/src/pkg/net/fd_mutex.go File src/pkg/net/fd_mutex.go (right): https://codereview.appspot.com/12418043/diff/77001/src/pkg/net/fd_mutex.go#newcode10 src/pkg/net/fd_mutex.go:10: // that manages lifetime of fd and serializes access ...
11 years, 7 months ago (2013-08-09 17:05:58 UTC) #18
dvyukov
On 2013/08/09 16:26:53, bradfitz wrote: > LGTM > > It's now cleaner overall. > > ...
11 years, 7 months ago (2013-08-09 17:09:40 UTC) #19
bradfitz
Gotcha. On Fri, Aug 9, 2013 at 10:09 AM, <dvyukov@google.com> wrote: > On 2013/08/09 16:26:53, ...
11 years, 7 months ago (2013-08-09 17:13:39 UTC) #20
dvyukov
11 years, 7 months ago (2013-08-09 17:43:08 UTC) #21
*** Submitted as https://code.google.com/p/go/source/detail?r=7afd81b7fe12 ***

net: add special netFD mutex
The mutex, fdMutex, handles locking and lifetime of sysfd,
and serializes Read and Write methods.
This allows to strip 2 sync.Mutex.Lock calls,
2 sync.Mutex.Unlock calls, 1 defer and some amount
of misc overhead from every network operation.

On linux/amd64, Intel E5-2690:
benchmark                             old ns/op    new ns/op    delta
BenchmarkTCP4Persistent                    9595         9454   -1.47%
BenchmarkTCP4Persistent-2                  8978         8772   -2.29%
BenchmarkTCP4ConcurrentReadWrite           4900         4625   -5.61%
BenchmarkTCP4ConcurrentReadWrite-2         2603         2500   -3.96%

In general it strips 70-500 ns from every network operation depending
on processor model. On my relatively new E5-2690 it accounts to ~5%
of network op cost.

Fixes issue 6074.

R=golang-dev, bradfitz, alex.brainman, iant, mikioh.mikioh
CC=golang-dev
https://codereview.appspot.com/12418043
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b