Skip to content

Commit 59cf734

Browse files
committed
sunrpc: Replace the rq_bvec array with dynamically-allocated memory
As a step towards making NFSD's maximum rsize and wsize variable at run-time, replace the fixed-size rq_bvec[] array in struct svc_rqst with a chunk of dynamically-allocated memory. The rq_bvec[] array contains enough bio_vecs to handle each page in a maximum size RPC message. On a system with 8-byte pointers and 4KB pages, pahole reports that the rq_bvec[] array is 4144 bytes. This patch replaces that array with a single 8-byte pointer field. Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent ed603bc commit 59cf734

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

include/linux/sunrpc/svc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct svc_rqst {
213213

214214
struct folio_batch rq_fbatch;
215215
struct kvec rq_vec[RPCSVC_MAXPAGES]; /* generally useful.. */
216-
struct bio_vec rq_bvec[RPCSVC_MAXPAGES];
216+
struct bio_vec *rq_bvec;
217217

218218
__be32 rq_xid; /* transmission id */
219219
u32 rq_prog; /* program number */

net/sunrpc/svc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ static void
672672
svc_rqst_free(struct svc_rqst *rqstp)
673673
{
674674
folio_batch_release(&rqstp->rq_fbatch);
675+
kfree(rqstp->rq_bvec);
675676
svc_release_buffer(rqstp);
676677
if (rqstp->rq_scratch_page)
677678
put_page(rqstp->rq_scratch_page);
@@ -710,6 +711,12 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
710711
if (!svc_init_buffer(rqstp, serv, node))
711712
goto out_enomem;
712713

714+
rqstp->rq_bvec = kcalloc_node(rqstp->rq_maxpages,
715+
sizeof(struct bio_vec),
716+
GFP_KERNEL, node);
717+
if (!rqstp->rq_bvec)
718+
goto out_enomem;
719+
713720
rqstp->rq_err = -EAGAIN; /* No error yet */
714721

715722
serv->sv_nrthreads += 1;

net/sunrpc/svcsock.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ static int svc_udp_sendto(struct svc_rqst *rqstp)
713713
if (svc_xprt_is_dead(xprt))
714714
goto out_notconn;
715715

716-
count = xdr_buf_to_bvec(rqstp->rq_bvec,
717-
ARRAY_SIZE(rqstp->rq_bvec), xdr);
716+
count = xdr_buf_to_bvec(rqstp->rq_bvec, rqstp->rq_maxpages, xdr);
718717

719718
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, rqstp->rq_bvec,
720719
count, rqstp->rq_res.len);
@@ -1219,8 +1218,8 @@ static int svc_tcp_sendmsg(struct svc_sock *svsk, struct svc_rqst *rqstp,
12191218
memcpy(buf, &marker, sizeof(marker));
12201219
bvec_set_virt(rqstp->rq_bvec, buf, sizeof(marker));
12211220

1222-
count = xdr_buf_to_bvec(rqstp->rq_bvec + 1,
1223-
ARRAY_SIZE(rqstp->rq_bvec) - 1, &rqstp->rq_res);
1221+
count = xdr_buf_to_bvec(rqstp->rq_bvec + 1, rqstp->rq_maxpages,
1222+
&rqstp->rq_res);
12241223

12251224
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, rqstp->rq_bvec,
12261225
1 + count, sizeof(marker) + rqstp->rq_res.len);

0 commit comments

Comments
 (0)