From: Jeff Layton <jlayton@kernel.org>
To: NeilBrown <neilb@suse.de>, Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia <kolga@netapp.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
Steve Dickson <steved@redhat.com>
Subject: Re: [PATCH 11/14] nfsd: don't use sv_nrthreads in connection limiting calculations.
Date: Mon, 15 Jul 2024 11:52:55 -0400 [thread overview]
Message-ID: <2d74fdf5f3c1f2b0e5264ff3c807b1b38657c9ef.camel@kernel.org> (raw)
In-Reply-To: <20240715074657.18174-12-neilb@suse.de>
On Mon, 2024-07-15 at 17:14 +1000, NeilBrown wrote:
> 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 is 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 add 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 be determined to be valid. There
> should be relative few of these at any given time.
>
> If the number of non-validated peer exceed as limit - currently 64 - we
> close the oldest non-validated peer to avoid having too many of these
> useless connections.
>
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
> fs/nfsd/netns.h | 4 ++--
> fs/nfsd/nfsfh.c | 8 ++++++++
> include/linux/sunrpc/svc.h | 2 +-
> include/linux/sunrpc/svc_xprt.h | 4 ++++
> net/sunrpc/svc_xprt.c | 33 +++++++++++++++++----------------
> 5 files changed, 32 insertions(+), 19 deletions(-)
>
> diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
> index 238fc4e56e53..0d2ac15a5003 100644
> --- a/fs/nfsd/netns.h
> +++ b/fs/nfsd/netns.h
> @@ -128,8 +128,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;
>
> diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
> index 0b75305fb5f5..08742bf8de02 100644
> --- a/fs/nfsd/nfsfh.c
> +++ b/fs/nfsd/nfsfh.c
> @@ -391,6 +391,14 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
> goto out;
>
> skip_pseudoflavor_check:
> + if (test_bit(XPT_TEMP, &rqstp->rq_xprt->xpt_flags) &&
> + !test_and_set_bit(XPT_PEER_VALID, &rqstp->rq_xprt->xpt_flags)) {
> + struct svc_serv *serv = rqstp->rq_server;
> + spin_lock(&serv->sv_lock);
> + serv->sv_tmpcnt -= 1;
> + spin_unlock(&serv->sv_lock);
> + }
> +
This is the only place you set XPT_PEER_VALID, but this change affects
more services than just nfsd. What about lockd? Do we need a similar
change there?
> /* Finally, check access permissions. */
> error = nfsd_permission(rqstp, exp, dentry, access);
> out:
> diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
> index 99e9345d829e..0b414af448e0 100644
> --- a/include/linux/sunrpc/svc.h
> +++ b/include/linux/sunrpc/svc.h
> @@ -79,7 +79,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 */
> diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
> index 0981e35a9fed..92565133b3b6 100644
> --- a/include/linux/sunrpc/svc_xprt.h
> +++ b/include/linux/sunrpc/svc_xprt.h
> @@ -99,6 +99,10 @@ 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 unregister_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u)
> diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
> index 53ebc719ff5a..a9215e1a2f38 100644
> --- a/net/sunrpc/svc_xprt.c
> +++ b/net/sunrpc/svc_xprt.c
> @@ -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 the 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,26 @@ 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 +1039,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);
>
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2024-07-15 15:52 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 7:14 [PATCH 00/14 RFC] support automatic changes to nfsd thread count NeilBrown
2024-07-15 7:14 ` [PATCH 01/14] lockd: discard nlmsvc_timeout NeilBrown
2024-07-15 7:14 ` [PATCH 02/14] SUNRPC: make various functions static, or not exported NeilBrown
2024-07-15 7:14 ` [PATCH 03/14] nfsd: move nfsd_pool_stats_open into nfsctl.c NeilBrown
2024-07-15 7:14 ` [PATCH 04/14] nfsd: don't allocate the versions array NeilBrown
2024-08-02 21:34 ` Mike Snitzer
2024-08-02 23:04 ` NeilBrown
2024-08-05 4:55 ` NeilBrown
2024-07-15 7:14 ` [PATCH 05/14] sunrpc: change sp_nrthreads from atomic_t to unsigned int NeilBrown
2024-07-15 14:12 ` Jeff Layton
2024-07-15 14:33 ` Jeff Layton
2024-07-16 1:33 ` NeilBrown
2024-07-24 19:36 ` Chuck Lever
2024-07-15 7:14 ` [PATCH 06/14] sunrpc: don't take ->sv_lock when updating ->sv_nrthreads NeilBrown
2024-07-15 7:14 ` [PATCH 07/14] Change unshare_fs_struct() to never fail NeilBrown
2024-07-15 14:39 ` Jeff Layton
2024-07-16 1:48 ` NeilBrown
2024-07-15 7:14 ` [PATCH 08/14] SUNRPC: move nrthreads counting to start/stop threads NeilBrown
2024-07-15 7:14 ` [PATCH 09/14] nfsd: return hard failure for OP_SETCLIENTID when there are too many clients NeilBrown
2024-07-15 15:21 ` Jeff Layton
2024-07-15 7:14 ` [PATCH 10/14] nfs: dynamically adjust per-client DRC slot limits NeilBrown
2024-07-15 7:14 ` [PATCH 11/14] nfsd: don't use sv_nrthreads in connection limiting calculations NeilBrown
2024-07-15 15:52 ` Jeff Layton [this message]
2024-07-16 2:04 ` NeilBrown
2024-07-15 7:14 ` [PATCH 12/14] sunrpc: introduce possibility that requested number of threads is different from actual NeilBrown
2024-07-15 16:00 ` Jeff Layton
2024-07-15 7:14 ` [PATCH 13/14] nfsd: introduce concept of a maximum number of threads NeilBrown
2024-07-15 17:06 ` Jeff Layton
2024-07-16 3:21 ` NeilBrown
2024-07-16 11:00 ` Jeff Layton
2024-07-16 13:31 ` Chuck Lever III
2024-07-16 18:49 ` Tom Talpey
2024-07-17 15:24 ` Chuck Lever III
2024-07-15 7:14 ` [PATCH 14/14] nfsd: adjust number of running nfsd threads NeilBrown
2024-07-15 17:29 ` [PATCH 00/14 RFC] support automatic changes to nfsd thread count Jeff Layton
2024-07-24 19:43 ` Chuck Lever III
2024-07-24 21:25 ` NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d74fdf5f3c1f2b0e5264ff3c807b1b38657c9ef.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=kolga@netapp.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
--cc=steved@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox