Skip to contentSkip to conversation

sunrpc: verbs: Avoid 1kb stack

PATCH In review Joe Perches 3 participants 4 messages Jan 7, 2013 – Jan 8, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sunrpc: verbs: Avoid 1kb stack

16 * 64 is a bit much.
Use kmalloc_array instead.

---
 net/sunrpc/xprtrdma/verbs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/verbs.c +9 -1
index 745973b..9cfebb4 100644
@@ -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;
 }
 
#1 lore raw
Quoted 2 lines · Joe Perches

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.

Quoted 28 lines
---
 net/sunrpc/xprtrdma/verbs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/verbs.c +6 -1
index 745973b..9cfebb4 100644
@@ -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;

net/sunrpc/xprtrdma/verbs.c rpcrdma_register_default_external(struct rpcrdma_mr_seg *seg, · line 1783

Quoted 9 lines
net/sunrpc/xprtrdma/verbs.c +3 -0
@@ -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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 9 lines · J. Bruce Fields
Quoted 2 lines · Joe Perches

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.

#3 lore raw
Quoted 9 lines

-----Original Message-----
From: Joe Perches [mailto:[email protected]]
Sent: Tuesday, January 8, 2013 1:10 PM
To: J. Bruce Fields
Cc: Trond Myklebust; David S. Miller; [email protected]; [email protected]; [email protected]; Tom Tucker; [email protected]; Tom Talpey
Subject: Re: [PATCH] sunrpc: verbs: Avoid 1kb stack

Quoted 6 lines
Quoted 5 lines · J. Bruce Fields
Quoted 2 lines · Joe Perches

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.

Quoted 10 lines
Quoted 4 lines

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.