NFSv3: Improve NFSv3 performance when server returns no post-op attributes
Subsystems (2)
PATCH v2 1/3 NFSv3: Improve NFSv3 performance when server returns no post-op attributes
From: Trond Myklebust <[email protected]>
When the server fails to return post-op attributes, the client's attempt to place read data directly in the page cache fails, and so we have to do an extra copy in order to realign the data with page borders.
This patch attempts to detect servers that don't return post-op attributes on read (e.g. for pNFS) and adjusts the placement calculation accordingly.
--- fs/nfs/nfs3proc.c | 5 +++++ fs/nfs/nfs3xdr.c | 6 +++++- include/linux/nfs_fs_sb.h | 3 +++ include/linux/nfs_xdr.h | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-)
fs/nfs/nfs3proc.c +5 -0
@@ -786,6 +786,7 @@ nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,static int nfs3_read_done (struct rpc_task *task,struct nfs_pgio_header *hdr) {struct inode *inode = hdr->inode; +struct nfs_server *server =NFS_SERVER (inode);if (hdr->pgio_done_cb !=NULL )return hdr->pgio_done_cb (task, hdr);
@@ -793,6 +794,9 @@ static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)if (nfs3_async_handle_jukebox (task, inode))return -EAGAIN ; +if (task->tk_status >=0 && !server->read_hdrsize) +cmpxchg (&server->read_hdrsize,0 , hdr->res.replen); +nfs_invalidate_atime (inode);nfs_refresh_inode (inode, &hdr->fattr);return 0 ;
@@ -802,6 +806,7 @@ static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr, struct rpc_message *msg) { msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ ]; + hdr->args.replen =NFS_SERVER (hdr->inode)->read_hdrsize; } static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
fs/nfs/nfs3xdr.c +5 -1
@@ -983,10 +983,11 @@ static void nfs3_xdr_enc_read3args(struct rpc_rqst *req, const void *data) {const struct nfs_pgio_args *args = data; +unsigned int replen = args->replen ? args->replen : NFS3_readres_sz;encode_read3args (xdr, args);prepare_reply_buffer (req, args->pages, args->pgbase, - args->count, NFS3_readres_sz); + args->count, replen); req->rq_rcv_buf.flags |=XDRBUF_READ ; }
@@ -1675,9 +1676,11 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr, void *data) {struct nfs_pgio_res *result = data; +unsigned int pos;enum nfs_stat status;int error; + pos =xdr_stream_pos (xdr); error =decode_nfsstat3 (xdr, &status);if (unlikely (error)) goto out;
@@ -1687,6 +1690,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr, result->op_status = status;if (status !=NFS3_OK ) goto out_status; + result->replen =3 + ((xdr_stream_pos (xdr) - pos) >>2 ); error =decode_read3resok (xdr, result); out:return error;
include/linux/nfs_fs_sb.h +3 -0
@@ -228,6 +228,9 @@ struct nfs_server {unsigned short mountd_port;unsigned short mountd_protocol;struct rpc_wait_queue uoc_rpcwaitq; + +/* XDR related information */ +unsigned int read_hdrsize; };/* Server capabilities */
include/linux/nfs_xdr.h +2 -1
@@ -608,6 +608,7 @@ struct nfs_pgio_args {__u32 count;unsigned int pgbase;struct page ** pages; +unsigned int replen;/* used by read */ const u32 * bitmask;/* used by write */ enum nfs3_stable_how stable;/* used by write */ };
@@ -618,9 +619,9 @@ struct nfs_pgio_res {__u32 count;__u32 op_status;int eof;/* used by read */ +unsigned int replen;/* used by read */ struct nfs_writeverf * verf;/* used by write */ const struct nfs_server *server;/* used by write */ - };/*
Signature · 1 line
2.17.1
PATCH v2 2/3 NFSv4: Save a few bytes in the nfs_pgio_args/res
Save a few bytes by allowing the read/write specific fields of the structures to share storage.
--- include/linux/nfs_xdr.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
include/linux/nfs_xdr.h +17 -7
@@ -608,9 +608,13 @@ struct nfs_pgio_args {__u32 count;unsigned int pgbase;struct page ** pages; -unsigned int replen;/* used by read */ -const u32 * bitmask;/* used by write */ -enum nfs3_stable_how stable;/* used by write */ +union { +unsigned int replen;/* used by read */ +struct { +const u32 * bitmask;/* used by write */ +enum nfs3_stable_how stable;/* used by write */ + }; + }; };struct nfs_pgio_res {
@@ -618,10 +622,16 @@ struct nfs_pgio_res {struct nfs_fattr * fattr;__u32 count;__u32 op_status; -int eof;/* used by read */ -unsigned int replen;/* used by read */ -struct nfs_writeverf * verf;/* used by write */ -const struct nfs_server *server;/* used by write */ +union { +struct { +unsigned int replen;/* used by read */ +int eof;/* used by read */ + }; +struct { +struct nfs_writeverf * verf;/* used by write */ +const struct nfs_server *server;/* used by write */ + }; + }; };/*
Signature · 1 line
2.17.1
PATCH v2 3/3 NFS: Remove private spinlock in struct nfs_pgio_header
Now that each struct nfs_pgio_header corresponds to one RPC call, we only have one writer to the struct nfs_pgio_header.
--- fs/nfs/pagelist.c | 13 ++++++------- fs/nfs/read.c | 10 ++++------ include/linux/nfs_xdr.h | 5 ++--- 3 files changed, 12 insertions(+), 16 deletions(-)
fs/nfs/pagelist.c +6 -7
@@ -63,14 +63,14 @@ EXPORT_SYMBOL_GPL(nfs_pgheader_init);void nfs_set_pgio_error (struct nfs_pgio_header *hdr,int error,loff_t pos) { -spin_lock (&hdr->lock); -if (!test_and_set_bit (NFS_IOHDR_ERROR , &hdr->flags) - || pos < hdr->io_start + hdr->good_bytes) { +unsigned int new = pos - hdr->io_start; + +if (hdr->good_bytes > new) { + hdr->good_bytes = new;clear_bit (NFS_IOHDR_EOF , &hdr->flags); - hdr->good_bytes = pos - hdr->io_start; - hdr->error = error; +if (!test_and_set_bit (NFS_IOHDR_ERROR , &hdr->flags)) + hdr->error = error; } -spin_unlock (&hdr->lock); } static inline struct nfs_page *
@@ -494,7 +494,6 @@ struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *ops)if (hdr) {INIT_LIST_HEAD (&hdr->pages); -spin_lock_init (&hdr->lock); hdr->rw_ops = ops; }return hdr;
fs/nfs/read.c +4 -6
@@ -276,16 +276,14 @@ static void nfs_readpage_result(struct rpc_task *task, struct nfs_pgio_header *hdr) {if (hdr->res.eof) { -loff_t bound; +loff_t pos = hdr->args.offset + hdr->res.count; +unsigned int new = pos - hdr->io_start; - bound = hdr->args.offset + hdr->res.count; -spin_lock (&hdr->lock); -if (bound < hdr->io_start + hdr->good_bytes) { +if (hdr->good_bytes > new) { + hdr->good_bytes = new;set_bit (NFS_IOHDR_EOF , &hdr->flags);clear_bit (NFS_IOHDR_ERROR , &hdr->flags); - hdr->good_bytes = bound - hdr->io_start; } -spin_unlock (&hdr->lock); }else if (hdr->res.count < hdr->args.count)nfs_readpage_retry (task, hdr); }
include/linux/nfs_xdr.h +2 -3
@@ -1482,11 +1482,10 @@ struct nfs_pgio_header {const struct nfs_rw_ops *rw_ops;struct nfs_io_completion *io_completion;struct nfs_direct_req *dreq; -spinlock_t lock; -/* fields protected by lock */ +int pnfs_error;int error;/* merge with pnfs_error */ -unsigned long good_bytes;/* boundary of good data */ +unsigned int good_bytes;/* boundary of good data */ unsigned long flags;/*
Signature · 1 line
2.17.1