Linux NFS development
 help / color / mirror / Atom feed
From: Tom Tucker <tom@opengridcomputing.com>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>, linux-nfs@vger.kernel.org
Subject: Re: [RFC,PATCH 09/38] svc: Add a transport function that checks for write space
Date: Fri, 30 Nov 2007 15:39:24 -0600	[thread overview]
Message-ID: <1196458764.5432.52.camel@trinity.ogc.int> (raw)
In-Reply-To: <2F76C3FF-923D-4C36-ADBE-E3F9F645F20E@oracle.com>


On Fri, 2007-11-30 at 15:46 -0500, Chuck Lever wrote:
> On Nov 29, 2007, at 5:40 PM, Tom Tucker wrote:
> > In order to avoid blocking a service thread, the receive side checks
> > to see if there is sufficient write space to reply to the request.
> > Each transport has a different mechanism for determining if there is
> > enough write space to reply.
> >
> > The code that checked for white space was coupled with code that
> 
> s/white space/write space/

ok.

> 
> > checked for CLOSE and CONN. These checks have been broken out into
> > separate statements to make the code easier to read.
> >
> > Signed-off-by: Tom Tucker <tom@opengridcomputing.com>
> > ---
> >
> >  include/linux/sunrpc/svc_xprt.h |    1 +
> >  net/sunrpc/svcsock.c            |   60 ++++++++++++++++++++++++++++ 
> > +++++------
> >  2 files changed, 51 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/ 
> > svc_xprt.h
> > index 8501115..3adc8f3 100644
> > --- a/include/linux/sunrpc/svc_xprt.h
> > +++ b/include/linux/sunrpc/svc_xprt.h
> > @@ -10,6 +10,7 @@
> >  #include <linux/sunrpc/svc.h>
> >
> >  struct svc_xprt_ops {
> > +	int		(*xpo_has_wspace)(struct svc_xprt *);
> >  	int		(*xpo_recvfrom)(struct svc_rqst *);
> >  	void		(*xpo_prep_reply_hdr)(struct svc_rqst *);
> >  	int		(*xpo_sendto)(struct svc_rqst *);
> > diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
> > index 510ad45..b796244 100644
> > --- a/net/sunrpc/svcsock.c
> > +++ b/net/sunrpc/svcsock.c
> > @@ -269,22 +269,24 @@ svc_sock_enqueue(struct svc_sock *svsk)
> >  	BUG_ON(svsk->sk_pool != NULL);
> >  	svsk->sk_pool = pool;
> >
> > -	set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
> > -	if (((atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg)*2
> > -	     > svc_sock_wspace(svsk))
> > -	    && !test_bit(SK_CLOSE, &svsk->sk_flags)
> > -	    && !test_bit(SK_CONN, &svsk->sk_flags)) {
> > +	/* Handle pending connection */
> > +	if (test_bit(SK_CONN, &svsk->sk_flags))
> > +		goto process;
> > +
> > +	/* Handle close in-progress */
> > +	if (test_bit(SK_CLOSE, &svsk->sk_flags))
> > +		goto process;
> > +
> > +	/* Check if we have space to reply to a request */
> > +	if (!svsk->sk_xprt.xpt_ops->xpo_has_wspace(&svsk->sk_xprt)) {
> >  		/* Don't enqueue while not enough space for reply */
> > -		dprintk("svc: socket %p  no space, %d*2 > %ld, not enqueued\n",
> > -			svsk->sk_sk, atomic_read(&svsk->sk_reserved)+serv->sv_max_mesg,
> > -			svc_sock_wspace(svsk));
> > +		dprintk("svc: no write space, socket %p  not enqueued\n", svsk);
> 
> Since you remove the only callers of svc_sock_wspace here, you can  
> probably safely delete that function in this patch as well.
> 

ok.

> >  		svsk->sk_pool = NULL;
> >  		clear_bit(SK_BUSY, &svsk->sk_flags);
> >  		goto out_unlock;
> >  	}
> > -	clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
> > -
> >
> > + process:
> >  	if (!list_empty(&pool->sp_threads)) {
> >  		rqstp = list_entry(pool->sp_threads.next,
> >  				   struct svc_rqst,
> > @@ -897,6 +899,24 @@ static void svc_udp_prep_reply_hdr(struct  
> > svc_rqst *rqstp)
> >  {
> >  }
> >
> > +static int svc_udp_has_wspace(struct svc_xprt *xprt)
> > +{
> > +	struct svc_sock *svsk = container_of(xprt, struct svc_sock,  
> > sk_xprt);
> > +	struct svc_serv	*serv = svsk->sk_server;
> > +	int required;
> > +
> > +	/*
> > +	 * Set the SOCK_NOSPACE flag before checking the available
> > +	 * sock space.
> > +	 */
> > +	set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
> > +	required = atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg;
> 
> The result of the sum is unsigned, but then we stuff it into a signed  
> integer...
> 
> > +	if (required*2 > sock_wspace(svsk->sk_sk))
> > +		return 0;
> 
> ...and then this introduces a mixed sign comparison (harmless  
> AFAICT).  Perhaps "required" should be an unsigned long.
> 

So for svc_udp_has_wspace, it makes sense for required to 
be unsigned, and then demote to signed on return. Yes?

> 
> Also, some may prefer "<< 1" to "* 2".  I'm not sure it makes much  
> difference here.  Arguably, it might be slightly better documentation  
> to double "required" before the if statement.
> 
> > +	clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
> > +	return 1;
> > +}
> > +
> >  static struct svc_xprt_ops svc_udp_ops = {
> >  	.xpo_recvfrom = svc_udp_recvfrom,
> >  	.xpo_sendto = svc_udp_sendto,
> > @@ -904,6 +924,7 @@ static struct svc_xprt_ops svc_udp_ops = {
> >  	.xpo_detach = svc_sock_detach,
> >  	.xpo_free = svc_sock_free,
> >  	.xpo_prep_reply_hdr = svc_udp_prep_reply_hdr,
> > +	.xpo_has_wspace = svc_udp_has_wspace,
> >  };
> >
> >  static struct svc_xprt_class svc_udp_class = {
> > @@ -1366,6 +1387,24 @@ static void svc_tcp_prep_reply_hdr(struct  
> > svc_rqst *rqstp)
> >  	svc_putnl(resv, 0);
> >  }
> >
> > +static int svc_tcp_has_wspace(struct svc_xprt *xprt)
> > +{
> > +	struct svc_sock *svsk = container_of(xprt, struct svc_sock,  
> > sk_xprt);
> > +	struct svc_serv	*serv = svsk->sk_server;
> > +	int required;
> > +
> > +	/*
> > +	 * Set the SOCK_NOSPACE flag before checking the available
> > +	 * sock space.
> > +	 */
> > +	set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
> > +	required = atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg;
> 
> Ibid.
> 
> > +	if (required*2 > sk_stream_wspace(svsk->sk_sk))
> > +		return 0;
> 
> Oddly sk_stream_wspace() returns an int, but sock_space() returns an  
> unsigned long.  Sigh...

For this one, let's leave required signed and add an explicit cast to
serv->sv_max_mesg. Sound ok?

What a mess...

> 
> > +	clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
> > +	return 1;
> > +}
> > +
> >  static struct svc_xprt_ops svc_tcp_ops = {
> >  	.xpo_recvfrom = svc_tcp_recvfrom,
> >  	.xpo_sendto = svc_tcp_sendto,
> > @@ -1373,6 +1412,7 @@ static struct svc_xprt_ops svc_tcp_ops = {
> >  	.xpo_detach = svc_sock_detach,
> >  	.xpo_free = svc_sock_free,
> >  	.xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr,
> > +	.xpo_has_wspace = svc_tcp_has_wspace,
> >  };
> >
> >  static struct svc_xprt_class svc_tcp_class = {
> 
> --
> Chuck Lever
> chuck[dot]lever[at]oracle[dot]com


  reply	other threads:[~2007-11-30 21:35 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29 22:39 [RFC,PATCH 00/38] SVC Transport Switch Tom Tucker
     [not found] ` <20071129223917.14563.77633.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-29 22:39   ` [RFC,PATCH 01/38] svc: Add an svc transport class Tom Tucker
2007-11-29 22:39   ` [RFC,PATCH 02/38] svc: Make svc_sock the tcp/udp transport Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 03/38] svc: Change the svc_sock in the rqstp structure to a transport Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 04/38] svc: Add a max payload value to the transport Tom Tucker
     [not found]     ` <20071129224002.14563.96227.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-30 20:22       ` Chuck Lever
2007-11-30 20:51         ` Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 05/38] svc: Move sk_sendto and sk_recvfrom to svc_xprt_class Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 06/38] svc: Add transport specific xpo_release function Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 07/38] svc: Add per-transport delete functions Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 08/38] svc: Add xpo_prep_reply_hdr Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 09/38] svc: Add a transport function that checks for write space Tom Tucker
     [not found]     ` <20071129224012.14563.23130.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-30 20:46       ` Chuck Lever
2007-11-30 21:39         ` Tom Tucker [this message]
     [not found]           ` <1196458764.5432.52.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org>
2007-11-30 22:43             ` Chuck Lever
2007-12-10 20:43               ` Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 10/38] svc: Move close processing to a single place Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 11/38] svc: Add xpo_accept transport function Tom Tucker
     [not found]     ` <20071129224016.14563.67547.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-30 21:01       ` Chuck Lever
2007-11-30 21:47         ` Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 12/38] svc: Add a generic transport svc_create_xprt function Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 13/38] svc: Change services to use new svc_create_xprt service Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 14/38] svc: Change sk_inuse to a kref Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 15/38] svc: Move sk_flags to the svc_xprt structure Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 16/38] svc: Move sk_server and sk_pool to svc_xprt Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 17/38] svc: Make close transport independent Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 18/38] svc: Move sk_reserved to svc_xprt Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 19/38] svc: Make the enqueue service transport neutral and export it Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 20/38] svc: Make svc_send transport neutral Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 21/38] svc: Change svc_sock_received to svc_xprt_received and export it Tom Tucker
     [not found]     ` <20071129224037.14563.69171.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-30 21:33       ` Chuck Lever
2007-11-30 23:17         ` Tom Tucker
     [not found]           ` <1196464634.5432.68.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org>
2007-11-30 23:23             ` Chuck Lever
2007-11-29 22:40   ` [RFC,PATCH 22/38] svc: Remove sk_lastrecv Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 24/38] svc: Make deferral processing xprt independent Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 25/38] svc: Move the sockaddr information to svc_xprt Tom Tucker
     [not found]     ` <20071129224046.14563.59353.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-30 23:20       ` Chuck Lever
2007-11-29 22:40   ` [RFC,PATCH 26/38] svc: Make svc_sock_release svc_xprt_release Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 27/38] svc: Make svc_recv transport neutral Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 28/38] svc: Make svc_age_temp_sockets svc_age_temp_transports Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 29/38] svc: Move common create logic to common code Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 30/38] svc: Removing remaining references to rq_sock in rqstp Tom Tucker
2007-11-29 22:40   ` [RFC,PATCH 31/38] svc: Make svc_check_conn_limits xprt independent Tom Tucker
2007-11-29 22:41   ` [RFC,PATCH 32/38] svc: Move the xprt independent code to the svc_xprt.c file Tom Tucker
2007-11-29 22:41   ` [RFC,PATCH 33/38] svc: Add transport hdr size for defer/revisit Tom Tucker
     [not found]     ` <20071129224103.14563.72780.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-30 23:51       ` Chuck Lever
2007-11-29 22:41   ` [RFC,PATCH 34/38] svc: Add /proc/sys/sunrpc/transport files Tom Tucker
     [not found]     ` <20071129224105.14563.48684.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-12-03 16:44       ` Chuck Lever
2007-12-03 16:58         ` J. Bruce Fields
2007-12-03 18:30           ` Chuck Lever
2007-12-03 19:10             ` Tom Tucker
     [not found]               ` <1196709058.5811.21.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org>
2007-12-03 20:36                 ` Chuck Lever
2007-12-04  0:45                   ` Tom Tucker
2007-12-05  8:44           ` Greg Banks
2007-11-29 22:41   ` [RFC,PATCH 35/38] knfsd: Support adding transports by writing portlist file Tom Tucker
2007-11-29 22:41   ` [RFC,PATCH 36/38] svc: Add svc API that queries for a transport instance Tom Tucker
     [not found]     ` <20071129224109.14563.34563.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-12-01  0:00       ` Chuck Lever
2007-11-29 22:41   ` [RFC,PATCH 37/38] knfsd: Modify write_ports to use svc_find_xprt service Tom Tucker
2007-11-29 22:41   ` [RFC,PATCH 38/38] svc: Add svc_xprt_names service to replace svc_sock_names Tom Tucker
2007-11-29 23:18   ` [RFC,PATCH 00/38] SVC Transport Switch Tom Tucker
  -- strict thread matches above, loose matches on Subject: below --
2007-11-29 22:51 Tom Tucker
     [not found] ` <20071129225142.15107.46200.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-29 22:53   ` [RFC,PATCH 09/38] svc: Add a transport function that checks for write space Tom Tucker
2007-11-29 22:55 [RFC,PATCH 00/38] RPC Transport Switch Tom Tucker
     [not found] ` <20071129225510.15275.82660.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org>
2007-11-29 22:55   ` [RFC,PATCH 09/38] svc: Add a transport function that checks for write space Tom Tucker

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=1196458764.5432.52.camel@trinity.ogc.int \
    --to=tom@opengridcomputing.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /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