Skip to content

Commit 6ff40de

Browse files
author
J. Bruce Fields
committed
nfsd4: improve write performance with better sendspace reservations
Currently the rpc code conservatively refuses to accept rpc's from a client if the sum of its worst-case estimates of the replies it owes that client exceed the send buffer space. Unfortunately our estimate of the worst-case reply for an NFSv4 compound is always the maximum read size. This can unnecessarily limit the number of operations we handle concurrently, for example in the case most operations are writes (which have small replies). We can do a little better if we check which ops the compound contains. This is still a rough estimate, we'll need to improve on it some day. Reported-by: Shyam Kaushik <shyamnfs1@gmail.com> Tested-by: Shyam Kaushik <shyamnfs1@gmail.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 587ac5e commit 6ff40de

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎fs/nfsd/nfs4xdr.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,12 +1597,39 @@ nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op)
15971597
return true;
15981598
}
15991599

1600+
/*
1601+
* Return a rough estimate of the maximum possible reply size. Note the
1602+
* estimate includes rpc headers so is meant to be passed to
1603+
* svc_reserve, not svc_reserve_auth.
1604+
*
1605+
* Also note the current compound encoding permits only one operation to
1606+
* use pages beyond the first one, so the maximum possible length is the
1607+
* maximum over these values, not the sum.
1608+
*/
1609+
static int nfsd4_max_reply(u32 opnum)
1610+
{
1611+
switch (opnum) {
1612+
case OP_READLINK:
1613+
case OP_READDIR:
1614+
/*
1615+
* Both of these ops take a single page for data and put
1616+
* the head and tail in another page:
1617+
*/
1618+
return 2 * PAGE_SIZE;
1619+
case OP_READ:
1620+
return INT_MAX;
1621+
default:
1622+
return PAGE_SIZE;
1623+
}
1624+
}
1625+
16001626
static __be32
16011627
nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
16021628
{
16031629
DECODE_HEAD;
16041630
struct nfsd4_op *op;
16051631
bool cachethis = false;
1632+
int max_reply = PAGE_SIZE;
16061633
int i;
16071634

16081635
READ_BUF(4);
@@ -1652,10 +1679,14 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
16521679
* op in the compound wants to be cached:
16531680
*/
16541681
cachethis |= nfsd4_cache_this_op(op);
1682+
1683+
max_reply = max(max_reply, nfsd4_max_reply(op->opnum));
16551684
}
16561685
/* Sessions make the DRC unnecessary: */
16571686
if (argp->minorversion)
16581687
cachethis = false;
1688+
if (max_reply != INT_MAX)
1689+
svc_reserve(argp->rqstp, max_reply);
16591690
argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
16601691

16611692
DECODE_TAIL;

0 commit comments

Comments
 (0)