Skip to content

Commit 431f6eb

Browse files
author
Trond Myklebust
committed
SUNRPC: Add a label for RPC calls that require allocation on receive
If the RPC call relies on the receive call allocating pages as buffers, then let's label it so that we a) Don't leak memory by allocating pages for requests that do not expect this behaviour b) Can optimise for the common case where calls do not require allocation. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 79c9915 commit 431f6eb

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

fs/nfs/nfs3xdr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,10 +1364,12 @@ static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
13641364

13651365
encode_nfs_fh3(xdr, args->fh);
13661366
encode_uint32(xdr, args->mask);
1367-
if (args->mask & (NFS_ACL | NFS_DFACL))
1367+
if (args->mask & (NFS_ACL | NFS_DFACL)) {
13681368
prepare_reply_buffer(req, args->pages, 0,
13691369
NFSACL_MAXPAGES << PAGE_SHIFT,
13701370
ACL3_getaclres_sz);
1371+
req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
1372+
}
13711373
}
13721374

13731375
static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,

include/linux/sunrpc/xdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct xdr_buf {
5858
flags; /* Flags for data disposition */
5959
#define XDRBUF_READ 0x01 /* target of file read */
6060
#define XDRBUF_WRITE 0x02 /* source of file write */
61+
#define XDRBUF_SPARSE_PAGES 0x04 /* Page array is sparse */
6162

6263
unsigned int buflen, /* Total length of storage buffer */
6364
len; /* Length of XDR encoded message */

net/sunrpc/auth_gss/gss_rpc_xdr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ void gssx_enc_accept_sec_context(struct rpc_rqst *req,
784784
xdr_inline_pages(&req->rq_rcv_buf,
785785
PAGE_SIZE/2 /* pretty arbitrary */,
786786
arg->pages, 0 /* page base */, arg->npages * PAGE_SIZE);
787+
req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
787788
done:
788789
if (err)
789790
dprintk("RPC: gssx_enc_accept_sec_context: %d\n", err);

net/sunrpc/socklib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ssize_t xdr_partial_copy_from_skb(struct xdr_buf *xdr, unsigned int base, struct
104104

105105
/* ACL likes to be lazy in allocating pages - ACLs
106106
* are small by default but can get huge. */
107-
if (unlikely(*ppage == NULL)) {
107+
if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage == NULL) {
108108
*ppage = alloc_page(GFP_ATOMIC);
109109
if (unlikely(*ppage == NULL)) {
110110
if (copied == 0)

0 commit comments

Comments
 (0)