alistair23-linux/include/linux/sunrpc
Jeff Layton b1691bc03d sunrpc: convert to lockless lookup of queued server threads
Testing has shown that the pool->sp_lock can be a bottleneck on a busy
server. Every time data is received on a socket, the server must take
that lock in order to dequeue a thread from the sp_threads list.

Address this problem by eliminating the sp_threads list (which contains
threads that are currently idle) and replacing it with a RQ_BUSY flag in
svc_rqst. This allows us to walk the sp_all_threads list under the
rcu_read_lock and find a suitable thread for the xprt by doing a
test_and_set_bit.

Note that we do still have a potential atomicity problem however with
this approach.  We don't want svc_xprt_do_enqueue to set the
rqst->rq_xprt pointer unless a test_and_set_bit of RQ_BUSY returned
zero (which indicates that the thread was idle). But, by the time we
check that, the bit could be flipped by a waking thread.

To address this, we acquire a new per-rqst spinlock (rq_lock) and take
that before doing the test_and_set_bit. If that returns false, then we
can set rq_xprt and drop the spinlock. Then, when the thread wakes up,
it must set the bit under the same spinlock and can trust that if it was
already set then the rq_xprt is also properly set.

With this scheme, the case where we have an idle thread no longer needs
to take the highly contended pool->sp_lock at all, and that removes the
bottleneck.

That still leaves one issue: What of the case where we walk the whole
sp_all_threads list and don't find an idle thread? Because the search is
lockess, it's possible for the queueing to race with a thread that is
going to sleep. To address that, we queue the xprt and then search again.

If we find an idle thread at that point, we can't attach the xprt to it
directly since that might race with a different thread waking up and
finding it.  All we can do is wake the idle thread back up and let it
attempt to find the now-queued xprt.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Tested-by: Chris Worley <chris.worley@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2014-12-09 11:22:22 -05:00
..
addr.h sunrpc: move address copy/cmp/convert routines and prototypes from clnt.h to addr.h 2013-02-05 09:41:14 -05:00
auth.h sunrpc: eliminate RPC_DEBUG 2014-11-24 17:31:46 -05:00
auth_gss.h sunrpc: remove __rcu annotation from struct gss_cl_ctx->gc_gss_ctx 2014-08-03 17:05:23 -04:00
bc_xprt.h SUNRPC: RPC callbacks may be split across several TCP segments 2014-02-11 14:01:20 -05:00
cache.h sunrpc: prepare NFS for 2038 2013-08-19 09:55:01 -04:00
clnt.h sunrpc: add debugfs file for displaying client rpc_task queue 2014-11-27 13:14:51 -05:00
debug.h sunrpc: add a debugfs rpc_xprt directory with an info file in it 2014-11-27 13:14:52 -05:00
gss_api.h svcrpc: store gss mech in svc_cred 2013-07-01 17:23:06 -04:00
gss_asn1.h
gss_err.h
gss_krb5.h sunrpc: remove "ec" argument from encrypt_v2 operation 2014-08-03 17:05:24 -04:00
gss_krb5_enctypes.h
metrics.h SUNRPC: serialize iostats updates 2014-11-25 16:22:15 -05:00
msg_prot.h nfsd4: check backchannel attributes on create_session 2013-04-09 16:53:56 -04:00
rpc_pipe_fs.h sunrpc: replace sunrpc_net->gssd_running flag with a more reliable check 2013-12-06 13:06:31 -05:00
rpc_rdma.h
sched.h sunrpc: eliminate RPC_TRACEPOINTS 2014-11-24 17:33:12 -05:00
stats.h
svc.h sunrpc: convert to lockless lookup of queued server threads 2014-12-09 11:22:22 -05:00
svc_rdma.h svcrdma: Double the default credit limit 2014-07-23 14:20:48 -04:00
svc_xprt.h sunrpc: eliminate the XPT_DETACHED flag 2014-12-01 12:45:26 -07:00
svcauth.h svcrpc: store gss mech in svc_cred 2013-07-01 17:23:06 -04:00
svcauth_gss.h
svcsock.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2014-04-12 17:31:22 -07:00
timer.h
types.h
xdr.h rpc: define xdr_restrict_buflen 2014-05-30 17:32:01 -04:00
xprt.h sunrpc: add a debugfs rpc_xprt directory with an info file in it 2014-11-27 13:14:52 -05:00
xprtrdma.h xprtrdma: Remove RPCRDMA_PERSISTENT_REGISTRATION macro 2014-07-31 16:22:59 -04:00
xprtsock.h sunrpc: add tracepoints in xs_tcp_data_recv 2014-11-24 12:53:35 -05:00