nfsd: don't use sv_nrthreads in connection limiting calculations.
The heuristic for limiting the number of incoming connections to nfsd currently uses sv_nrthreads - allowing more connections if more threads were configured. A future patch will allow number of threads to grow dynamically so that there will be no need to configure sv_nrthreads. So we need a different solution for limiting connections. It isn't clear what problem is solved by limiting connections (as mentioned in a code comment) but the most likely problem is a connection storm - many connections that are not doing productive work. These will be closed after about 6 minutes already but it might help to slow down a storm. This patch adds a per-connection flag XPT_PEER_VALID which indicates that the peer has presented a filehandle for which it has some sort of access. i.e the peer is known to be trusted in some way. We now only count connections which have NOT been determined to be valid. There should be relative few of these at any given time. If the number of non-validated peer exceed a limit - currently 64 - we close the oldest non-validated peer to avoid having too many of these useless connections. Note that this patch significantly changes the meaning of the various configuration parameters for "max connections". The next patch will remove all of these. Signed-off-by: NeilBrown <neilb@suse.de> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
parent
de71d4e211
commit
eccbbc7c00
7 changed files with 38 additions and 23 deletions
|
@ -211,10 +211,6 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)
|
|||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
cb_info->serv = serv;
|
||||
/* As there is only one thread we need to over-ride the
|
||||
* default maximum of 80 connections
|
||||
*/
|
||||
serv->sv_maxconn = 1024;
|
||||
dprintk("nfs_callback_create_svc: service created\n");
|
||||
return serv;
|
||||
}
|
||||
|
|
|
@ -984,6 +984,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp)
|
|||
nfs_put_client(cps.clp);
|
||||
goto out_invalidcred;
|
||||
}
|
||||
svc_xprt_set_valid(rqstp->rq_xprt);
|
||||
}
|
||||
|
||||
cps.minorversion = hdr_arg.minorversion;
|
||||
|
|
|
@ -129,8 +129,8 @@ struct nfsd_net {
|
|||
unsigned char writeverf[8];
|
||||
|
||||
/*
|
||||
* Max number of connections this nfsd container will allow. Defaults
|
||||
* to '0' which is means that it bases this on the number of threads.
|
||||
* Max number of non-validated connections this nfsd container
|
||||
* will allow. Defaults to '0' gets mapped to 64.
|
||||
*/
|
||||
unsigned int max_connections;
|
||||
|
||||
|
|
|
@ -382,6 +382,8 @@ __fh_verify(struct svc_rqst *rqstp,
|
|||
if (error)
|
||||
goto out;
|
||||
|
||||
svc_xprt_set_valid(rqstp->rq_xprt);
|
||||
|
||||
/* Finally, check access permissions. */
|
||||
error = nfsd_permission(cred, exp, dentry, access);
|
||||
out:
|
||||
|
|
|
@ -81,7 +81,7 @@ struct svc_serv {
|
|||
unsigned int sv_xdrsize; /* XDR buffer size */
|
||||
struct list_head sv_permsocks; /* all permanent sockets */
|
||||
struct list_head sv_tempsocks; /* all temporary sockets */
|
||||
int sv_tmpcnt; /* count of temporary sockets */
|
||||
int sv_tmpcnt; /* count of temporary "valid" sockets */
|
||||
struct timer_list sv_temptimer; /* timer for aging temporary sockets */
|
||||
|
||||
char * sv_name; /* service name */
|
||||
|
|
|
@ -99,8 +99,24 @@ enum {
|
|||
XPT_HANDSHAKE, /* xprt requests a handshake */
|
||||
XPT_TLS_SESSION, /* transport-layer security established */
|
||||
XPT_PEER_AUTH, /* peer has been authenticated */
|
||||
XPT_PEER_VALID, /* peer has presented a filehandle that
|
||||
* it has access to. It is NOT counted
|
||||
* in ->sv_tmpcnt.
|
||||
*/
|
||||
};
|
||||
|
||||
static inline void svc_xprt_set_valid(struct svc_xprt *xpt)
|
||||
{
|
||||
if (test_bit(XPT_TEMP, &xpt->xpt_flags) &&
|
||||
!test_and_set_bit(XPT_PEER_VALID, &xpt->xpt_flags)) {
|
||||
struct svc_serv *serv = xpt->xpt_server;
|
||||
|
||||
spin_lock(&serv->sv_lock);
|
||||
serv->sv_tmpcnt -= 1;
|
||||
spin_unlock(&serv->sv_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void unregister_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u)
|
||||
{
|
||||
spin_lock(&xpt->xpt_lock);
|
||||
|
|
|
@ -606,7 +606,8 @@ int svc_port_is_privileged(struct sockaddr *sin)
|
|||
}
|
||||
|
||||
/*
|
||||
* Make sure that we don't have too many active connections. If we have,
|
||||
* Make sure that we don't have too many connections that have not yet
|
||||
* demonstrated that they have access to the NFS server. If we have,
|
||||
* something must be dropped. It's not clear what will happen if we allow
|
||||
* "too many" connections, but when dealing with network-facing software,
|
||||
* we have to code defensively. Here we do that by imposing hard limits.
|
||||
|
@ -625,27 +626,25 @@ int svc_port_is_privileged(struct sockaddr *sin)
|
|||
*/
|
||||
static void svc_check_conn_limits(struct svc_serv *serv)
|
||||
{
|
||||
unsigned int limit = serv->sv_maxconn ? serv->sv_maxconn :
|
||||
(serv->sv_nrthreads+3) * 20;
|
||||
unsigned int limit = serv->sv_maxconn ? serv->sv_maxconn : 64;
|
||||
|
||||
if (serv->sv_tmpcnt > limit) {
|
||||
struct svc_xprt *xprt = NULL;
|
||||
struct svc_xprt *xprt = NULL, *xprti;
|
||||
spin_lock_bh(&serv->sv_lock);
|
||||
if (!list_empty(&serv->sv_tempsocks)) {
|
||||
/* Try to help the admin */
|
||||
net_notice_ratelimited("%s: too many open connections, consider increasing the %s\n",
|
||||
serv->sv_name, serv->sv_maxconn ?
|
||||
"max number of connections" :
|
||||
"number of threads");
|
||||
/*
|
||||
* Always select the oldest connection. It's not fair,
|
||||
* but so is life
|
||||
* but nor is life.
|
||||
*/
|
||||
xprt = list_entry(serv->sv_tempsocks.prev,
|
||||
struct svc_xprt,
|
||||
xpt_list);
|
||||
set_bit(XPT_CLOSE, &xprt->xpt_flags);
|
||||
svc_xprt_get(xprt);
|
||||
list_for_each_entry_reverse(xprti, &serv->sv_tempsocks,
|
||||
xpt_list) {
|
||||
if (!test_bit(XPT_PEER_VALID, &xprti->xpt_flags)) {
|
||||
xprt = xprti;
|
||||
set_bit(XPT_CLOSE, &xprt->xpt_flags);
|
||||
svc_xprt_get(xprt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
spin_unlock_bh(&serv->sv_lock);
|
||||
|
||||
|
@ -1039,7 +1038,8 @@ static void svc_delete_xprt(struct svc_xprt *xprt)
|
|||
|
||||
spin_lock_bh(&serv->sv_lock);
|
||||
list_del_init(&xprt->xpt_list);
|
||||
if (test_bit(XPT_TEMP, &xprt->xpt_flags))
|
||||
if (test_bit(XPT_TEMP, &xprt->xpt_flags) &&
|
||||
!test_bit(XPT_PEER_VALID, &xprt->xpt_flags))
|
||||
serv->sv_tmpcnt--;
|
||||
spin_unlock_bh(&serv->sv_lock);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue