freebsd-dev/sys/rpc
Garrett Wollman 3c42b5bf28 Fix overflow bugs in and remove obsolete limit from kernel RPC
implementation.

The kernel RPC code, which is responsible for the low-level scheduling
of incoming NFS requests, contains a throttling mechanism that
prevents too much kernel memory from being tied up by NFS requests
that are being serviced.  When the throttle is engaged, the RPC layer
stops servicing incoming NFS sockets, resulting ultimately in
backpressure on the clients (if they're using TCP).  However, this is
a very heavy-handed mechanism as it prevents all clients from making
any requests, regardless of how heavy or light they are.  (Thus, when
engaged, the throttle often prevents clients from even mounting the
filesystem.)  The throttle mechanism applies specifically to requests
that have been received by the RPC layer (from a TCP or UDP socket)
and are queued waiting to be serviced by one of the nfsd threads; it
does not limit the amount of backlog in the socket buffers.

The original implementation limited the total bytes of queued requests
to the minimum of a quarter of (nmbclusters * MCLBYTES) and 45 MiB.
The former limit seems reasonable, since requests queued in the socket
buffers and replies being constructed to the requests in progress will
all require some amount of network memory, but the 45 MiB limit is
plainly ridiculous for modern memory sizes: when running 256 service
threads on a busy server, 45 MiB would result in just a single
maximum-sized NFS3PROC_WRITE queued per thread before throttling.

Removing this limit exposed integer-overflow bugs in the original
computation, and related bugs in the routines that actually account
for the amount of traffic enqueued for service threads.  The old
implementation also attempted to reduce accounting overhead by
batching updates until each queue is fully drained, but this is prone
to livelock, resulting in repeated accumulate-throttle-drain cycles on
a busy server.  Various data types are changed to long or unsigned
long; explicit 64-bit types are not used due to the unavailability of
64-bit atomics on many 32-bit platforms, but those platforms also
cannot support nmbclusters large enough to cause overflow.

This code (in a 10.1 kernel) is presently running on production NFS
servers at CSAIL.

Summary of this revision:
* Removes 45 MiB limit on requests queued for nfsd service threads
* Fixes integer-overflow and signedness bugs
* Avoids unnecessary throttling by not deferring accounting for
  completed requests

Differential Revision:	https://reviews.freebsd.org/D2165
Reviewed by:	rmacklem, mav
MFC after:	30 days
Relnotes:	yes
Sponsored by:	MIT Computer Science & Artificial Intelligence Laboratory
2015-04-01 00:45:47 +00:00
..
rpcsec_gss Add support for host-based (Kerberos 5 service principal) initiator 2013-07-09 01:05:28 +00:00
auth_none.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
auth_unix.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
auth.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
authunix_prot.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
clnt_bck.c Merge the NFSv4.1 server code in projects/nfsv4.1-server over 2014-07-01 20:47:16 +00:00
clnt_dg.c Remove some unused static const strings under sys/rpc, which have never 2013-12-24 20:55:22 +00:00
clnt_rc.c Revert 195703 and 195821 as this special stop handling in NFS is now 2013-03-13 21:06:03 +00:00
clnt_stat.h
clnt_vc.c In preparation of merging projects/sendfile, transform bare access to 2014-11-12 09:57:15 +00:00
clnt.h Replace Sun Industry Standards Source License for Sun RPC code with a 2013-11-25 19:08:38 +00:00
getnetconfig.c
krpc.h Merge the NFSv4.1 server code in projects/nfsv4.1-server over 2014-07-01 20:47:16 +00:00
netconfig.h
nettype.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
pmap_prot.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
replay.c
replay.h
rpc_callmsg.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpc_com.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpc_generic.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpc_msg.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpc_prot.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpc.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpcb_clnt.c Move a static const variable to the #if 0 part where it is only used. 2013-12-24 20:57:26 +00:00
rpcb_clnt.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:07:44 +00:00
rpcb_prot.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpcb_prot.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
rpcm_subs.h
rpcsec_gss.h Add support for host-based (Kerberos 5 service principal) initiator 2013-07-09 01:05:28 +00:00
svc_auth_unix.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
svc_auth.c Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
svc_auth.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
svc_dg.c Rework NFS Duplicate Request Cache cleanup logic. 2014-01-03 15:09:59 +00:00
svc_generic.c Split RPC pool threads into number of smaller semi-isolated groups. 2014-06-08 11:19:32 +00:00
svc_vc.c rpc: Uninitialized pointer read 2015-02-02 16:07:07 +00:00
svc.c Fix overflow bugs in and remove obsolete limit from kernel RPC 2015-04-01 00:45:47 +00:00
svc.h Fix overflow bugs in and remove obsolete limit from kernel RPC 2015-04-01 00:45:47 +00:00
types.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00
xdr.h Replace Sun RPC license in TI-RPC library with a 3-clause BSD license, 2013-11-25 19:04:36 +00:00