socket: Speed up soclose by avoiding putting the user thread into sleep
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 20 Nov 2011 11:25:05 +0000 (19:25 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 20 Nov 2011 11:51:04 +0000 (19:51 +0800)
commitacd31a69ea41698798c8dcc03369dd7c70e4741e
tree4c810082c63b19c5332fe0c2802cc990207923a2
parentf3dcefea4999dd3bbd2f735115ae125ebc0df740
socket: Speed up soclose by avoiding putting the user thread into sleep

- Embed a netmsg_base into socket, it will be used if fast soclose
  is possible
- Factor out sodiscard(), which abort the connections on the listen
  socket and set the SS_NOFDREF bit.  This function is shared across
  fast soclose and synchronized soclose
- Rename the original soclose() to soclose_sync(), which uses domsg
  to perform proto-specific operation
- If kern.ipc.soclose_fast is 1 (it is 1 by default) and SO_LINGER
  socket option is not set and the socket does not use synchronized
  msgport (e.g. UNIX domain socket), fast soclose will be used
- The fast soclose is implemented to avoid putting the caller thread
  (usually a user thread) into sleep.  It uses the socket's embeded
  "close message" with different dispatch functions based on the
  current socket state and send the "close message" (asynchronized)
  to proto thread to carry out various tasks.

The result:
On Phenom 9550 (4 core, 2.2GHz):
route change -host 127.0.0.1 -msl 50 (set MSL to 50ms)
8 parallel netperf -H 127.0.0.1 -t TCP_CC -P0 (4 runs, unit: tps)

old  33181.18  33005.66  33130.48  33010.50
new  39109.07  39032.48  39022.75  38993.72

This gives 18% performance improvement
sys/kern/uipc_msg.c
sys/kern/uipc_socket.c
sys/sys/socketops.h
sys/sys/socketvar.h