mm: improve write performance with RWF_DONTCACHE
Subsystems (6)
Jeff Layton
maintainerv2 cover mm: improve write performance with RWF_DONTCACHE
This version adopts Christoph's suggest to have generic_write_sync() kick the flusher thread for the superblock instead of initiating writeback directly. This seems to perform as well or better in most cases than doing the writeback directly.
Here are results on XFS, both local and exported via knfsd:
nfsd: https://markdownpastebin.com/?id=1884b9487c404ff4b7094ed41cc48f05 xfs: https://markdownpastebin.com/?id=3c6b262182184b25b7d58fb211374475
Ritesh had also asked about getting perf lock traces to confirm the source of the contention. I did that (and I can post them if you like), but the results from the unpatched dontcache runs didn't point out any specific lock contention. That leads me to believe that the bottlenecks were from normal queueing work, and not contention for the xa_lock after all.
Kicking the writeback thread seems to be a clear improvement over the status quo in my testing, but I do wonder if having dontcache writes spamming writeback for the whole bdi is the best idea.
I'm benchmarking out a patch that has the flusher do a writeback_single_inode() for the work. I don't expect it to perform measurably better in this testing, but it would better isolate the DONTCACHE writeback behavior to just those inodes touched by DONTCACHE writes.
Assuming that looks OK, I'll probably send a v3. Original cover letter from v1 follows:
-----------------------------------8<------------------------------------
Recently, we've added controls that allow nfsd to use different IO modes for reads and writes. There are currently 3 different settings for each:
- buffered: traditional buffered reads and writes (this is the default)
- dontcache: set the RWF_DONTCACHE flag on the read or write
- direct: use direct I/O
One of my goals for this half of the year was to do some benchmarking of these different modes with different workloads to see if we can come up with some guidance about what should be used and when.
I had Claude cook up a set of benchmarks that used fio's libnfs backend and started testing the different modes. The initial results weren't terribly surprising, but one thing that really stood out was how badly RWF_DONTCACHE performed with write-heavy workloads. This turned out to be the case on a local xfs with io_uring as well as with nfsd.
The nice thing about these new debugfs controls for nfsd is that it makes it easy to experiement with different IO modes for nfsd. After testing several different approaches, I think this patchset represents a fairly clear improvement. The first two patches alleviate the flush contention when RWF_DONTCACHE is used with heavy write activity.
The last two patches add the performance benchmarking scripts. I don't expect us to merge those, but I wanted to include them to make it clear how this was tested. The results of my testing with all 4 modes (buffered, direct, patched and unpatched dontcache) along with Claude's analysis are at the links below:
nfsd results: https://markdownpastebin.com/?id=0eaf694bd54046b584a8572895abcec2
xfs results: https://markdownpastebin.com/?id=96249deb897a401ba32acbce05312dcc
I can also send them inline if people don't want to chase links.
---
Changes in v2:
- kick flusher thread instead of initiatin writeback inline
- add mechanism to run 'perf lock' around the testcases
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeff Layton (3):
mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
testing: add nfsd-io-bench NFS server benchmark suite
testing: add dontcache-bench local filesystem benchmark suite
fs/fs-writeback.c | 14 + include/linux/backing-dev-defs.h | 1 + include/linux/fs.h | 6 +- include/trace/events/writeback.h | 3 +- .../dontcache-bench/fio-jobs/lat-reader.fio | 12 + .../dontcache-bench/fio-jobs/multi-write.fio | 9 + .../dontcache-bench/fio-jobs/noisy-writer.fio | 12 + .../testing/dontcache-bench/fio-jobs/rand-read.fio | 13 + .../dontcache-bench/fio-jobs/rand-write.fio | 13 + .../testing/dontcache-bench/fio-jobs/seq-read.fio | 13 + .../testing/dontcache-bench/fio-jobs/seq-write.fio | 13 + .../dontcache-bench/scripts/parse-results.sh | 238 +++++++++ .../dontcache-bench/scripts/run-benchmarks.sh | 562 ++++++++++++++++++++ .../testing/nfsd-io-bench/fio-jobs/lat-reader.fio | 15 + .../testing/nfsd-io-bench/fio-jobs/multi-write.fio | 14 + .../nfsd-io-bench/fio-jobs/noisy-writer.fio | 14 + tools/testing/nfsd-io-bench/fio-jobs/rand-read.fio | 15 + .../testing/nfsd-io-bench/fio-jobs/rand-write.fio | 15 + tools/testing/nfsd-io-bench/fio-jobs/seq-read.fio | 14 + tools/testing/nfsd-io-bench/fio-jobs/seq-write.fio | 14 + .../testing/nfsd-io-bench/scripts/parse-results.sh | 238 +++++++++ .../nfsd-io-bench/scripts/run-benchmarks.sh | 591 +++++++++++++++++++++ .../testing/nfsd-io-bench/scripts/setup-server.sh | 94 ++++ 23 files changed, 1928 insertions(+), 5 deletions(-)
---
base-commit: 9147566d801602c9e7fc7f85e989735735bf38ba
change-id: 20260401-dontcache-5811efd7eaf3
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v2 1/3 mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
The IOCB_DONTCACHE writeback path in generic_write_sync() calls filemap_flush_range() on every write, submitting writeback inline in the writer's context. Perf lock contention profiling shows the performance problem is not lock contention but the writeback submission work itself — walking the page tree and submitting I/O blocks the writer for milliseconds, inflating p99.9 latency from 23ms (buffered) to 93ms (dontcache).
Replace the inline filemap_flush_range() call with a wakeup_flusher_threads_bdi() call that kicks the BDI's flusher thread to drain dirty pages in the background. This moves writeback submission completely off the writer's hot path. The flusher thread handles writeback asynchronously, naturally coalescing and rate-limiting I/O without any explicit skip-if-busy or dirty pressure checks.
Add WB_REASON_DONTCACHE as a new writeback reason for tracing visibility.
--- fs/fs-writeback.c | 14 ++++++++++++++ include/linux/backing-dev-defs.h | 1 + include/linux/fs.h | 6 ++---- include/trace/events/writeback.h | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-)
fs/fs-writeback.c +14 -0
@@ -2466,6 +2466,20 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi,rcu_read_unlock (); } +/** +* filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes +* @mapping: address_space that was just written to +* +* Wake the BDI flusher thread to start writeback of dirty pages in the +* background. +*/ +void filemap_dontcache_kick_writeback (struct address_space *mapping) +{ +wakeup_flusher_threads_bdi (inode_to_bdi (mapping->host), +WB_REASON_DONTCACHE ); +} +EXPORT_SYMBOL (filemap_dontcache_kick_writeback); +/* * Wakeup the flusher threads to start writeback of all currently dirty pages */
include/linux/backing-dev-defs.h +1 -0
@@ -55,6 +55,7 @@ enum wb_reason {*/ WB_REASON_FORKER_THREAD ,WB_REASON_FOREIGN_FLUSH , +WB_REASON_DONTCACHE , WB_REASON_MAX, };
include/linux/fs.h +2 -4
@@ -2610,6 +2610,7 @@ extern int __must_check file_write_and_wait_range(struct file *file, loff_t start, loff_t end);int filemap_flush_range (struct address_space *mapping,loff_t start,loff_t end); +void filemap_dontcache_kick_writeback (struct address_space *mapping);static inline int file_write_and_wait (struct file *file) {
@@ -2643,10 +2644,7 @@ static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count)if (ret)return ret; }else if (iocb->ki_flags &IOCB_DONTCACHE ) { -struct address_space *mapping = iocb->ki_filp->f_mapping; - -filemap_flush_range (mapping, iocb->ki_pos - count, - iocb->ki_pos -1 ); +filemap_dontcache_kick_writeback (iocb->ki_filp->f_mapping); }return count;
include/trace/events/writeback.h +2 -1
@@ -44,7 +44,8 @@ EM( WB_REASON_PERIODIC, "periodic") \ EM( WB_REASON_FS_FREE_SPACE, "fs_free_space") \ EM( WB_REASON_FORKER_THREAD, "forker_thread") \ - EMe(WB_REASON_FOREIGN_FLUSH, "foreign_flush") + EM( WB_REASON_FOREIGN_FLUSH, "foreign_flush") \ + EMe(WB_REASON_DONTCACHE, "dontcache")WB_WORK_REASON
Signature · 1 line
2.53.0
Re: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 8 lines · Jeff Layton
The
IOCB_DONTCACHEwriteback path ingeneric_write_sync()callsfilemap_flush_range()on every write, submitting writeback inline in the writer's context. Perf lock contention profiling shows the performance problem is not lock contention but the writeback submission work itself — walking the page tree and submitting I/O blocks the writer for milliseconds, inflating p99.9 latency from 23ms (buffered) to 93ms (dontcache).
Quoted 7 lines
Replace the inline
filemap_flush_range()call with awakeup_flusher_threads_bdi()call that kicks the BDI's flusher thread to drain dirty pages in the background. This moves writeback submission completely off the writer's hot path. The flusher thread handles writeback asynchronously, naturally coalescing and rate-limiting I/O without any explicit skip-if-busy or dirty pressure checks.
Thanks Jeff for explaining this. It make sense now.
Quoted 17 lines
Add
WB_REASON_DONTCACHEas a new writeback reason for tracing visibility.Signed-off-by Jeff Layton <[email protected]>--- fs/fs-writeback.c | 14 ++++++++++++++ include/linux/backing-dev-defs.h | 1 + include/linux/fs.h | 6 ++---- include/trace/events/writeback.h | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-)fs/fs-writeback.c +0
-0@@ -2466,6 +2466,20 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi,rcu_read_unlock ();
fs/fs-writeback.c void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, · line 2476
Quoted 10 lines
fs/fs-writeback.c +8
-0} +/** +* filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes +* @mapping: address_space that was just written to +* +* Wake the BDI flusher thread to start writeback of dirty pages in the +* background. +*/ +void filemap_dontcache_kick_writeback (struct address_space *mapping)
This api gives a wrong sense that we are kicking writeback to write dirty pages which belongs to only this inode's address space mapping. But instead we are starting wb for everything on the respective bdi.
So instead why not just export symbol for wakeup_flusher_threads_bdi() and use it instead?
If not, then IMO at least making it...
filemap_kick_writeback_all(mapping, enum wb_reason)
... might be better.
Quoted 62 lines
fs/fs-writeback.c +6
-0+{ +wakeup_flusher_threads_bdi (inode_to_bdi (mapping->host), +WB_REASON_DONTCACHE ); +} +EXPORT_SYMBOL (filemap_dontcache_kick_writeback); +/* * Wakeup the flusher threads to start writeback of all currently dirty pages */ include/linux/backing-dev-defs.h +1
-0@@ -55,6 +55,7 @@ enum wb_reason {*/ WB_REASON_FORKER_THREAD ,WB_REASON_FOREIGN_FLUSH , +WB_REASON_DONTCACHE , WB_REASON_MAX, };include/linux/fs.h +2
-4@@ -2610,6 +2610,7 @@ extern int __must_check file_write_and_wait_range(struct file *file, loff_t start, loff_t end);int filemap_flush_range (struct address_space *mapping,loff_t start,loff_t end); +void filemap_dontcache_kick_writeback (struct address_space *mapping);static inline int file_write_and_wait (struct file *file) {@@ -2643,10 +2644,7 @@ static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count)if (ret)return ret; }else if (iocb->ki_flags &IOCB_DONTCACHE ) { -struct address_space *mapping = iocb->ki_filp->f_mapping; - -filemap_flush_range (mapping, iocb->ki_pos - count, - iocb->ki_pos -1 ); +filemap_dontcache_kick_writeback (iocb->ki_filp->f_mapping); }return count;include/trace/events/writeback.h +2
-1@@ -44,7 +44,8 @@ EM( WB_REASON_PERIODIC, "periodic") \ EM( WB_REASON_FS_FREE_SPACE, "fs_free_space") \ EM( WB_REASON_FORKER_THREAD, "forker_thread") \ - EMe(WB_REASON_FOREIGN_FLUSH, "foreign_flush") + EM( WB_REASON_FOREIGN_FLUSH, "foreign_flush") \ + EMe(WB_REASON_DONTCACHE, "dontcache")WB_WORK_REASON Signature · 2 lines
-- 2.53.0
Re: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 8 lines · Ritesh Harjani
Quoted 1 line
+void
filemap_dontcache_kick_writeback(struct address_space *mapping)This api gives a wrong sense that we are kicking writeback to write dirty pages which belongs to only this inode's address space mapping. But instead we are starting wb for everything on the respective bdi.
So instead why not just export symbol for
wakeup_flusher_threads_bdi()and use it instead?
I'd rather not expose that to wide with the extra reason arguments that's not otherwise exposed outside the core writeback code.
Btw, wakeup_flusher_threads_bdi should really be marked static in fs-writeback.c as well.
Jeff Layton
maintainerRe: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
In reply to Ritesh Harjani (IBM)Quoted 53 lines · Ritesh Harjani
Quoted 8 lines · Jeff Layton
The
IOCB_DONTCACHEwriteback path ingeneric_write_sync()callsfilemap_flush_range()on every write, submitting writeback inline in the writer's context. Perf lock contention profiling shows the performance problem is not lock contention but the writeback submission work itself — walking the page tree and submitting I/O blocks the writer for milliseconds, inflating p99.9 latency from 23ms (buffered) to 93ms (dontcache).Quoted 7 lines
Replace the inline
filemap_flush_range()call with awakeup_flusher_threads_bdi()call that kicks the BDI's flusher thread to drain dirty pages in the background. This moves writeback submission completely off the writer's hot path. The flusher thread handles writeback asynchronously, naturally coalescing and rate-limiting I/O without any explicit skip-if-busy or dirty pressure checks.Thanks Jeff for explaining this. It make sense now.
Quoted 17 lines
Add
WB_REASON_DONTCACHEas a new writeback reason for tracing visibility.Signed-off-by Jeff Layton <[email protected]>--- fs/fs-writeback.c | 14 ++++++++++++++ include/linux/backing-dev-defs.h | 1 + include/linux/fs.h | 6 ++---- include/trace/events/writeback.h | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-)fs/fs-writeback.c +0
-0@@ -2466,6 +2466,20 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi,rcu_read_unlock ();fs/fs-writeback.c void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, · line 2476
Quoted 10 lines
fs/fs-writeback.c +8
-0} +/** +* filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes +* @mapping: address_space that was just written to +* +* Wake the BDI flusher thread to start writeback of dirty pages in the +* background. +*/ +void filemap_dontcache_kick_writeback (struct address_space *mapping)This api gives a wrong sense that we are kicking writeback to write dirty pages which belongs to only this inode's address space mapping. But instead we are starting wb for everything on the respective bdi.
Quoted 7 lines
So instead why not just export symbol for
wakeup_flusher_threads_bdi()and use it instead?If not, then IMO at least making it...
filemap_kick_writeback_all(mapping, enum wb_reason)... might be better.
I did draft up a version of this -- adding a way to tell the flusher thread to only flush a single inode. The performance is better than today's DONTCACHE, but was worse than just kicking the flusher thread.
I think we're probably better off not doing this because we lose some batching opportunities by trying to force out a single inode's pages rather than allowing the thread to do its thing.
The raw results and Claude's analysis follows. The analysis seems a bit speculative, but the numbers were pretty clear:
==================================================================
Deliverable 1: Single-Client fio Benchmarks
==================================================================
--- seq-write ---
Mode MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) Sys CPU% PeakDirty(kB) PeakCache(kB)
------------------------------------------------------------------------------------------------------------------------
buffered 695.5 695.528450 22949.1 20054.016 55312.384 61079.552 1.9 44987764 253243376
dontcache 1437.9 1437.886186 11072.1 11993.088 21889.024 23461.888 2.0 42870772 52593220 direct 1383.4 1383.368808 11511.1 10944.512 22151.168 23986.176 2.0 44749956 252773512
--- rand-write ---
Mode MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) Sys CPU% PeakDirty(kB) PeakCache(kB)
------------------------------------------------------------------------------------------------------------------------
buffered 314 80374.217300 196.5 193.536 522.24 757.76 2.0 44149552 252083008 dontcache 285.8 73158.694019 216.2 112.128 489.472 16711.68 1.8 45074268 54406332 direct 220.9 56539.452768 280.5 98.816 749.568 17170.432 1.6 44545592 251172912
--- seq-read ---
Mode MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) Sys CPU% PeakDirty(kB) PeakCache(kB)
------------------------------------------------------------------------------------------------------------------------
buffered 2330.9 2330.876027 6508.6 6455.296 9633.792 11075.584 1.5 12112 253248964 dontcache 2350.4 2350.352499 6382.3 6324.224 7503.872 8093.696 1.4 5420 5717984 direct 2392.4 2392.364823 6364.5 6324.224 9240.576 10420.224 1.4 17784 252508448
--- rand-read ---
Mode MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) Sys CPU% PeakDirty(kB) PeakCache(kB)
------------------------------------------------------------------------------------------------------------------------
buffered 590.8 151245.227927 99.7 94.72 179.2 228.352 1.4 207388 253316616 dontcache 518.8 132801.398005 113.3 105.984 218.112 856.064 1.4 15504 8251388 direct 574.2 146991.048352 102.6 97.792 181.248 232.448 1.3 1520268 253300752
==================================================================
Deliverable 2: Noisy-Neighbor Benchmarks
==================================================================
--- Scenario A: Multiple Writers ---
Mode: buffered
Client MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) client1 405.9 405.890628 2332.4 0.564 40632.32 57933.824 client2 397.2 397.237862 2371.2 0.572 40632.32 58458.112 client3 398.1 398.125174 2365.1 0.548 40632.32 58982.4 client4 398.7 398.714803 2360.9 0.628 40632.32 58458.112
Aggregate BW: 1599.9 MB/s | Sys CPU: 1.1% | Peak Dirty: 48237132 kB
Mode: dontcache
Client MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) client1 249.7 249.679863 3861 0.556 51642.368 77070.336 client2 250.8 250.827411 3844.4 0.532 51642.368 77070.336 client3 249.5 249.498815 3871.6 0.596 52166.656 77070.336 client4 249.3 249.264908 3875.4 0.612 52166.656 77070.336
Aggregate BW: 999.3 MB/s | Sys CPU: 1.1% | Peak Dirty: 44716500 kB
Mode: direct
Client MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us) client1 237.8 237.802737 4072.9 0.564 42729.472 50069.504 client2 239.3 239.331213 4046.4 0.588 42729.472 50069.504 client3 238.1 238.123964 4069.2 0.58 42729.472 50069.504 client4 239.8 239.752136 4038.6 0.596 42729.472 50069.504
Aggregate BW: 955.0 MB/s | Sys CPU: 1.1% | Peak Dirty: 44481312 kB
--- Scenario C: Noisy Writer + Latency-Sensitive Readers ---
Mode: buffered
Job MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us)
Bulk writer 891.7 891.707189 964.6 0.668 18743.296 25559.04 reader1 643.2 164663.316583 4.7 0.131 164.864 684.032 reader2 638.4 163431.421446 4.4 0.131 162.816 634.88 reader3 633.7 162217.821782 4.4 0.131 173.056 626.688
Sys CPU: 1.1% | Peak Dirty: 44129604 kB
Mode: dontcache
Job MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us)
Bulk writer 1385.9 1385.920180 566.7 0.564 14876.672 23461.888 reader1 18.7 4781.729962 204.3 0.183 1548.288 88604.672 reader2 18.7 4784.697379 204.1 0.185 1581.056 88604.672 reader3 18.7 4780.857893 204.3 0.183 1564.672 88604.672
Sys CPU: 1.1% | Peak Dirty: 44262448 kB
Mode: direct
Job MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us)
Bulk writer 1313.6 1313.630216 604.1 0.652 15007.744 24248.32
reader1 984.6 252061.538462 2.5 0.131 136.192 259.072 reader2 992.2 254015.503876 2.4 0.131 130.56 280.576 reader3 988.4 253034.749035 2.4 0.131 128.512 284.672
Sys CPU: 1.0% | Peak Dirty: 44416804 kB
--- Scenario D: Mixed-Mode Noisy Writer + Readers ---
Mode: dontcache-w_buffered-r
Job MB/s IOPS Avg(us) p50(us) p99(us) p99.9(us)
Bulk writer 1466.7 1466.717576 529.7 0.564 13959.168 23724.032
reader1 504.4 129134.975369 6.3 0.131 129.536 358.4 reader2 504.4 129134.975369 6.1 0.131 123.392 358.4 reader3 513.5 131466.399198 6.2 0.131 140.288 358.4
Sys CPU: 0.9% | Peak Dirty: 43284376 kB
==================================================================
System Info
==================================================================
Timestamp: 20260408-071440
Kernel: 7.0.0-rc6-00025-gad8572d1ac65
Filesystem: xfs
File size: 514746M
Test dir: /export
Host: 256GB RAM + 80 CPUs
==================================================================
CLAUDE's Comparison and Analysis
==================================================================
● Comparing dontcache numbers against the previous whole-BDI flusher kernel (from /tmp/dontcache-local-4way-flusher.md):
Per-Inode vs Whole-BDI Flusher — DONTCACHE on Local XFS
Single-Client Writes
┌──────────────────┬───────────┬───────────┬─────────────┐ │ Benchmark │ Whole-BDI │ Per-Inode │ Change │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Seq write MB/s │ 1450 │ 1438 │ -1% (noise) │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Seq write p99.9 │ 23.5 ms │ 23.5 ms │ identical │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Rand write MB/s │ 363 │ 286 │ -21% │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Rand write p99.9 │ 1.8 ms │ 16.7 ms │ regression │ └──────────────────┴───────────┴───────────┴─────────────┘
Seq write is identical. Rand write regressed — the whole-BDI flusher batched all dirty pages in one pass with writeback_sb_inodes() under a single blk_plug, while per-inode write_inode_now() loses that batching.
Single-Client Reads
┌────────────────┬───────────┬───────────┬────────┐ │ Benchmark │ Whole-BDI │ Per-Inode │ Change │ ├────────────────┼───────────┼───────────┼────────┤ │ Seq read MB/s │ 2950 │ 2350 │ -20% │ ├────────────────┼───────────┼───────────┼────────┤ │ Rand read MB/s │ 651 │ 519 │ -20% │ └────────────────┴───────────┴───────────┴────────┘
Reads shouldn't be affected by writeback path changes. Buffered reads also dropped (2888 → 2331), suggesting different system conditions between runs rather than a per-inode regression.
Multi-Writer (Scenario A)
┌────────────────┬───────────┬───────────┬────────────┐ │ Metric │ Whole-BDI │ Per-Inode │ Change │ ├────────────────┼───────────┼───────────┼────────────┤ │ Aggregate MB/s │ 1478 │ 999 │ -32% │ ├────────────────┼───────────┼───────────┼────────────┤ │ p99.9 │ 46 ms │ 77 ms │ -67% worse │ └────────────────┴───────────┴───────────┴────────────┘
This is the biggest regression. With whole-BDI, the flusher did one batched pass through all dirty inodes via writeback_sb_inodes(). With per-inode, each of 4 writers queues a separate work item processed serially by write_inode_now() — losing the batch I/O merging benefit.
Scenario C & D (Noisy Neighbor)
┌─────────────────────────┬───────────┬───────────┬─────────────┐ │ Metric │ Whole-BDI │ Per-Inode │ Change │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario C writer │ 1468 │ 1386 │ -6% │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario C readers │ 18.7 MB/s │ 18.7 MB/s │ identical │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario D writer │ 1472 │ 1467 │ identical │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario D readers │ 496 MB/s │ 507 MB/s │ +2% │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario D reader p99.9 │ 440 us │ 358 us │ +19% better │ └─────────────────────────┴───────────┴───────────┴─────────────┘
Mixed-mode (Scenario D) is the intended production case and it's essentially identical or slightly better — per-inode writeback creates less device contention for buffered readers.
Summary
The per-inode approach is neutral-to-slightly-better for the production scenario (Scenario D), but regresses on multi-writer and random write workloads. The core issue is loss of I/O batching — writeback_sb_inodes() processes all dirty inodes in one blk_plug'd pass, while per-inode write_inode_now() calls are processed one at a time. The read regressions likely reflect different system conditions since buffered/direct reads also dropped ~20%.
Re: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 62 lines · Jeff Layton
Quoted 53 lines · Ritesh Harjani
Quoted 8 lines · Jeff Layton
The
IOCB_DONTCACHEwriteback path ingeneric_write_sync()callsfilemap_flush_range()on every write, submitting writeback inline in the writer's context. Perf lock contention profiling shows the performance problem is not lock contention but the writeback submission work itself — walking the page tree and submitting I/O blocks the writer for milliseconds, inflating p99.9 latency from 23ms (buffered) to 93ms (dontcache).Quoted 7 lines
Replace the inline
filemap_flush_range()call with awakeup_flusher_threads_bdi()call that kicks the BDI's flusher thread to drain dirty pages in the background. This moves writeback submission completely off the writer's hot path. The flusher thread handles writeback asynchronously, naturally coalescing and rate-limiting I/O without any explicit skip-if-busy or dirty pressure checks.Thanks Jeff for explaining this. It make sense now.
Quoted 17 lines
Add
WB_REASON_DONTCACHEas a new writeback reason for tracing visibility.Signed-off-by Jeff Layton <[email protected]>--- fs/fs-writeback.c | 14 ++++++++++++++ include/linux/backing-dev-defs.h | 1 + include/linux/fs.h | 6 ++---- include/trace/events/writeback.h | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-)fs/fs-writeback.c +0
-0@@ -2466,6 +2466,20 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi,rcu_read_unlock ();fs/fs-writeback.c void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, · line 2476
Quoted 10 lines
fs/fs-writeback.c +8
-0} +/** +* filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes +* @mapping: address_space that was just written to +* +* Wake the BDI flusher thread to start writeback of dirty pages in the +* background. +*/ +void filemap_dontcache_kick_writeback (struct address_space *mapping)This api gives a wrong sense that we are kicking writeback to write dirty pages which belongs to only this inode's address space mapping. But instead we are starting wb for everything on the respective bdi.
Quoted 7 lines
So instead why not just export symbol for
wakeup_flusher_threads_bdi()and use it instead?If not, then IMO at least making it...
filemap_kick_writeback_all(mapping, enum wb_reason)... might be better.
Quoted 8 lines
I did draft up a version of this -- adding a way to tell the flusher thread to only flush a single inode. The performance is better than today's DONTCACHE, but was worse than just kicking the flusher thread.
I think we're probably better off not doing this because we lose some batching opportunities by trying to force out a single inode's pages rather than allowing the thread to do its thing.
So, if I understood it correctly, Christoph might be talking about a different approach here.
Instead of kicking flusher thread to writeback pages for a single inode, if we can track the number of dontcache pages (get_nr_dontcache_pages()), then we can kick the flusher for those many target pages. I think this way we are still reducing the dirty page cache pressure - the problem which RWF_DONTCACHE is supposed to solve. But I guess, that doesn't necessarily always mean that only dontcache marked folios will get written.
If we implement that then, this should still help with the batching problem you mentioned and hopefully should not cause a major regression for the workload which Jan mentioned.
Feel free to correct my understanding here please.
-ritesh
Re: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
In reply to Jeff LaytonQuoted 6 lines · Jeff Layton
Replace the inline
filemap_flush_range()call with awakeup_flusher_threads_bdi()call that kicks the BDI's flusher thread to drain dirty pages in the background. This moves writeback submission completely off the writer's hot path. The flusher thread handles writeback asynchronously, naturally coalescing and rate-limiting I/O without any explicit skip-if-busy or dirty pressure checks.
Having numbers showing the benefit here would be very useful.
fs/fs-writeback.c void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, · line 2480
Quoted 12 lines
fs/fs-writeback.c +12
-0+/** +* filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes +* @mapping: address_space that was just written to +* +* Wake the BDI flusher thread to start writeback of dirty pages in the +* background. +*/ +void filemap_dontcache_kick_writeback (struct address_space *mapping) +{ +wakeup_flusher_threads_bdi (inode_to_bdi (mapping->host), +WB_REASON_DONTCACHE ); +}
wakeup_flusher_threads_bdi ends up calling wb_start_writeback eventually, which sets WB_start_all, pushes the reason to start_all_reason and then does the actual wakeup.
The flusher thread then through wb_check_start_all does a WB_SYNC_NONE writeback based on get_nr_dirty_pages. Which seems wrong - we don't want to do a huge writeback evertime the some DONTCACHE write finished.
So I think you'll want a new WB_start_dontcache bit, a new get_nr_dontcache_pages() helper on a new node counter, etc.
Quoted 1 line
+EXPORT_SYMBOL(filemap_dontcache_kick_writeback);
EXPORT_SYMBOL_GPL, please.
Jan Kara
maintainerRe: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 18 lines · Christoph Hellwig
fs/fs-writeback.c void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, · line 2480
Quoted 12 lines · Jeff Layton
fs/fs-writeback.c +12
-0+/** +* filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes +* @mapping: address_space that was just written to +* +* Wake the BDI flusher thread to start writeback of dirty pages in the +* background. +*/ +void filemap_dontcache_kick_writeback (struct address_space *mapping) +{ +wakeup_flusher_threads_bdi (inode_to_bdi (mapping->host), +WB_REASON_DONTCACHE ); +}
wakeup_flusher_threads_bdiends up callingwb_start_writebackeventually, which setsWB_start_all, pushes the reason tostart_all_reasonand then does the actual wakeup.
Quoted 3 lines
The flusher thread then through
wb_check_start_alldoes aWB_SYNC_NONEwriteback based onget_nr_dirty_pages. Which seems wrong - we don't want to do a huge writeback evertime the some DONTCACHE write finished.
This is all true and I can certainly construct a workload where this behavior will lead to big regressions in performance - for example one process creating say 1G temporary file and deleting it shortly after creation + one process doing small DONTCACHE writes. Before this change only DONTCACHE writes will make it to the disk and temporary file will only be in the page cache, after this change you pay for allocating, writing back, and deleting the temporary file.
Quoted 2 lines
So I think you'll want a new
WB_start_dontcachebit, a newget_nr_dontcache_pages()helper on a new node counter, etc.
But I'm not sure how you imagine this would work without restricting writeback to particular inodes. Maybe we could mark inodes which have folios with dropbehind set and make flush worker only write such inodes? That would probably require tracking number of folios with dropbehind flag per inode but that wouldn't be too bad. Or we could just lazily clear this "inode has dropbehind folios" flag once the inode is clean.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 6 lines · Jan Kara
Quoted 2 lines
So I think you'll want a new
WB_start_dontcachebit, a newget_nr_dontcache_pages()helper on a new node counter, etc.But I'm not sure how you imagine this would work without restricting writeback to particular inodes. Maybe we could mark inodes which have folios with dropbehind set and make flush worker only write such inodes?
I'd only expedite writing by the number of pending dontcache folios. It would still write the least recently dirtied inodes.
Jan Kara
maintainerRe: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Jan Kara
Quoted 2 lines
So I think you'll want a new
WB_start_dontcachebit, a newget_nr_dontcache_pages()helper on a new node counter, etc.But I'm not sure how you imagine this would work without restricting writeback to particular inodes. Maybe we could mark inodes which have folios with dropbehind set and make flush worker only write such inodes?
I'd only expedite writing by the number of pending dontcache folios. It would still write the least recently dirtied inodes.
So that may result in dontcache folios staying cached for quite some time if DONTCACHE and normal writes are mixed. But I agree over longer time it might just level out so maybe that's fine.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerRe: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE
Quoted 9 lines · Jan Kara
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Jan Kara
Quoted 2 lines
So I think you'll want a new
WB_start_dontcachebit, a newget_nr_dontcache_pages()helper on a new node counter, etc.But I'm not sure how you imagine this would work without restricting writeback to particular inodes. Maybe we could mark inodes which have folios with dropbehind set and make flush worker only write such inodes?
Quoted 7 lines
Quoted 2 lines
I'd only expedite writing by the number of pending dontcache folios. It would still write the least recently dirtied inodes.
So that may result in dontcache folios staying cached for quite some time if DONTCACHE and normal writes are mixed. But I agree over longer time it might just level out so maybe that's fine.
I think that's probably OK. In my interpretation, DONTCACHE on write just means "don't cache this data beyond what's needed for writeback". It doesn't provide any guarantees about when the writeback will be done.
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v2 2/3 testing: add nfsd-io-bench NFS server benchmark suite
In reply to Jeff LaytonAdd a benchmark suite for testing NFSD I/O mode performance using fio with the libnfs backend against an NFS server on localhost. Tests buffered, dontcache, and direct I/O modes via NFSD debugfs controls.
Includes:
- fio job files for sequential/random read/write, multi-writer, noisy-neighbor, and latency-sensitive reader workloads
- run-benchmarks.sh: orchestrates test matrix with mode switching
- parse-results.sh: extracts metrics from fio JSON output
- setup-server.sh: configures NFS export for testing
--- .../testing/nfsd-io-bench/fio-jobs/lat-reader.fio | 15 + .../testing/nfsd-io-bench/fio-jobs/multi-write.fio | 14 + .../nfsd-io-bench/fio-jobs/noisy-writer.fio | 14 + tools/testing/nfsd-io-bench/fio-jobs/rand-read.fio | 15 + .../testing/nfsd-io-bench/fio-jobs/rand-write.fio | 15 + tools/testing/nfsd-io-bench/fio-jobs/seq-read.fio | 14 + tools/testing/nfsd-io-bench/fio-jobs/seq-write.fio | 14 + .../testing/nfsd-io-bench/scripts/parse-results.sh | 238 +++++++++ .../nfsd-io-bench/scripts/run-benchmarks.sh | 591 +++++++++++++++++++++ .../testing/nfsd-io-bench/scripts/setup-server.sh | 94 ++++ 10 files changed, 1024 insertions(+)
tools/testing/nfsd-io-bench/fio-jobs/lat-reader.fio new file +15 -0
@@ -0,0 +1,15 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=4k +numjobs=16 +runtime=300 +time_based=1 +group_reporting=1 +rw=randread +log_avg_msec=1000 +write_bw_log=latreader +write_lat_log=latreader + +[lat_reader]
tools/testing/nfsd-io-bench/fio-jobs/multi-write.fio new file +14 -0
@@ -0,0 +1,14 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=1M +numjobs=16 +time_based=0 +group_reporting=1 +rw=write +log_avg_msec=1000 +write_bw_log=multiwrite +write_lat_log=multiwrite + +[writer]
tools/testing/nfsd-io-bench/fio-jobs/noisy-writer.fio new file +14 -0
@@ -0,0 +1,14 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=1M +numjobs=16 +time_based=0 +group_reporting=1 +rw=write +log_avg_msec=1000 +write_bw_log=noisywriter +write_lat_log=noisywriter + +[bulk_writer]
tools/testing/nfsd-io-bench/fio-jobs/rand-read.fio new file +15 -0
@@ -0,0 +1,15 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=4k +numjobs=16 +runtime=300 +time_based=1 +group_reporting=1 +rw=randread +log_avg_msec=1000 +write_bw_log=randread +write_lat_log=randread + +[randread]
tools/testing/nfsd-io-bench/fio-jobs/rand-write.fio new file +15 -0
@@ -0,0 +1,15 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=64k +numjobs=16 +runtime=300 +time_based=1 +group_reporting=1 +rw=randwrite +log_avg_msec=1000 +write_bw_log=randwrite +write_lat_log=randwrite + +[randwrite]
tools/testing/nfsd-io-bench/fio-jobs/seq-read.fio new file +14 -0
@@ -0,0 +1,14 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=1M +numjobs=16 +time_based=0 +group_reporting=1 +rw=read +log_avg_msec=1000 +write_bw_log=seqread +write_lat_log=seqread + +[seqread]
tools/testing/nfsd-io-bench/fio-jobs/seq-write.fio new file +14 -0
@@ -0,0 +1,14 @@ +[global] +ioengine=nfs +nfs_url=nfs://localhost/export +direct=0 +bs=1M +numjobs=16 +time_based=0 +group_reporting=1 +rw=write +log_avg_msec=1000 +write_bw_log=seqwrite +write_lat_log=seqwrite + +[seqwrite]
tools/testing/nfsd-io-bench/scripts/parse-results.sh new file +238 -0
238 lines not on this page · raw message
tools/testing/nfsd-io-bench/scripts/run-benchmarks.sh new file +591 -0
591 lines not on this page · raw message
tools/testing/nfsd-io-bench/scripts/setup-server.sh new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 3/3 testing: add dontcache-bench local filesystem benchmark suite
In reply to Jeff LaytonAdd a benchmark suite for testing IOCB_DONTCACHE on local filesystems via fio's io_uring engine with the RWF_DONTCACHE flag.
The suite mirrors the nfsd-io-bench test matrix but uses io_uring with the "uncached" fio option instead of NFSD debugfs mode switching:
- uncached=0: standard buffered I/O
- uncached=1: RWF_DONTCACHE
- Mode 2 uses O_DIRECT via fio's --direct=1
Includes fio job files, run-benchmarks.sh, and parse-results.sh.
--- .../dontcache-bench/fio-jobs/lat-reader.fio | 12 + .../dontcache-bench/fio-jobs/multi-write.fio | 9 + .../dontcache-bench/fio-jobs/noisy-writer.fio | 12 + .../testing/dontcache-bench/fio-jobs/rand-read.fio | 13 + .../dontcache-bench/fio-jobs/rand-write.fio | 13 + .../testing/dontcache-bench/fio-jobs/seq-read.fio | 13 + .../testing/dontcache-bench/fio-jobs/seq-write.fio | 13 + .../dontcache-bench/scripts/parse-results.sh | 238 +++++++++ .../dontcache-bench/scripts/run-benchmarks.sh | 562 +++++++++++++++++++++ 9 files changed, 885 insertions(+)
tools/testing/dontcache-bench/fio-jobs/lat-reader.fio new file +12 -0
@@ -0,0 +1,12 @@ +[global] +ioengine=io_uring +direct=0 +bs=4k +numjobs=1 +time_based=0 +rw=read +log_avg_msec=1000 +write_bw_log=latreader +write_lat_log=latreader + +[latreader]
tools/testing/dontcache-bench/fio-jobs/multi-write.fio new file +9 -0
@@ -0,0 +1,9 @@ +[global] +ioengine=io_uring +direct=0 +bs=1M +numjobs=1 +time_based=0 +rw=write + +[multiwrite]
tools/testing/dontcache-bench/fio-jobs/noisy-writer.fio new file +12 -0
@@ -0,0 +1,12 @@ +[global] +ioengine=io_uring +direct=0 +bs=1M +numjobs=1 +time_based=0 +rw=write +log_avg_msec=1000 +write_bw_log=noisywriter +write_lat_log=noisywriter + +[noisywriter]
tools/testing/dontcache-bench/fio-jobs/rand-read.fio new file +13 -0
@@ -0,0 +1,13 @@ +[global] +ioengine=io_uring +direct=0 +bs=4k +numjobs=1 +iodepth=16 +time_based=0 +rw=randread +log_avg_msec=1000 +write_bw_log=randread +write_lat_log=randread + +[randread]
tools/testing/dontcache-bench/fio-jobs/rand-write.fio new file +13 -0
@@ -0,0 +1,13 @@ +[global] +ioengine=io_uring +direct=0 +bs=4k +numjobs=1 +iodepth=16 +time_based=0 +rw=randwrite +log_avg_msec=1000 +write_bw_log=randwrite +write_lat_log=randwrite + +[randwrite]
tools/testing/dontcache-bench/fio-jobs/seq-read.fio new file +13 -0
@@ -0,0 +1,13 @@ +[global] +ioengine=io_uring +direct=0 +bs=1M +numjobs=1 +iodepth=16 +time_based=0 +rw=read +log_avg_msec=1000 +write_bw_log=seqread +write_lat_log=seqread + +[seqread]
tools/testing/dontcache-bench/fio-jobs/seq-write.fio new file +13 -0
@@ -0,0 +1,13 @@ +[global] +ioengine=io_uring +direct=0 +bs=1M +numjobs=1 +iodepth=16 +time_based=0 +rw=write +log_avg_msec=1000 +write_bw_log=seqwrite +write_lat_log=seqwrite + +[seqwrite]
tools/testing/dontcache-bench/scripts/parse-results.sh new file +238 -0
238 lines not on this page · raw message
tools/testing/dontcache-bench/scripts/run-benchmarks.sh new file +562 -0
562 lines not on this page · raw message
Signature · 1 line
2.53.0
Jeff Layton
maintainerQuoted 21 lines · Jeff Layton
This version adopts Christoph's suggest to have
generic_write_sync()kick the flusher thread for the superblock instead of initiating writeback directly. This seems to perform as well or better in most cases than doing the writeback directly.Here are results on XFS, both local and exported via knfsd:
nfsd: https://markdownpastebin.com/?id=1884b9487c404ff4b7094ed41cc48f05 xfs: https://markdownpastebin.com/?id=3c6b262182184b25b7d58fb211374475Ritesh had also asked about getting perf lock traces to confirm the source of the contention. I did that (and I can post them if you like), but the results from the unpatched dontcache runs didn't point out any specific lock contention. That leads me to believe that the bottlenecks were from normal queueing work, and not contention for the
xa_lockafter all.Kicking the writeback thread seems to be a clear improvement over the status quo in my testing, but I do wonder if having dontcache writes spamming writeback for the whole bdi is the best idea.
Quoted 9 lines
I'm benchmarking out a patch that has the flusher do a
writeback_single_inode()for the work. I don't expect it to perform measurably better in this testing, but it would better isolate the DONTCACHE writeback behavior to just those inodes touched by DONTCACHE writes.Assuming that looks OK, I'll probably send a v3. Original cover letter from v1 follows:
Actually, that version regressed performance in a couple of cases. I think v2 is probably the best approach, on balance. Maybe we can get this into -next so that it can make v7.2?
Here's the comparison between this version and a writeback_single_inode() flush version:
------------------8<-----------------------
● Comparing dontcache numbers against the previous whole-BDI flusher kernel (from /tmp/dontcache-local-4way-flusher.md):
Per-Inode vs Whole-BDI Flusher — DONTCACHE on Local XFS
Single-Client Writes
┌──────────────────┬───────────┬───────────┬─────────────┐ │ Benchmark │ Whole-BDI │ Per-Inode │ Change │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Seq write MB/s │ 1450 │ 1438 │ -1% (noise) │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Seq write p99.9 │ 23.5 ms │ 23.5 ms │ identical │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Rand write MB/s │ 363 │ 286 │ -21% │ ├──────────────────┼───────────┼───────────┼─────────────┤ │ Rand write p99.9 │ 1.8 ms │ 16.7 ms │ regression │ └──────────────────┴───────────┴───────────┴─────────────┘
Seq write is identical. Rand write regressed — the whole-BDI flusher batched all dirty pages in one pass with writeback_sb_inodes() under a single blk_plug, while per-inode write_inode_now() loses that batching.
Single-Client Reads
┌────────────────┬───────────┬───────────┬────────┐ │ Benchmark │ Whole-BDI │ Per-Inode │ Change │ ├────────────────┼───────────┼───────────┼────────┤ │ Seq read MB/s │ 2950 │ 2350 │ -20% │ ├────────────────┼───────────┼───────────┼────────┤ │ Rand read MB/s │ 651 │ 519 │ -20% │ └────────────────┴───────────┴───────────┴────────┘
Reads shouldn't be affected by writeback path changes. Buffered reads also dropped (2888 → 2331), suggesting different system conditions between runs rather than a per-inode regression.
Multi-Writer (Scenario A)
┌────────────────┬───────────┬───────────┬────────────┐ │ Metric │ Whole-BDI │ Per-Inode │ Change │ ├────────────────┼───────────┼───────────┼────────────┤ │ Aggregate MB/s │ 1478 │ 999 │ -32% │ ├────────────────┼───────────┼───────────┼────────────┤ │ p99.9 │ 46 ms │ 77 ms │ -67% worse │ └────────────────┴───────────┴───────────┴────────────┘
This is the biggest regression. With whole-BDI, the flusher did one batched pass through all dirty inodes via writeback_sb_inodes(). With per-inode, each of 4 writers queues a separate work item processed serially by write_inode_now() — losing the batch I/O merging benefit.
Scenario C & D (Noisy Neighbor)
┌─────────────────────────┬───────────┬───────────┬─────────────┐ │ Metric │ Whole-BDI │ Per-Inode │ Change │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario C writer │ 1468 │ 1386 │ -6% │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario C readers │ 18.7 MB/s │ 18.7 MB/s │ identical │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario D writer │ 1472 │ 1467 │ identical │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario D readers │ 496 MB/s │ 507 MB/s │ +2% │ ├─────────────────────────┼───────────┼───────────┼─────────────┤ │ Scenario D reader p99.9 │ 440 us │ 358 us │ +19% better │ └─────────────────────────┴───────────┴───────────┴─────────────┘
Mixed-mode (Scenario D) is the intended production case and it's essentially identical or slightly better — per-inode writeback creates less device contention for buffered readers.
Summary
The per-inode approach is neutral-to-slightly-better for the production scenario (Scenario D), but regresses on multi-writer and random write workloads. The core issue is loss of I/O batching
— writeback_sb_inodes() processes all dirty inodes in one blk_plug'd pass, while per-inode write_inode_now() calls are processed one at a time. The read regressions likely reflect different
system conditions since buffered/direct reads also dropped ~20%.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 6 lines · Jeff Layton
Quoted 3 lines
Assuming that looks OK, I'll probably send a v3. Original cover letter from v1 follows:
Actually, that version regressed performance in a couple of cases. I think v2 is probably the best approach, on balance.
Limiting writeback to a specific inode has many downsides as I explained before, so this is not surprising.
Quoted 1 line
Maybe we can get this into -next so that it can make v7.2?
If you want to target 7.2 we're not in any rush. If you were trying to say 7.1 we're way to close too the merge window. We also haven't heard from Jens at all, whom I'd really like to look over this.
Quoted 9 lines · Jeff Layton
This version adopts Christoph's suggest to have
generic_write_sync()kick the flusher thread for the superblock instead of initiating writeback directly. This seems to perform as well or better in most cases than doing the writeback directly.Here are results on XFS, both local and exported via knfsd:
nfsd: https://markdownpastebin.com/?id=1884b9487c404ff4b7094ed41cc48f05 xfs: https://markdownpastebin.com/?id=3c6b262182184b25b7d58fb211374475
Please add the results into the patch. Besides having them in the patch vs the cover letter, URLs to random hosting sites tend to get stale very easily.
Comments on the XFS numbers / benchmark setup:
How does O_DIRECT manage to create almost the same peek dirty as buffered? Similarly even this patched doncache show be lower, which feels odd.
(the editorializing in these results feels odd, not sure what tool generates them, but maybe edit it for the commit log to look a bit more serious).
Given that this patch does not change the read path, how do the pure read numbers for patches vs unpatched dontcache manage to differ so much?
Comments on the NFSD numbers / benchmark setup:
I though you were testing using dontcache on the server, but the comments seem to imply it is done on the client, what is the case here?
Again, the read changes between patches and unpatched look suspect. Please drill down why they happen, the fact that patches is slower here and faster in XFS makes me wonder if the results might just be very volatile?