diff mbox

sunrpc: verbs: Avoid 1kb stack

Message ID 1357587696.21481.48.camel@joe-AO722 (mailing list archive)
State New, archived
Headers show

Commit Message

Joe Perches Jan. 7, 2013, 7:41 p.m. UTC
16 * 64 is a bit much.
Use kmalloc_array instead.

Signed-off-by: Joe Perches <joe@perches.com>
---
 net/sunrpc/xprtrdma/verbs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

J. Bruce Fields Jan. 8, 2013, 2:46 p.m. UTC | #1
On Mon, Jan 07, 2013 at 11:41:36AM -0800, Joe Perches wrote:
> 16 * 64 is a bit much.
> Use kmalloc_array instead.

I thought there was some reason we didn't do this.

Grepping up through the callers....  It looks like the result is
xprt_rdma_send_request returns -EIO, and as far as I can tell that gets
passed up to the application on the client.   That doesn't sound right.

--b.

> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  net/sunrpc/xprtrdma/verbs.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
> index 745973b..9cfebb4 100644
> --- a/net/sunrpc/xprtrdma/verbs.c
> +++ b/net/sunrpc/xprtrdma/verbs.c
> @@ -1736,8 +1736,13 @@ rpcrdma_register_default_external(struct rpcrdma_mr_seg *seg,
>  	int mem_priv = (writing ? IB_ACCESS_REMOTE_WRITE :
>  				  IB_ACCESS_REMOTE_READ);
>  	struct rpcrdma_mr_seg *seg1 = seg;
> -	struct ib_phys_buf ipb[RPCRDMA_MAX_DATA_SEGS];
>  	int len, i, rc = 0;
> +	struct ib_phys_buf *ipb = kmalloc_array(RPCRDMA_MAX_DATA_SEGS,
> +						sizeof(*ipb),
> +						GFP_KERNEL);
> +
> +	if (!ipb)
> +		return -ENOMEM;
>  
>  	if (*nsegs > RPCRDMA_MAX_DATA_SEGS)
>  		*nsegs = RPCRDMA_MAX_DATA_SEGS;
> @@ -1770,6 +1775,9 @@ rpcrdma_register_default_external(struct rpcrdma_mr_seg *seg,
>  		seg1->mr_len = len;
>  	}
>  	*nsegs = i;
> +
> +	kfree(ipb);
> +
>  	return rc;
>  }
>  
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches Jan. 8, 2013, 6:09 p.m. UTC | #2
On Tue, 2013-01-08 at 09:46 -0500, J. Bruce Fields wrote:
> On Mon, Jan 07, 2013 at 11:41:36AM -0800, Joe Perches wrote:
> > 16 * 64 is a bit much.
> > Use kmalloc_array instead.
> 
> I thought there was some reason we didn't do this.
> 
> Grepping up through the callers....  It looks like the result is
> xprt_rdma_send_request returns -EIO, and as far as I can tell that gets
> passed up to the application on the client.   That doesn't sound right.

No worries, it was just a warning I noticed when I
did an allmodconfig compilation.

Perhaps a comment there might be appropriate instead.


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tom Talpey Jan. 8, 2013, 10:52 p.m. UTC | #3
> -----Original Message-----
> From: Joe Perches [mailto:joe@perches.com]
> Sent: Tuesday, January 8, 2013 1:10 PM
> To: J. Bruce Fields
> Cc: Trond Myklebust; David S. Miller; linux-nfs@vger.kernel.org;
> netdev@vger.kernel.org; linux-kernel@vger.kernel.org; Tom Tucker;
> steved@redhat.com; Tom Talpey
> Subject: Re: [PATCH] sunrpc: verbs: Avoid 1kb stack
> 
> On Tue, 2013-01-08 at 09:46 -0500, J. Bruce Fields wrote:
> > On Mon, Jan 07, 2013 at 11:41:36AM -0800, Joe Perches wrote:
> > > 16 * 64 is a bit much.
> > > Use kmalloc_array instead.
> >
> > I thought there was some reason we didn't do this.

The value of RPCRDMA_MAX_DATA_SEGS appears to have been increased to allow 256KB operations (64 pages). Not all requests will need this, so you may want to consider dynamically allocating the array only when it's relatively large (*nsegs is >8, perhaps).

IIRC, the ib_phys_buf array is only built because it's passed to the FastRegister verb as a parameter. It's not needed by the xprtrdma layer.

> >
> > Grepping up through the callers....  It looks like the result is
> > xprt_rdma_send_request returns -EIO, and as far as I can tell that gets
> > passed up to the application on the client.   That doesn't sound right.
> 
> No worries, it was just a warning I noticed when I did an allmodconfig
> compilation.
> 
> Perhaps a comment there might be appropriate instead.
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
index 745973b..9cfebb4 100644
--- a/net/sunrpc/xprtrdma/verbs.c
+++ b/net/sunrpc/xprtrdma/verbs.c
@@ -1736,8 +1736,13 @@  rpcrdma_register_default_external(struct rpcrdma_mr_seg *seg,
 	int mem_priv = (writing ? IB_ACCESS_REMOTE_WRITE :
 				  IB_ACCESS_REMOTE_READ);
 	struct rpcrdma_mr_seg *seg1 = seg;
-	struct ib_phys_buf ipb[RPCRDMA_MAX_DATA_SEGS];
 	int len, i, rc = 0;
+	struct ib_phys_buf *ipb = kmalloc_array(RPCRDMA_MAX_DATA_SEGS,
+						sizeof(*ipb),
+						GFP_KERNEL);
+
+	if (!ipb)
+		return -ENOMEM;
 
 	if (*nsegs > RPCRDMA_MAX_DATA_SEGS)
 		*nsegs = RPCRDMA_MAX_DATA_SEGS;
@@ -1770,6 +1775,9 @@  rpcrdma_register_default_external(struct rpcrdma_mr_seg *seg,
 		seg1->mr_len = len;
 	}
 	*nsegs = i;
+
+	kfree(ipb);
+
 	return rc;
 }