Add a "file_sync" export option
Subsystems (2)
[email protected]
maintainercover Add a "file_sync" export option
From: Chuck Lever <[email protected]>
This is a quick-and-dirty prototype of an idea we discussed briefly during the recent NFS bake-a-thon.
tmpfs exports don't need clients to send a COMMIT because they are not backed by persistent storage. NFSD can change all NFS WRITE operations to FILE_SYNC to signal to clients that COMMIT is not necessary.
The theory behind this is that waiting for the COMMIT adds latency. Without the COMMIT, applications should observe lower latency on write(2) and close(2).
We could make this an internal export flag that tmpfs sets, but there are other cases where a separate COMMIT might not be a benefit because the underlying storage device is faster than the network.
This patch aims to give administrators the ability to make that call for a whole export -- tmpfs, RAM disk-backed file systems, and file systems backed by NVMe might all benefit.
I've tested this patch (with a sibling patch to nfs-utils) and found that it doesn't make any difference on fast networks. Someone else might find it helps them, so I'm posting it here for others to try.
Chuck Lever (2):
NFSD: Return the actual stable_how value to clients
NFSD: Add a "file_sync" export option
fs/nfsd/export.c | 1 + fs/nfsd/nfs3proc.c | 2 +- fs/nfsd/nfs4proc.c | 3 +- fs/nfsd/nfsproc.c | 3 +- fs/nfsd/vfs.c | 54 ++++++++++++++++++++++++-------- fs/nfsd/vfs.h | 8 ++--- fs/nfsd/xdr3.h | 2 +- include/uapi/linux/nfsd/export.h | 3 +- 8 files changed, 54 insertions(+), 22 deletions(-)
Signature · 1 line
2.47.0
[email protected]
maintainerRFC PATCH 1/2 NFSD: Return the actual stable_how value to clients
From: Chuck Lever <[email protected]>
nfsd_vfs_write() may alter the stable_how value of an NFS WRITE operation. The current implementation does not convey that change back to the client, however. Instead it always returns the same value as the client sent in the request. This might cause a client to believe a FILE_SYNC WRITE payload was durable when in fact it was converted to an UNSTABLE WRITE.
In the future, nfsd_vfs_write() might make the converse alteration:
promoting an UNSTABLE WRITE to be a FILE_SYNC WRITE. This would signal that the client does not need a subsequent COMMIT operation. Therefore the change to stable_how has to appear in the server's WRITE response.
--- fs/nfsd/nfs3proc.c | 2 +- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfsproc.c | 3 ++- fs/nfsd/vfs.c | 49 +++++++++++++++++++++++++++++++++++----------- fs/nfsd/vfs.h | 8 ++++---- fs/nfsd/xdr3.h | 2 +- 6 files changed, 47 insertions(+), 19 deletions(-)
fs/nfsd/nfs3proc.c +1 -1
@@ -239,7 +239,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp) resp->status =nfsd_write (rqstp, &resp->fh, argp->offset, rqstp->rq_vec, nvecs, &cnt, - resp->committed, resp->verf); + &resp->committed, resp->verf); resp->count = cnt; resp->status =nfsd3_map_status (resp->status);return rpc_success;
fs/nfsd/nfs4proc.c +1 -1
@@ -1205,7 +1205,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, status =nfsd_vfs_write (rqstp, &cstate->current_fh, nf, write->wr_offset, rqstp->rq_vec, nvecs, &cnt, - write->wr_how_written, + &write->wr_how_written, (__be32 *)write->wr_verifier.data);nfsd_file_put (nf);
fs/nfsd/nfsproc.c +2 -1
@@ -250,6 +250,7 @@ nfsd_proc_write(struct svc_rqst *rqstp)struct nfsd_writeargs *argp = rqstp->rq_argp;struct nfsd_attrstat *resp = rqstp->rq_resp;unsigned long cnt = argp->len; +u32 committed =NFS_DATA_SYNC ;unsigned int nvecs; dprintk("nfsd: WRITE %s %u bytes at %d\n",
@@ -260,7 +261,7 @@ nfsd_proc_write(struct svc_rqst *rqstp) resp->status =nfsd_write (rqstp,fh_copy (&resp->fh, &argp->fh), argp->offset, rqstp->rq_vec, nvecs, - &cnt,NFS_DATA_SYNC ,NULL ); + &cnt, &committed,NULL );if (resp->status == nfs_ok) resp->status =fh_getattr (&resp->fh, &resp->stat);else if (resp->status == nfserr_jukebox)
fs/nfsd/vfs.c +38 -11
79 lines not on this page · raw message
fs/nfsd/vfs.h +4 -4
@@ -128,13 +128,13 @@ bool nfsd_read_splice_ok(struct svc_rqst *rqstp);__be32 nfsd_read (struct svc_rqst *rqstp,struct svc_fh *fhp,loff_t offset,unsigned long *count,u32 *eof); -__be32 nfsd_write (struct svc_rqst *,struct svc_fh *,loff_t , -struct kvec *,int ,unsigned long *, -int stable,__be32 *verf); +__be32 nfsd_write (struct svc_rqst *rqstp,struct svc_fh *fhp, +loff_t offset,struct kvec *vec,int vlen, +unsigned long *cnt,u32 *stable,__be32 *verf);__be32 nfsd_vfs_write (struct svc_rqst *rqstp,struct svc_fh *fhp,struct nfsd_file *nf,loff_t offset,struct kvec *vec,int vlen,unsigned long *cnt, -int stable,__be32 *verf); +u32 *stable,__be32 *verf);__be32 nfsd_readlink (struct svc_rqst *,struct svc_fh *,char *,int *); __be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *,
fs/nfsd/xdr3.h +1 -1
@@ -152,7 +152,7 @@ struct nfsd3_writeres {__be32 status;struct svc_fh fh;unsigned long count; -int committed; +u32 committed;__be32 verf[2 ]; };
Signature · 1 line
2.47.0
[email protected]
maintainerRFC PATCH 2/2 NFSD: Add a "file_sync" export option
In reply to [email protected]From: Chuck Lever <[email protected]>
Introduce the kernel pieces for a "file_sync" export option. This option would make all NFS WRITE operations on one export a FILE_SYNC WRITE.
There are two primary use cases for this new export option:
1. The exported file system is not backed by persistent storage. Thus a subsequent COMMIT will be a no-op. To prevent the client from wasting the extra round-trip on a COMMIT operation, convert all WRITEs to files on that export to FILE_SYNC.
2. The exported file system is backed by persistent storage that is faster than the mean network round trip with the client. Waiting for a separate COMMIT operation would cost more time than just committing the data during the WRITE operation.
Either the underlying persistent storage is faster than most any network fabric (eg, NVMe); or the network connection to the client is very high latency (eg, a WAN link).
--- fs/nfsd/export.c | 1 + fs/nfsd/nfs4proc.c | 1 + fs/nfsd/vfs.c | 5 +++-- include/uapi/linux/nfsd/export.h | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-)
fs/nfsd/export.c +1 -0
@@ -1297,6 +1297,7 @@ static struct flags { { NFSEXP_V4ROOT, {"v4root", ""}}, { NFSEXP_PNFS, {"pnfs", ""}}, { NFSEXP_SECURITY_LABEL, {"security_label", ""}}, + { NFSEXP_FILE_SYNC, {"file_sync", ""}}, { 0, {"", ""}} };
fs/nfsd/nfs4proc.c +1 -0
@@ -1269,6 +1269,7 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export)); +/* cel: check the "file_sync" export option as well */ nfsd_file_put (dst);nfsd_file_put (src);
fs/nfsd/vfs.c +3 -2
@@ -1205,9 +1205,10 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, exp = fhp->fh_export; -if (!EX_ISSYNC (exp)) +if (exp->ex_flags &NFSEXP_FILE_SYNC ) + *stable =NFS_FILE_SYNC ; +else if (!EX_ISSYNC (exp)) *stable =NFS_UNSTABLE ; -if (*stable && !fhp->fh_use_wgather) flags |=RWF_SYNC ;
include/uapi/linux/nfsd/export.h +2 -1
@@ -53,9 +53,10 @@*/ #define NFSEXP_V4ROOT 0x10000#define NFSEXP_PNFS 0x20000 +#define NFSEXP_FILE_SYNC 0x40000/* All flags that we claim to support. (Note we don't support NOACL.) */ -#define NFSEXP_ALLFLAGS 0x3FEFF +#define NFSEXP_ALLFLAGS 0x7FEFF/* The flags that may vary depending on security flavor: */ #define NFSEXP_SECINFO_FLAGS (NFSEXP_READONLY | NFSEXP_ROOTSQUASH \
Signature · 1 line
2.47.0