NFSD: additional NFSD Direct changes
Subsystems (3)
v4 cover NFSD: additional NFSD Direct changes
Hi,
This series builds ontop of what has been staged in nfsd-testing for NFSD Direct.
For now, I elected to use io_cache_write to expose control over stable_how when NFSD Direct is used, rather than a per-export control that can work with any NFSD IO mode. It seemed best to approach it this way until/unless there is a clear associated win.
But the benchmarking of stable_how variants is still pending (performance cluster that's required to do the benchmarking is tied up with higher priority work at the moment, so will need to circle back to that).
Thanks,
Mike
changes in v4:
- set flags_{buffered,direct} in nfsd_write_dio_iters_init()
- moving where flags_{buffered,direct} set exposed that nfsd_issue_dio_write should just be folded into nfsd_direct_write
- patch 2 was just rebased on patch 1
- patch 3 is unchanged
Mike Snitzer (3):
NFSD: avoid DONTCACHE for misaligned ends of misaligned DIO WRITE
NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
NFSD: update Documentation/filesystems/nfs/nfsd-io-modes.rst
.../filesystems/nfs/nfsd-io-modes.rst | 58 +++++----- fs/nfsd/debugfs.c | 7 +- fs/nfsd/nfsd.h | 2 + fs/nfsd/vfs.c | 109 ++++++++++-------- 4 files changed, 100 insertions(+), 76 deletions(-)
Signature · 1 line
2.44.0
PATCH v4 1/3 NFSD: avoid DONTCACHE for misaligned ends of misaligned DIO WRITE
NFSD_IO_DIRECT can easily improve streaming misaligned WRITE performance if it uses buffered IO (without DONTCACHE) for the misaligned end segment(s) and O_DIRECT for the aligned middle segment's IO.
On one capable testbed, this commit improved streaming 47008 byte write performance from 0.3433 GB/s to 1.26 GB/s.
This commit also merges nfsd_issue_dio_write into its only caller (nfsd_direct_write).
--- fs/nfsd/vfs.c | 73 ++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 42 deletions(-)
fs/nfsd/vfs.c +31 -42
@@ -1296,12 +1296,13 @@ nfsd_write_dio_seg_init(struct nfsd_write_dio_seg *segment,static void nfsd_write_dio_iters_init (struct bio_vec *bvec,unsigned int nvecs, -loff_t offset,unsigned long total, +struct kiocb *kiocb,unsigned long total,struct nfsd_write_dio_args *args) {u32 offset_align = args->nf->nf_dio_offset_align;u32 mem_align = args->nf->nf_dio_mem_align;loff_t prefix_end, orig_end, middle_end; +loff_t offset = kiocb->ki_pos;size_t prefix, middle, suffix; args->nsegs =0 ;
@@ -1347,6 +1348,8 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs, ++args->nsegs; } + args->flags_buffered = kiocb->ki_flags; + args->flags_direct = kiocb->ki_flags |IOCB_DIRECT ;return ; no_dio:
@@ -1354,39 +1357,14 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs,nfsd_write_dio_seg_init (&args->segment[0 ], bvec, nvecs, total,0 , total); args->nsegs =1 ; -} -static int -nfsd_issue_dio_write (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct kiocb *kiocb,unsigned int nvecs, -unsigned long *cnt,struct nfsd_write_dio_args *args) -{ -struct file *file = args->nf->nf_file; -ssize_t host_err; -unsigned int i; - -nfsd_write_dio_iters_init (rqstp->rq_bvec, nvecs, kiocb->ki_pos, - *cnt, args); - - *cnt =0 ; -for (i =0 ; i < args->nsegs; i++) { -if (args->segment[i].use_dio) { - kiocb->ki_flags = args->flags_direct; -trace_nfsd_write_direct (rqstp, fhp, kiocb->ki_pos, - args->segment[i].iter.count); - }else - kiocb->ki_flags = args->flags_buffered; - - host_err =vfs_iocb_iter_write (file, kiocb, - &args->segment[i].iter); -if (host_err <0 ) -return host_err; - *cnt += host_err; -if (host_err < args->segment[i].iter.count) -break ;/* partial write */ - } - -return 0 ; +/* +* IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT when +* falling back to buffered IO if the entire WRITE is unaligned. +*/ + args->flags_buffered = kiocb->ki_flags; +if (args->nf->nf_file->f_op->fop_flags &FOP_DONTCACHE ) + args->flags_buffered |=IOCB_DONTCACHE ; }static noinline_for_stack int
@@ -1395,20 +1373,31 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned long *cnt, struct kiocb *kiocb) { struct nfsd_write_dio_args args; +ssize_t host_err; +unsigned int i; args.nf = nf; +nfsd_write_dio_iters_init (rqstp->rq_bvec, nvecs, kiocb, *cnt, &args); -/* -* IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT when -* writing unaligned segments or handling fallback I/O. -*/ - args.flags_buffered = kiocb->ki_flags; -if (args.nf->nf_file->f_op->fop_flags &FOP_DONTCACHE ) - args.flags_buffered |=IOCB_DONTCACHE ; + *cnt =0 ; +for (i =0 ; i < args.nsegs; i++) { +if (args.segment[i].use_dio) { + kiocb->ki_flags = args.flags_direct; +trace_nfsd_write_direct (rqstp, fhp, kiocb->ki_pos, + args.segment[i].iter.count); + }else + kiocb->ki_flags = args.flags_buffered; - args.flags_direct = kiocb->ki_flags |IOCB_DIRECT ; + host_err =vfs_iocb_iter_write (nf->nf_file, kiocb, + &args.segment[i].iter); +if (host_err <0 ) +return host_err; + *cnt += host_err; +if (host_err < args.segment[i].iter.count) +break ;/* partial write */ + } -return nfsd_issue_dio_write (rqstp, fhp, kiocb, nvecs, cnt, &args); +return 0 ; }/**
Signature · 1 line
2.44.0
Re: [PATCH v4 1/3] NFSD: avoid DONTCACHE for misaligned ends of misaligned DIO WRITE
Quoted 122 lines · Mike Snitzer
NFSD_IO_DIRECTcan easily improve streaming misaligned WRITE performance if it uses buffered IO (without DONTCACHE) for the misaligned end segment(s) andO_DIRECTfor the aligned middle segment's IO.On one capable testbed, this commit improved streaming 47008 byte write performance from 0.3433 GB/s to 1.26 GB/s.
This commit also merges
nfsd_issue_dio_writeinto its only caller (nfsd_direct_write).Signed-off-by Mike Snitzer <[email protected]>--- fs/nfsd/vfs.c | 73 ++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 42 deletions(-)fs/nfsd/vfs.c +26
-41@@ -1296,12 +1296,13 @@ nfsd_write_dio_seg_init(struct nfsd_write_dio_seg *segment,static void nfsd_write_dio_iters_init (struct bio_vec *bvec,unsigned int nvecs, -loff_t offset,unsigned long total, +struct kiocb *kiocb,unsigned long total,struct nfsd_write_dio_args *args) {u32 offset_align = args->nf->nf_dio_offset_align;u32 mem_align = args->nf->nf_dio_mem_align;loff_t prefix_end, orig_end, middle_end; +loff_t offset = kiocb->ki_pos;size_t prefix, middle, suffix; args->nsegs =0 ;@@ -1347,6 +1348,8 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs, ++args->nsegs; } + args->flags_buffered = kiocb->ki_flags; + args->flags_direct = kiocb->ki_flags |IOCB_DIRECT ;return ; no_dio:@@ -1354,39 +1357,14 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs,nfsd_write_dio_seg_init (&args->segment[0 ], bvec, nvecs, total,0 , total); args->nsegs =1 ; -} -static int -nfsd_issue_dio_write (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct kiocb *kiocb,unsigned int nvecs, -unsigned long *cnt,struct nfsd_write_dio_args *args) -{ -struct file *file = args->nf->nf_file; -ssize_t host_err; -unsigned int i; - -nfsd_write_dio_iters_init (rqstp->rq_bvec, nvecs, kiocb->ki_pos, - *cnt, args); - - *cnt =0 ; -for (i =0 ; i < args->nsegs; i++) { -if (args->segment[i].use_dio) { - kiocb->ki_flags = args->flags_direct; -trace_nfsd_write_direct (rqstp, fhp, kiocb->ki_pos, - args->segment[i].iter.count); - }else - kiocb->ki_flags = args->flags_buffered; - - host_err =vfs_iocb_iter_write (file, kiocb, - &args->segment[i].iter); -if (host_err <0 ) -return host_err; - *cnt += host_err; -if (host_err < args->segment[i].iter.count) -break ;/* partial write */ - } - -return 0 ; +/* +* IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT when +* falling back to buffered IO if the entire WRITE is unaligned. +*/ + args->flags_buffered = kiocb->ki_flags; +if (args->nf->nf_file->f_op->fop_flags &FOP_DONTCACHE ) + args->flags_buffered |=IOCB_DONTCACHE ; }static noinline_for_stack int@@ -1395,20 +1373,31 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned long *cnt, struct kiocb *kiocb) { struct nfsd_write_dio_args args; +ssize_t host_err; +unsigned int i; args.nf = nf; +nfsd_write_dio_iters_init (rqstp->rq_bvec, nvecs, kiocb, *cnt, &args); -/* -* IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT when -* writing unaligned segments or handling fallback I/O. -*/ - args.flags_buffered = kiocb->ki_flags; -if (args.nf->nf_file->f_op->fop_flags &FOP_DONTCACHE ) - args.flags_buffered |=IOCB_DONTCACHE ; + *cnt =0 ; +for (i =0 ; i < args.nsegs; i++) { +if (args.segment[i].use_dio) { + kiocb->ki_flags = args.flags_direct; +trace_nfsd_write_direct (rqstp, fhp, kiocb->ki_pos, + args.segment[i].iter.count); + }else + kiocb->ki_flags = args.flags_buffered; - args.flags_direct = kiocb->ki_flags |IOCB_DIRECT ; + host_err =vfs_iocb_iter_write (nf->nf_file, kiocb, + &args.segment[i].iter); +if (host_err <0 ) +return host_err;
fs/nfsd/vfs.c nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 1403
Quoted 10 lines
fs/nfsd/vfs.c +5
-1+ *cnt += host_err; +if (host_err < args.segment[i].iter.count) +break ;/* partial write */ + } -return nfsd_issue_dio_write (rqstp, fhp, kiocb, nvecs, cnt, &args); +return 0 ; }/**
This is not at all what I had in mind. I'll fold something into the jumbo patch roll up for v10.
Signature · 1 line
Chuck Lever
Re: [PATCH v4 1/3] NFSD: avoid DONTCACHE for misaligned ends of misaligned DIO WRITE
In reply to Mike SnitzerQuoted 7 lines · Mike Snitzer
NFSD_IO_DIRECTcan easily improve streaming misaligned WRITE performance if it uses buffered IO (without DONTCACHE) for the misaligned end segment(s) andO_DIRECTfor the aligned middle segment's IO.On one capable testbed, this commit improved streaming 47008 byte write performance from 0.3433 GB/s to 1.26 GB/s.
When you say "improved streaming 47008 byte write performance" do you mean the application on the client doing writes of 47008 bytes for each syscall, probably synchronous? Why is a workload that matters? How do the numbers look for normal writes that are aligned to a power of two, and especially the preferred write size exposed by the client in st_blksize?
PATCH v4 2/3 NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
In reply to Mike SnitzerNFSD_IO_DIRECT_WRITE_FILE_SYNC is direct IO with stable_how=NFS_FILE_SYNC. NFSD_IO_DIRECT_WRITE_DATA_SYNC is direct IO with stable_how=NFS_DATA_SYNC.
The stable_how associated with each is a hint in the form of a "floor" value for stable_how. Meaning if the client provided stable_how is already of higher value it will not be changed.
These permutations of NFSD_IO_DIRECT allow to experiment with also elevating stable_how and sending it back to the client. Which for NFSD_IO_DIRECT_WRITE_FILE_SYNC will cause the client to elide its COMMIT.
--- fs/nfsd/debugfs.c | 7 ++++++- fs/nfsd/nfsd.h | 2 ++ fs/nfsd/vfs.c | 46 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 13 deletions(-)
fs/nfsd/debugfs.c +6 -1
@@ -68,7 +68,7 @@ static int nfsd_io_cache_read_set(void *data, u64 val)case NFSD_IO_DIRECT :/* * Must disable splice_read when enabling -* NFSD_IO_DONTCACHE. +* NFSD_IO_DONTCACHE and NFSD_IO_DIRECT. */ nfsd_disable_splice_read = true; nfsd_io_cache_read = val;
@@ -90,6 +90,9 @@ DEFINE_DEBUGFS_ATTRIBUTE(nfsd_io_cache_read_fops, nfsd_io_cache_read_get,* Contents: * %0: NFS WRITE will use buffered IO * %1: NFS WRITE will use dontcache (buffered IO w/ dropbehind) +* %2: NFS WRITE will use direct IO with stable_how=NFS_UNSTABLE +* %3: NFS WRITE will use direct IO with stable_how=NFS_DATA_SYNC +* %4: NFS WRITE will use direct IO with stable_how=NFS_FILE_SYNC * * This setting takes immediate effect for all NFS versions, * all exports, and in all NFSD net namespaces.
@@ -109,6 +112,8 @@ static int nfsd_io_cache_write_set(void *data, u64 val)case NFSD_IO_BUFFERED :case NFSD_IO_DONTCACHE :case NFSD_IO_DIRECT : +case NFSD_IO_DIRECT_WRITE_DATA_SYNC : +case NFSD_IO_DIRECT_WRITE_FILE_SYNC : nfsd_io_cache_write = val;break ;default :
fs/nfsd/nfsd.h +2 -0
@@ -161,6 +161,8 @@ enum {NFSD_IO_BUFFERED ,NFSD_IO_DONTCACHE ,NFSD_IO_DIRECT , +NFSD_IO_DIRECT_WRITE_DATA_SYNC , + NFSD_IO_DIRECT_WRITE_FILE_SYNC, };extern u64 nfsd_io_cache_read__read_mostly ;
fs/nfsd/vfs.c +34 -12
73 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 136 lines · Mike Snitzer
NFSD_IO_DIRECT_WRITE_FILE_SYNCis direct IO with stable_how=NFS_FILE_SYNC.NFSD_IO_DIRECT_WRITE_DATA_SYNCis direct IO with stable_how=NFS_DATA_SYNC.The
stable_howassociated with each is a hint in the form of a "floor" value forstable_how. Meaning if the client providedstable_howis already of higher value it will not be changed.These permutations of
NFSD_IO_DIRECTallow to experiment with also elevatingstable_howand sending it back to the client. Which forNFSD_IO_DIRECT_WRITE_FILE_SYNCwill cause the client to elide its COMMIT.Signed-off-by Mike Snitzer <[email protected]>--- fs/nfsd/debugfs.c | 7 ++++++- fs/nfsd/nfsd.h | 2 ++ fs/nfsd/vfs.c | 46 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 13 deletions(-)fs/nfsd/debugfs.c +6
-1@@ -68,7 +68,7 @@ static int nfsd_io_cache_read_set(void *data, u64 val)case NFSD_IO_DIRECT :/* * Must disable splice_read when enabling -* NFSD_IO_DONTCACHE. +* NFSD_IO_DONTCACHE and NFSD_IO_DIRECT. */ nfsd_disable_splice_read = true; nfsd_io_cache_read = val;@@ -90,6 +90,9 @@ DEFINE_DEBUGFS_ATTRIBUTE(nfsd_io_cache_read_fops, nfsd_io_cache_read_get,* Contents: * %0: NFS WRITE will use buffered IO * %1: NFS WRITE will use dontcache (buffered IO w/ dropbehind) +* %2: NFS WRITE will use direct IO with stable_how=NFS_UNSTABLE +* %3: NFS WRITE will use direct IO with stable_how=NFS_DATA_SYNC +* %4: NFS WRITE will use direct IO with stable_how=NFS_FILE_SYNC * * This setting takes immediate effect for all NFS versions, * all exports, and in all NFSD net namespaces. @@ -109,6 +112,8 @@ static int nfsd_io_cache_write_set(void *data, u64 val)case NFSD_IO_BUFFERED :case NFSD_IO_DONTCACHE :case NFSD_IO_DIRECT : +case NFSD_IO_DIRECT_WRITE_DATA_SYNC : +case NFSD_IO_DIRECT_WRITE_FILE_SYNC : nfsd_io_cache_write = val;break ;default :fs/nfsd/nfsd.h +2
-0@@ -161,6 +161,8 @@ enum {NFSD_IO_BUFFERED ,NFSD_IO_DONTCACHE ,NFSD_IO_DIRECT , +NFSD_IO_DIRECT_WRITE_DATA_SYNC , + NFSD_IO_DIRECT_WRITE_FILE_SYNC, };extern u64 nfsd_io_cache_read__read_mostly ;fs/nfsd/vfs.c +32
-12@@ -1367,15 +1367,45 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs, args->flags_buffered |=IOCB_DONTCACHE ; } +static void +nfsd_init_write_kiocb_from_stable (u32 stable_floor, +struct kiocb *kiocb, +u32 *stable_how) +{ +if (stable_floor < *stable_how) +return ;/* stable_how already set higher */ + + *stable_how = stable_floor; + +switch (stable_floor) { +case NFS_FILE_SYNC : +/* persist data and timestamps */ + kiocb->ki_flags |=IOCB_DSYNC |IOCB_SYNC ; +break ; +case NFS_DATA_SYNC : +/* persist data only */ + kiocb->ki_flags |=IOCB_DSYNC ; +break ; + } +} + static noinline_for_stack intnfsd_direct_write (struct svc_rqst *rqstp,struct svc_fh *fhp,struct nfsd_file *nf,u32 *stable_how,unsigned int nvecs,unsigned long *cnt,struct kiocb *kiocb) { +u32 stable_floor =NFS_UNSTABLE ;struct nfsd_write_dio_args args;ssize_t host_err;unsigned int i; +if (nfsd_io_cache_write ==NFSD_IO_DIRECT_WRITE_FILE_SYNC ) + stable_floor =NFS_FILE_SYNC ; +else if (nfsd_io_cache_write ==NFSD_IO_DIRECT_WRITE_DATA_SYNC ) + stable_floor =NFS_DATA_SYNC ; +if (stable_floor !=NFS_UNSTABLE ) +nfsd_init_write_kiocb_from_stable (stable_floor, kiocb, + stable_how); args.nf = nf;nfsd_write_dio_iters_init (rqstp->rq_bvec, nvecs, kiocb, *cnt, &args);@@ -1461,18 +1491,8 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, stable =NFS_UNSTABLE ;init_sync_kiocb (&kiocb, file); kiocb.ki_pos = offset; -if (likely (!fhp->fh_use_wgather)) { -switch (stable) { -case NFS_FILE_SYNC : -/* persist data and timestamps */ - kiocb.ki_flags |=IOCB_DSYNC |IOCB_SYNC ; -break ; -case NFS_DATA_SYNC : -/* persist data only */ - kiocb.ki_flags |=IOCB_DSYNC ; -break ; - } - } +if (likely (!fhp->fh_use_wgather)) +nfsd_init_write_kiocb_from_stable (stable, &kiocb, stable_how); nvecs =xdr_buf_to_bvec (rqstp->rq_bvec, rqstp->rq_maxpages, payload);
fs/nfsd/vfs.c nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 1509
Quoted 8 lines
fs/nfsd/vfs.c +2
-0@@ -1482,6 +1502,8 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,switch (nfsd_io_cache_write) {case NFSD_IO_DIRECT : +case NFSD_IO_DIRECT_WRITE_DATA_SYNC : +case NFSD_IO_DIRECT_WRITE_FILE_SYNC : host_err =nfsd_direct_write (rqstp, fhp, nf, stable_how, nvecs, cnt, &kiocb); stable = *stable_how;
I asked for the use of a file_sync export option because we need to test the BUFFERED cache mode as well as DIRECT. So, continue to experiment with this one, but I don't plan to merge it for now.
Signature · 1 line
Chuck Lever
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 138 lines · Chuck Lever
Quoted 137 lines · Mike Snitzer
NFSD_IO_DIRECT_WRITE_FILE_SYNCis direct IO with stable_how=NFS_FILE_SYNC.NFSD_IO_DIRECT_WRITE_DATA_SYNCis direct IO with stable_how=NFS_DATA_SYNC.The
stable_howassociated with each is a hint in the form of a "floor" value forstable_how. Meaning if the client providedstable_howis already of higher value it will not be changed.These permutations of
NFSD_IO_DIRECTallow to experiment with also elevatingstable_howand sending it back to the client. Which forNFSD_IO_DIRECT_WRITE_FILE_SYNCwill cause the client to elide its COMMIT.Signed-off-by Mike Snitzer <[email protected]>--- fs/nfsd/debugfs.c | 7 ++++++- fs/nfsd/nfsd.h | 2 ++ fs/nfsd/vfs.c | 46 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 13 deletions(-)fs/nfsd/debugfs.c +6
-1@@ -68,7 +68,7 @@ static int nfsd_io_cache_read_set(void *data, u64 val)case NFSD_IO_DIRECT :/* * Must disable splice_read when enabling -* NFSD_IO_DONTCACHE. +* NFSD_IO_DONTCACHE and NFSD_IO_DIRECT. */ nfsd_disable_splice_read = true; nfsd_io_cache_read = val;@@ -90,6 +90,9 @@ DEFINE_DEBUGFS_ATTRIBUTE(nfsd_io_cache_read_fops, nfsd_io_cache_read_get,* Contents: * %0: NFS WRITE will use buffered IO * %1: NFS WRITE will use dontcache (buffered IO w/ dropbehind) +* %2: NFS WRITE will use direct IO with stable_how=NFS_UNSTABLE +* %3: NFS WRITE will use direct IO with stable_how=NFS_DATA_SYNC +* %4: NFS WRITE will use direct IO with stable_how=NFS_FILE_SYNC * * This setting takes immediate effect for all NFS versions, * all exports, and in all NFSD net namespaces. @@ -109,6 +112,8 @@ static int nfsd_io_cache_write_set(void *data, u64 val)case NFSD_IO_BUFFERED :case NFSD_IO_DONTCACHE :case NFSD_IO_DIRECT : +case NFSD_IO_DIRECT_WRITE_DATA_SYNC : +case NFSD_IO_DIRECT_WRITE_FILE_SYNC : nfsd_io_cache_write = val;break ;default :fs/nfsd/nfsd.h +2
-0@@ -161,6 +161,8 @@ enum {NFSD_IO_BUFFERED ,NFSD_IO_DONTCACHE ,NFSD_IO_DIRECT , +NFSD_IO_DIRECT_WRITE_DATA_SYNC , + NFSD_IO_DIRECT_WRITE_FILE_SYNC, };extern u64 nfsd_io_cache_read__read_mostly ;fs/nfsd/vfs.c +32
-12@@ -1367,15 +1367,45 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs, args->flags_buffered |=IOCB_DONTCACHE ; } +static void +nfsd_init_write_kiocb_from_stable (u32 stable_floor, +struct kiocb *kiocb, +u32 *stable_how) +{ +if (stable_floor < *stable_how) +return ;/* stable_how already set higher */ + + *stable_how = stable_floor; + +switch (stable_floor) { +case NFS_FILE_SYNC : +/* persist data and timestamps */ + kiocb->ki_flags |=IOCB_DSYNC |IOCB_SYNC ; +break ; +case NFS_DATA_SYNC : +/* persist data only */ + kiocb->ki_flags |=IOCB_DSYNC ; +break ; + } +} + static noinline_for_stack intnfsd_direct_write (struct svc_rqst *rqstp,struct svc_fh *fhp,struct nfsd_file *nf,u32 *stable_how,unsigned int nvecs,unsigned long *cnt,struct kiocb *kiocb) { +u32 stable_floor =NFS_UNSTABLE ;struct nfsd_write_dio_args args;ssize_t host_err;unsigned int i; +if (nfsd_io_cache_write ==NFSD_IO_DIRECT_WRITE_FILE_SYNC ) + stable_floor =NFS_FILE_SYNC ; +else if (nfsd_io_cache_write ==NFSD_IO_DIRECT_WRITE_DATA_SYNC ) + stable_floor =NFS_DATA_SYNC ; +if (stable_floor !=NFS_UNSTABLE ) +nfsd_init_write_kiocb_from_stable (stable_floor, kiocb, + stable_how); args.nf = nf;nfsd_write_dio_iters_init (rqstp->rq_bvec, nvecs, kiocb, *cnt, &args);@@ -1461,18 +1491,8 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, stable =NFS_UNSTABLE ;init_sync_kiocb (&kiocb, file); kiocb.ki_pos = offset; -if (likely (!fhp->fh_use_wgather)) { -switch (stable) { -case NFS_FILE_SYNC : -/* persist data and timestamps */ - kiocb.ki_flags |=IOCB_DSYNC |IOCB_SYNC ; -break ; -case NFS_DATA_SYNC : -/* persist data only */ - kiocb.ki_flags |=IOCB_DSYNC ; -break ; - } - } +if (likely (!fhp->fh_use_wgather)) +nfsd_init_write_kiocb_from_stable (stable, &kiocb, stable_how); nvecs =xdr_buf_to_bvec (rqstp->rq_bvec, rqstp->rq_maxpages, payload);@@ -1482,6 +1502,8 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
Quoted 12 lines
fs/nfsd/vfs.c nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 1509
Quoted 7 lines
fs/nfsd/vfs.c +2
-0switch (nfsd_io_cache_write) {case NFSD_IO_DIRECT : +case NFSD_IO_DIRECT_WRITE_DATA_SYNC : +case NFSD_IO_DIRECT_WRITE_FILE_SYNC : host_err =nfsd_direct_write (rqstp, fhp, nf, stable_how, nvecs, cnt, &kiocb); stable = *stable_how;I asked for the use of a
file_syncexport option because we need to test the BUFFERED cache mode as well as DIRECT. So, continue to experiment with this one, but I don't plan to merge it for now.
Doesn't the client have the ability to control NFS_UNSTABLE, NFS_DATA_SYNC and NFS_FILE_SYNC already? What experiment are you looking to run?
If just looking to compare NFS_FILE_SYNC performance of NFSD_IO_BUFFERED versus NFSD_IO_DIRECT then using the client control is fine right?
Anyway, maybe I'm just being overly concerned about the permanence of an export option. I thought it best to avoid export for now given we do seem to have adequate controls for a NFS_FILE_SYNC performance bakeoff.
Here is a rebased patch that applies ontop of Christoph's cleanup and my incremental Documentation patch. I would appreciate us exposing this NFSD stable_how "floor" control so others can try. But if this still isn't OK, due it to being in terms of NFSD_IO_DIRECT debugfs knobs, then I can pursue a generic export option that works for all NFS IO modes.
Thanks,
Mike
From: Mike Snitzer <[email protected]>
Date: Thu, 30 Oct 2025 17:53:09 -0400
Subject: [PATCH v4 rebased] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
NFSD_IO_DIRECT_WRITE_FILE_SYNC is direct IO with stable_how=NFS_FILE_SYNC. NFSD_IO_DIRECT_WRITE_DATA_SYNC is direct IO with stable_how=NFS_DATA_SYNC.
The stable_how associated with each is a hint in the form of a "floor" value for stable_how. Meaning if the client provided stable_how is already of higher value it will not be changed.
These permutations of NFSD_IO_DIRECT allow to experiment with also elevating stable_how and sending it back to the client. Which for NFSD_IO_DIRECT_WRITE_FILE_SYNC will cause the client to elide its COMMIT.
--- .../filesystems/nfs/nfsd-io-modes.rst | 6 ++- fs/nfsd/debugfs.c | 7 ++- fs/nfsd/nfsd.h | 2 + fs/nfsd/vfs.c | 54 +++++++++++++------ 4 files changed, 51 insertions(+), 18 deletions(-)
Documentation/filesystems/nfs/nfsd-io-modes.rst +4 -2
@@ -23,11 +23,13 @@ Based on the configured settings, NFSD's IO will either be: - cached using page cache (NFSD_IO_BUFFERED=0) - cached but removed from page cache on completion (NFSD_IO_DONTCACHE=1) - not cached stable_how=NFS_UNSTABLE (NFSD_IO_DIRECT=2) +- not cached stable_how=NFS_DATA_SYNC (NFSD_IO_DIRECT_WRITE_DATA_SYNC=3) +- not cached stable_how=NFS_FILE_SYNC (NFSD_IO_DIRECT_WRITE_FILE_SYNC=4) -To set an NFSD IO mode, write a supported value (0 - 2) to the +To set an NFSD IO mode, write a supported value (0 - 4) to the corresponding IO operation's debugfs interface, e.g.: echo 2 > /sys/kernel/debug/nfsd/io_cache_read - echo 2 > /sys/kernel/debug/nfsd/io_cache_write + echo 4 > /sys/kernel/debug/nfsd/io_cache_write To check which IO mode NFSD is using for READ or WRITE, simply read the corresponding IO operation's debugfs interface, e.g.:
fs/nfsd/debugfs.c +6 -1
@@ -68,7 +68,7 @@ static int nfsd_io_cache_read_set(void *data, u64 val)case NFSD_IO_DIRECT :/* * Must disable splice_read when enabling -* NFSD_IO_DONTCACHE. +* NFSD_IO_DONTCACHE and NFSD_IO_DIRECT. */ nfsd_disable_splice_read = true; nfsd_io_cache_read = val;
@@ -90,6 +90,9 @@ DEFINE_DEBUGFS_ATTRIBUTE(nfsd_io_cache_read_fops, nfsd_io_cache_read_get,* Contents: * %0: NFS WRITE will use buffered IO * %1: NFS WRITE will use dontcache (buffered IO w/ dropbehind) +* %2: NFS WRITE will use direct IO with stable_how=NFS_UNSTABLE +* %3: NFS WRITE will use direct IO with stable_how=NFS_DATA_SYNC +* %4: NFS WRITE will use direct IO with stable_how=NFS_FILE_SYNC * * This setting takes immediate effect for all NFS versions, * all exports, and in all NFSD net namespaces.
@@ -109,6 +112,8 @@ static int nfsd_io_cache_write_set(void *data, u64 val)case NFSD_IO_BUFFERED :case NFSD_IO_DONTCACHE :case NFSD_IO_DIRECT : +case NFSD_IO_DIRECT_WRITE_DATA_SYNC : +case NFSD_IO_DIRECT_WRITE_FILE_SYNC : nfsd_io_cache_write = val;break ;default :
fs/nfsd/nfsd.h +2 -0
@@ -161,6 +161,8 @@ enum {NFSD_IO_BUFFERED ,NFSD_IO_DONTCACHE ,NFSD_IO_DIRECT , +NFSD_IO_DIRECT_WRITE_DATA_SYNC , + NFSD_IO_DIRECT_WRITE_FILE_SYNC, };extern u64 nfsd_io_cache_read__read_mostly ;
fs/nfsd/vfs.c +39 -15
81 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 10 lines · Mike Snitzer
Quoted 3 lines
I asked for the use of a
file_syncexport option because we need to test the BUFFERED cache mode as well as DIRECT. So, continue to experiment with this one, but I don't plan to merge it for now.Doesn't the client have the ability to control
NFS_UNSTABLE,NFS_DATA_SYNCandNFS_FILE_SYNCalready? What experiment are you looking to run?If just looking to compare
NFS_FILE_SYNCperformance ofNFSD_IO_BUFFEREDversusNFSD_IO_DIRECTthen using the client control is fine right?
Not necessarily. You can mount with "sync" but for large application write requests, that might still generate UNSTABLE + immediate COMMIT.
Quoted 4 lines
Anyway, maybe I'm just being overly concerned about the permanence of an export option. I thought it best to avoid export for now given we do seem to have adequate controls for a
NFS_FILE_SYNCperformance bakeoff.
I agree on not rushing another administrative API change. I was thinking you would be prototyping some of this stuff first and playing with it for a little while before it goes upstream.
It feels like it would be much more straightforward to implement an export option that applies to all cache modes rather than gluing it to DIRECT.
And as I said above, "no plan to merge it for now," meaning it's still on the table for sometime down the road. I have some other ideas I'm cooking up, such as using BDI congestion to control NFS WRITE throttling.
But let's get the base direct WRITE stuff finished.
Signature · 1 line
Chuck Lever
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 8 lines · Chuck Lever
Quoted 7 lines · Mike Snitzer
Quoted 3 lines
I asked for the use of a
file_syncexport option because we need to test the BUFFERED cache mode as well as DIRECT. So, continue to experiment with this one, but I don't plan to merge it for now.Doesn't the client have the ability to control
NFS_UNSTABLE,NFS_DATA_SYNCandNFS_FILE_SYNCalready? What experiment are you looking to run?
Quoted 6 lines
Quoted 3 lines
If just looking to compare
NFS_FILE_SYNCperformance ofNFSD_IO_BUFFEREDversusNFSD_IO_DIRECTthen using the client control is fine right?Not necessarily. You can mount with "sync" but for large application write requests, that might still generate UNSTABLE + immediate COMMIT.
OK, I'll take a closer look at NFS client controls for stable_how, because NFSD clearly handles NFS_DATA_SYNC and NFS_FILE_SYNC so I just assumed its because the client does actually send them.
Quoted 5 lines
Quoted 4 lines
Anyway, maybe I'm just being overly concerned about the permanence of an export option. I thought it best to avoid export for now given we do seem to have adequate controls for a
NFS_FILE_SYNCperformance bakeoff.
Quoted 7 lines
I agree on not rushing another administrative API change. I was thinking you would be prototyping some of this stuff first and playing with it for a little while before it goes upstream.
It feels like it would be much more straightforward to implement an export option that applies to all cache modes rather than gluing it to DIRECT.
OK, I'll carry the patch in Hammerspace kernel for the time being so Jon Flynn can test whenever he has availability,
Quoted 4 lines
And as I said above, "no plan to merge it for now," meaning it's still on the table for sometime down the road. I have some other ideas I'm cooking up, such as using BDI congestion to control NFS WRITE throttling.
Hmm, I thought the BDI congestion infra got killed (by Jan Kara and others).. which made me sad because when it was first introduced it was amazing at solving some complex deadlocks (but we're talking 20 years ago now). So I haven't kept my finger on the pulse of what is still available to us relative to BDI congestion.
Another possiblity is the PSI data, that infra was put in place by Meta to deal with exactly the sitution we're confronting: take action(s) when pressure builds to a particular threshold.
Quoted 1 line
But let's get the base direct WRITE stuff finished.
Yes.
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 13 lines · Mike Snitzer
Quoted 12 lines · Chuck Lever
Quoted 10 lines · Mike Snitzer
Quoted 3 lines
I asked for the use of a
file_syncexport option because we need to test the BUFFERED cache mode as well as DIRECT. So, continue to experiment with this one, but I don't plan to merge it for now.Doesn't the client have the ability to control
NFS_UNSTABLE,NFS_DATA_SYNCandNFS_FILE_SYNCalready? What experiment are you looking to run?If just looking to compare
NFS_FILE_SYNCperformance ofNFSD_IO_BUFFEREDversusNFSD_IO_DIRECTthen using the client control is fine right?
Quoted 6 lines
Quoted 2 lines
Not necessarily. You can mount with "sync" but for large application write requests, that might still generate UNSTABLE + immediate COMMIT.
OK, I'll take a closer look at NFS client controls for
stable_how, because NFSD clearly handlesNFS_DATA_SYNCandNFS_FILE_SYNCso I just assumed its because the client does actually send them.
Clients do send them sometimes. The question here is what happens if NFSD promotes all of them unconditionally. I'm not sure a client can be made to send all FILE_SYNC (even the big writes) without code changes.
Quoted 10 lines
Quoted 4 lines
And as I said above, "no plan to merge it for now," meaning it's still on the table for sometime down the road. I have some other ideas I'm cooking up, such as using BDI congestion to control NFS WRITE throttling.
Hmm, I thought the BDI congestion infra got killed (by Jan Kara and others).. which made me sad because when it was first introduced it was amazing at solving some complex deadlocks (but we're talking 20 years ago now). So I haven't kept my finger on the pulse of what is still available to us relative to BDI congestion.
My (naive) audit suggests that, under memory pressure, the generic write path will throttle writes by delaying the return from the function (balance_dirty_pages and friends). What we might be seeing is that this throttling is not aggressive enough to serve NFSD well.
When the base direct write patches are further along, I'll post my RFC patches and copy fsdevel, and we can explore this more.
Signature · 1 line
Chuck Lever
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
In reply to Mike SnitzerQuoted 3 lines · Mike Snitzer
OK, I'll take a closer look at NFS client controls for
stable_how, because NFSD clearly handlesNFS_DATA_SYNCandNFS_FILE_SYNCso I just assumed its because the client does actually send them.
Asking for NFS_DATA_SYNC / NFS_FILE_SYNC for O_ЅYNC/O_SYNC writes or even fdatasync/fsync calls that translate to a single on the write write request would be a valuable client additoon that should speed things up with most if not all servers.
Quoted 10 lines
Quoted 4 lines
And as I said above, "no plan to merge it for now," meaning it's still on the table for sometime down the road. I have some other ideas I'm cooking up, such as using BDI congestion to control NFS WRITE throttling.
Hmm, I thought the BDI congestion infra got killed (by Jan Kara and others).. which made me sad because when it was first introduced it was amazing at solving some complex deadlocks (but we're talking 20 years ago now). So I haven't kept my finger on the pulse of what is still available to us relative to BDI congestion.
Yes, BDI congestion is gone, mostly because it didn't really work. I'm also not sure how it could have solved deadlocks.
I feel a little out of the loops, though - what are the NFS-level write throttling needs to start with?
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 21 lines · Christoph Hellwig
Quoted 3 lines · Mike Snitzer
OK, I'll take a closer look at NFS client controls for
stable_how, because NFSD clearly handlesNFS_DATA_SYNCandNFS_FILE_SYNCso I just assumed its because the client does actually send them.Asking for
NFS_DATA_SYNC/NFS_FILE_SYNCfor O_ЅYNC/O_SYNC writes or even fdatasync/fsync calls that translate to a single on the write write request would be a valuable client additoon that should speed things up with most if not all servers.Quoted 10 lines
Quoted 4 lines
And as I said above, "no plan to merge it for now," meaning it's still on the table for sometime down the road. I have some other ideas I'm cooking up, such as using BDI congestion to control NFS WRITE throttling.
Hmm, I thought the BDI congestion infra got killed (by Jan Kara and others).. which made me sad because when it was first introduced it was amazing at solving some complex deadlocks (but we're talking 20 years ago now). So I haven't kept my finger on the pulse of what is still available to us relative to BDI congestion.
Quoted 6 lines
Yes, BDI congestion is gone, mostly because it didn't really work. I'm also not sure how it could have solved deadlocks.
I feel a little out of the loops, though - what are the NFS-level write throttling needs to start with?
Let's not go down this path right now. I'd like to stay focused on getting the direct WRITE work merged.
Signature · 1 line
Chuck Lever
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
Quoted 9 lines · Chuck Lever
Quoted 6 lines
Yes, BDI congestion is gone, mostly because it didn't really work. I'm also not sure how it could have solved deadlocks.
I feel a little out of the loops, though - what are the NFS-level write throttling needs to start with?
Let's not go down this path right now. I'd like to stay focused on getting the direct WRITE work merged.
I'm just curious what the discussion is about at all.
Re: [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how
In reply to Mike SnitzerQuoted 11 lines · Mike Snitzer
NFSD_IO_DIRECT_WRITE_FILE_SYNCis direct IO with stable_how=NFS_FILE_SYNC.NFSD_IO_DIRECT_WRITE_DATA_SYNCis direct IO with stable_how=NFS_DATA_SYNC.The
stable_howassociated with each is a hint in the form of a "floor" value forstable_how. Meaning if the client providedstable_howis already of higher value it will not be changed.These permutations of
NFSD_IO_DIRECTallow to experiment with also elevatingstable_howand sending it back to the client. Which forNFSD_IO_DIRECT_WRITE_FILE_SYNCwill cause the client to elide its COMMIT.
What is your use case? Do you have performance numbers for them?
PATCH v4 3/3 NFSD: update Documentation/filesystems/nfs/nfsd-io-modes.rst
In reply to Mike SnitzerAlso fixed some typos.
--- .../filesystems/nfs/nfsd-io-modes.rst | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-)
Documentation/filesystems/nfs/nfsd-io-modes.rst +32 -26
@@ -21,17 +21,20 @@ NFSD's default IO mode (which is NFSD_IO_BUFFERED=0). Based on the configured settings, NFSD's IO will either be: - cached using page cache (NFSD_IO_BUFFERED=0) -- cached but removed from the page cache upon completion - (NFSD_IO_DONTCACHE=1). -- not cached (NFSD_IO_DIRECT=2) +- cached but removed from page cache on completion (NFSD_IO_DONTCACHE=1) +- not cached stable_how=NFS_UNSTABLE (NFSD_IO_DIRECT=2) +- not cached stable_how=NFS_DATA_SYNC (NFSD_IO_DIRECT_WRITE_DATA_SYNC=3) +- not cached stable_how=NFS_FILE_SYNC (NFSD_IO_DIRECT_WRITE_FILE_SYNC=4) -To set an NFSD IO mode, write a supported value (0, 1 or 2) to the +To set an NFSD IO mode, write a supported value (0 - 4) to the corresponding IO operation's debugfs interface, e.g.: echo 2 > /sys/kernel/debug/nfsd/io_cache_read + echo 4 > /sys/kernel/debug/nfsd/io_cache_write To check which IO mode NFSD is using for READ or WRITE, simply read the corresponding IO operation's debugfs interface, e.g.: cat /sys/kernel/debug/nfsd/io_cache_read + cat /sys/kernel/debug/nfsd/io_cache_write NFSD DONTCACHE ==============
@@ -46,10 +49,10 @@ DONTCACHE aims to avoid what has proven to be a fairly significant limition of Linux's memory management subsystem if/when large amounts of data is infrequently accessed (e.g. read once _or_ written once but not read until much later). Such use-cases are particularly problematic -because the page cache will eventually become a bottleneck to surfacing +because the page cache will eventually become a bottleneck to servicing new IO requests. -For more context, please see these Linux commit headers: +For more context on DONTCACHE, please see these Linux commit headers: - Overview: 9ad6344568cc3 ("mm/filemap: change filemap_create_folio() to take a struct kiocb") - for READ: 8026e49bff9b1 ("mm/filemap: add read support for
@@ -73,12 +76,18 @@ those with a working set that is significantly larger than available system memory. The pathological worst-case workload that NFSD DIRECT has proven to help most is: NFS client issuing large sequential IO to a file that is 2-3 times larger than the NFS server's available system memory. +The reason for such improvement is NFSD DIRECT eliminates a lot of work +that the memory management subsystem would otherwise be required to +perform (e.g. page allocation, dirty writeback, page reclaim). When +using NFSD DIRECT, kswapd and kcompactd are no longer commanding CPU +time trying to find adequate free pages so that forward IO progress can +be made. The performance win associated with using NFSD DIRECT was previously discussed on linux-nfs, see: https://lore.kernel.org/linux-nfs/[email protected]/ But in summary: -- NFSD DIRECT can signicantly reduce memory requirements +- NFSD DIRECT can significantly reduce memory requirements - NFSD DIRECT can reduce CPU load by avoiding costly page reclaim work - NFSD DIRECT can offer more deterministic IO performance
@@ -91,11 +100,11 @@ to generate a "flamegraph" for work Linux must perform on behalf of your test is a really meaningful way to compare the relative health of the system and how switching NFSD's IO mode changes what is observed. -If NFSD_IO_DIRECT is specified by writing 2 to NFSD's debugfs -interfaces, ideally the IO will be aligned relative to the underlying -block device's logical_block_size. Also the memory buffer used to store -the READ or WRITE payload must be aligned relative to the underlying -block device's dma_alignment. +If NFSD_IO_DIRECT is specified by writing 2 (or 3 and 4 for WRITE) to +NFSD's debugfs interfaces, ideally the IO will be aligned relative to +the underlying block device's logical_block_size. Also the memory buffer +used to store the READ or WRITE payload must be aligned relative to the +underlying block device's dma_alignment. But NFSD DIRECT does handle misaligned IO in terms of O_DIRECT as best it can:
@@ -113,32 +122,29 @@ Misaligned READ: Misaligned WRITE: If NFSD_IO_DIRECT is used, split any misaligned WRITE into a start, - middle and end as needed. The large middle extent is DIO-aligned and - the start and/or end are misaligned. Buffered IO is used for the - misaligned extents and O_DIRECT is used for the middle DIO-aligned - extent. - - If vfs_iocb_iter_write() returns -ENOTBLK, due to its inability to - invalidate the page cache on behalf of the DIO WRITE, then - nfsd_issue_write_dio() will fall back to using buffered IO. + middle and end as needed. The large middle segment is DIO-aligned + and the start and/or end are misaligned. Buffered IO is used for the + misaligned segments and O_DIRECT is used for the middle DIO-aligned + segment. DONTCACHE buffered IO is _not_ used for the misaligned + segments because using normal buffered IO offers significant RMW + performance benefit when handling streaming misaligned WRITEs. Tracing: - The nfsd_analyze_read_dio trace event shows how NFSD expands any + The nfsd_read_direct trace event shows how NFSD expands any misaligned READ to the next DIO-aligned block (on either end of the original READ, as needed). This combination of trace events is useful for READs: echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_read_vector/enable - echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_analyze_read_dio/enable + echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_read_direct/enable echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_read_io_done/enable echo 1 > /sys/kernel/tracing/events/xfs/xfs_file_direct_read/enable - The nfsd_analyze_write_dio trace event shows how NFSD splits a given - misaligned WRITE into a mix of misaligned extent(s) and a DIO-aligned - extent. + The nfsd_write_direct trace event shows how NFSD splits a given + misaligned WRITE into a DIO-aligned middle segment. This combination of trace events is useful for WRITEs: echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_write_opened/enable - echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_analyze_write_dio/enable + echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_write_direct/enable echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_write_io_done/enable echo 1 > /sys/kernel/tracing/events/xfs/xfs_file_direct_write/enable
Signature · 1 line
2.44.0
Re: [PATCH v4 3/3] NFSD: update Documentation/filesystems/nfs/nfsd-io-modes.rst
Quoted 120 lines · Mike Snitzer
Also fixed some typos.
Signed-off-by Mike Snitzer <[email protected]>--- .../filesystems/nfs/nfsd-io-modes.rst | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-)Documentation/filesystems/nfs/nfsd-io-modes.rst +29
-24@@ -21,17 +21,20 @@ NFSD's default IO mode (which is NFSD_IO_BUFFERED=0). Based on the configured settings, NFSD's IO will either be: - cached using page cache (NFSD_IO_BUFFERED=0) -- cached but removed from the page cache upon completion - (NFSD_IO_DONTCACHE=1). -- not cached (NFSD_IO_DIRECT=2) +- cached but removed from page cache on completion (NFSD_IO_DONTCACHE=1) +- not cached stable_how=NFS_UNSTABLE (NFSD_IO_DIRECT=2) +- not cached stable_how=NFS_DATA_SYNC (NFSD_IO_DIRECT_WRITE_DATA_SYNC=3) +- not cached stable_how=NFS_FILE_SYNC (NFSD_IO_DIRECT_WRITE_FILE_SYNC=4) -To set an NFSD IO mode, write a supported value (0, 1 or 2) to the +To set an NFSD IO mode, write a supported value (0 - 4) to the corresponding IO operation's debugfs interface, e.g.: echo 2 > /sys/kernel/debug/nfsd/io_cache_read + echo 4 > /sys/kernel/debug/nfsd/io_cache_write To check which IO mode NFSD is using for READ or WRITE, simply read the corresponding IO operation's debugfs interface, e.g.: cat /sys/kernel/debug/nfsd/io_cache_read + cat /sys/kernel/debug/nfsd/io_cache_write NFSD DONTCACHE ==============@@ -46,10 +49,10 @@ DONTCACHE aims to avoid what has proven to be a fairly significant limition of Linux's memory management subsystem if/when large amounts of data is infrequently accessed (e.g. read once _or_ written once but not read until much later). Such use-cases are particularly problematic -because the page cache will eventually become a bottleneck to surfacing +because the page cache will eventually become a bottleneck to servicing new IO requests. -For more context, please see these Linux commit headers: +For more context on DONTCACHE, please see these Linux commit headers: - Overview: 9ad6344568cc3 ("mm/filemap: change filemap_create_folio() to take a struct kiocb") - for READ: 8026e49bff9b1 ("mm/filemap: add read support for@@ -73,12 +76,18 @@ those with a working set that is significantly larger than available system memory. The pathological worst-case workload that NFSD DIRECT has proven to help most is: NFS client issuing large sequential IO to a file that is 2-3 times larger than the NFS server's available system memory. +The reason for such improvement is NFSD DIRECT eliminates a lot of work +that the memory management subsystem would otherwise be required to +perform (e.g. page allocation, dirty writeback, page reclaim). When +using NFSD DIRECT, kswapd and kcompactd are no longer commanding CPU +time trying to find adequate free pages so that forward IO progress can +be made. The performance win associated with using NFSD DIRECT was previously discussed on linux-nfs, see: https://lore.kernel.org/linux-nfs/[email protected]/ But in summary: -- NFSD DIRECT can signicantly reduce memory requirements +- NFSD DIRECT can significantly reduce memory requirements - NFSD DIRECT can reduce CPU load by avoiding costly page reclaim work - NFSD DIRECT can offer more deterministic IO performance@@ -91,11 +100,11 @@ to generate a "flamegraph" for work Linux must perform on behalf of your test is a really meaningful way to compare the relative health of the system and how switching NFSD's IO mode changes what is observed. -If NFSD_IO_DIRECT is specified by writing 2 to NFSD's debugfs -interfaces, ideally the IO will be aligned relative to the underlying -block device's logical_block_size. Also the memory buffer used to store -the READ or WRITE payload must be aligned relative to the underlying -block device's dma_alignment. +If NFSD_IO_DIRECT is specified by writing 2 (or 3 and 4 for WRITE) to +NFSD's debugfs interfaces, ideally the IO will be aligned relative to +the underlying block device's logical_block_size. Also the memory buffer +used to store the READ or WRITE payload must be aligned relative to the +underlying block device's dma_alignment. But NFSD DIRECT does handle misaligned IO in terms of O_DIRECT as best it can:@@ -113,32 +122,29 @@ Misaligned READ: Misaligned WRITE: If NFSD_IO_DIRECT is used, split any misaligned WRITE into a start, - middle and end as needed. The large middle extent is DIO-aligned and - the start and/or end are misaligned. Buffered IO is used for the - misaligned extents and O_DIRECT is used for the middle DIO-aligned - extent. - - If vfs_iocb_iter_write() returns -ENOTBLK, due to its inability to - invalidate the page cache on behalf of the DIO WRITE, then - nfsd_issue_write_dio() will fall back to using buffered IO. + middle and end as needed. The large middle segment is DIO-aligned + and the start and/or end are misaligned. Buffered IO is used for the + misaligned segments and O_DIRECT is used for the middle DIO-aligned + segment. DONTCACHE buffered IO is _not_ used for the misaligned + segments because using normal buffered IO offers significant RMW + performance benefit when handling streaming misaligned WRITEs. Tracing: - The nfsd_analyze_read_dio trace event shows how NFSD expands any + The nfsd_read_direct trace event shows how NFSD expands any misaligned READ to the next DIO-aligned block (on either end of the original READ, as needed). This combination of trace events is useful for READs: echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_read_vector/enable - echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_analyze_read_dio/enable + echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_read_direct/enable echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_read_io_done/enable echo 1 > /sys/kernel/tracing/events/xfs/xfs_file_direct_read/enable - The nfsd_analyze_write_dio trace event shows how NFSD splits a given - misaligned WRITE into a mix of misaligned extent(s) and a DIO-aligned
Documentation/filesystems/nfs/nfsd-io-modes.rst Misaligned READ: · line 150
Quoted 10 lines
Documentation/filesystems/nfs/nfsd-io-modes.rst +3
-2- extent. + The nfsd_write_direct trace event shows how NFSD splits a given + misaligned WRITE into a DIO-aligned middle segment. This combination of trace events is useful for WRITEs: echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_write_opened/enable - echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_analyze_write_dio/enable + echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_write_direct/enable echo 1 > /sys/kernel/tracing/events/nfsd/nfsd_write_io_done/enable echo 1 > /sys/kernel/tracing/events/xfs/xfs_file_direct_write/enable
I've already squashed the previous version of this patch into my private tree... if you confirm there were no changes, I'll leave this one for now.
Signature · 1 line
Chuck Lever