Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH v13 0/7] mm, iomap, NFSD: stop DONTCACHE writes reading back shared pages
@ 2026-12-04  7:38 Mike Snitzer
  2026-12-04  7:38 ` [PATCH v13 1/7] mm: move clearing the dropbehind flag of a found folio into a helper Mike Snitzer
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Mike Snitzer @ 2026-12-04  7:38 UTC (permalink / raw)
  To: Matthew Wilcox, Jan Kara, linux-mm, Christian Brauner,
	linux-fsdevel

Hi,

An RWF_DONTCACHE write is buffered IO: its data goes through the page
cache, and writeback drops each folio once the folio is written back.  A
write that starts or ends inside a folio covers that folio only
partially.  Usually other writes cover the rest of the folio.  If
writeback drops the folio before the other writes write their parts, the
next of them must first read the folio back from disk.  32 threads
writing interleaved records to one XFS file, 4 KiB pages, before and
after 5/7:

  record  pwritev2() flags          4 KiB device       MiB/s
  bytes                             reads per write
                                    before   after     before  after
  47008   RWF_DONTCACHE             0.97     0.0007    831     2152
  47008   RWF_DONTCACHE|RWF_DSYNC   0.99     0.0007    601     1210
  6000    RWF_DONTCACHE             0.97     0.0001    121      502
  6000    RWF_DONTCACHE|RWF_DSYNC   0.99     0.0001     90      209

47008 bytes is the transfer size of IO500's ior-hard, in which each
rank writes interleaved records to one shared file.  Any record size
that is not a multiple of the page size has the same problem.  6000
bytes is a second example.

The test program and script: https://lore.kernel.org/linux-nfs/atqJBS8MlYfeUU-t@kernel.org/

- 1/7 moves code into a helper, with no functional change.
- 2/7 fixes 88d6f128d06d ("mm: track DONTCACHE dirty pages per
  bdi_writeback"), in v7.3: WB_DONTCACHE_DIRTY could drift.
- 3/7 reports WB_DONTCACHE_DIRTY in the bdi debugfs stats.
- 4/7 adds folio_mark_dropbehind() for a folio that is already dirty.
- 5/7 keeps a partially covered folio until the write that completes
  it.  The change is in iomap only.
- 6/7 adds IOCB_DONTCACHE_NOKICK: a writer that syncs the range itself
  does not kick DONTCACHE writeback.
- 7/7 makes NFSD set it for a split FILE_SYNC or DATA_SYNC WRITE.

Merging: Chuck suggested taking the series through the mm tree.  1/7 to
6/7 apply cleanly to each of these mm branches:

  mm-unstable  e685fdf67323 ("zram: publish streams under lock in zcomp_cpu_up_prepare()")
  mm-new       1a7610248a38 ("mm/zsmalloc: remove shrinker")
  mm-stable    6cce17ffe54a ("Merge tag 'staging-7.4-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging")

7/7 needs the NFSD direct-mode changes that are in cel/nfsd-testing.
The whole series applies to cel/nfsd-testing at eb76c146d6fa ("NFSD:
parse fsloc and secinfo export options without CONFIG_NFSD_V4"), where
each patch builds with W=1 with no warnings.  So 7/7 could follow in
the nfsd tree once the mm part is merged.

Changes since v12:
- Added Jan's Reviewed-by to 1/7, 2/7 and 3/7.
- 2/7: the count to subtract is -(long)folio_nr_pages().  v12 negated
  the unsigned value, which added about 2^32 to WB_DONTCACHE_DIRTY on
  32-bit.  sashiko found this in its review of v12 2/7
  (https://lore.kernel.org/r/sashiko-outbox-213508@kernel.org).
- 5/7 to 7/7 are much simpler, after Jan's review of v12
  (https://lore.kernel.org/linux-nfs/iushs6l3mjqkq65srej4gevaf2oeazy5j5miaipy6yxscetzjd@d4ti4qgbhman/).
  5/7 to 7/7 now add 122 lines and remove 10.  In v12 they added 287
  lines and removed 18.  The whole series now adds 198 lines and removes
  23, against 370 and 31 in v12.
- 5/7 is now in iomap only.  iomap looks up a partially covered folio
  without FGP_DONTCACHE, as Jan suggested, so a new folio is not marked
  dropbehind.  If this write completes the folio, iomap marks it after
  the write copies its part into it.  iomap can give a folio up without
  writing it: the mapping can go stale, or a copy can come up short.
  Such a folio stays unmarked.  FGP_DONTCACHE_EDGE and
  folio_dontcache_edge_written() are gone, and 5/7 does not change
  mm/filemap.c.  iomap_write_begin() makes the decision before it reads
  or zeroes the rest of the folio.  It returns the decision to
  iomap_write_iter(), which marks the folio after the copy.
- 5/7 also checks the file size.  An appending write makes its folio
  uptodate, because iomap fills the part past EOF with zeroes.  v12 took
  that for the data of the other writes, so the next append marked the
  folio before it was complete.  Benjamin Coddington found this.  One
  writer appended 4000-byte records with RWF_DONTCACHE|RWF_DSYNC to XFS
  with 16 KiB blocks.  It read back about half of its writes and left
  91% of the file cached.  Now the part of the folio outside the write
  must also lie below EOF.
- 6/7 replaces the interface of v12 6/7 (IOCB_DONTCACHE_DEFER,
  IOMAP_DONTCACHE_DEFER, FGP_DONTCACHE_DEFER,
  filemap_dontcache_edge_completes() and
  filemap_dontcache_edge_complete()) with one flag,
  IOCB_DONTCACHE_NOKICK.  v12 6/7 existed only to stop the DONTCACHE
  writeback kick for a write whose caller syncs it.  This flag does
  that and nothing else.
- 7/7 only sets IOCB_DONTCACHE_NOKICK, and describes the shared pages in
  nfsd-io-modes.rst.  NFSD keeps no state across a WRITE.  The race of
  v12 is gone: two WRITEs that checked a shared folio at the same time,
  before either wrote it, both left it cached.  Now the check runs under
  the folio lock, inside the write.
- Dropped Jeff's Reviewed-by from 7/7, which is a new patch.
- Rebased on the current cel/nfsd-testing.

Testing, 4 KiB pages:
- Through NFSD (io_cache_write=2), 32 ranks write interleaved records to
  one file, and the client sends each WRITE as FILE_SYNC.  With
  47008-byte records: 0.0003 reads per WRITE, no DONTCACHE writeback
  kick, and 1 of the file's 524066 pages cached at the end.  With
  6000-byte records: 0.0000, no kick, 11 cached.  With v12's 6/7 and 7/7
  in place of these, the same test cached 1294 and 1400 pages, with the
  same reads and no kick.
- Benjamin's case, on XFS with 16 KiB blocks: one writer appends
  4000-byte records with RWF_DONTCACHE|RWF_DSYNC.  With v12, it read
  back 0.49 folios per write and left 91% of the file cached.  With v13,
  it reads no data back and leaves only the last folio cached.  With
  10240-byte records, v12 read back 0.25 folios per write and left 40%
  cached.  v13 again reads nothing back.
- The KUnit test of v12 (not in this series) gives the same result.
- The tests of v12 with mmap stores into a file while writes run on it,
  through NFSD and locally, give the same results with v13.  So does a
  stress run of 20 iterations through NFSD and LOCALIO.  Every record
  verifies, and WB_DONTCACHE_DIRTY is 0 at the end.

Limits: 5/7 is exact for two writes that share a folio, and for any
number of writes that append to the file.  It decides whether the other
writes wrote the rest of a folio from the uptodate state of the folio
and from the file size.  A write fills the part of a block that it does
not cover with zeroes.  Below EOF, a later write cannot tell these
zeroes from the data of another write.  So when three or more writes
share a folio below EOF, the folio can be dropped too early, and a later
write reads it back.  With 16 KiB blocks, 32 threads write interleaved
4000-byte records to one file.  They read 1.95 4 KiB blocks per write,
and 91% of the file stays cached.  With 10240-byte records, they read
0.97 blocks per write, and 39% stays cached.

v12: https://lore.kernel.org/linux-nfs/20261112190911.84702-1-snitzer@kernel.org/
v11: https://lore.kernel.org/linux-nfs/20261111015607.46338-1-snitzer@kernel.org/
v10: https://lore.kernel.org/linux-nfs/20261103211754.35352-1-snitzer@kernel.org/
v9: https://lore.kernel.org/linux-nfs/20261024221152.6965-1-snitzer@kernel.org/
v8: https://lore.kernel.org/linux-nfs/20261023024548.71123-1-snitzer@kernel.org/
v7: https://lore.kernel.org/linux-nfs/20261020220346.28020-1-snitzer@kernel.org/
v6: https://lore.kernel.org/linux-nfs/atbfEbgMU6UGkn2X@kernel.org/
v5: https://lore.kernel.org/linux-nfs/20261019150725.1507-1-snitzer@kernel.org/
v4: https://lore.kernel.org/linux-nfs/20261015233309.42999-1-snitzer@kernel.org/
v3: https://lore.kernel.org/linux-nfs/20261001045502.48381-1-snitzer@kernel.org/
v2: https://lore.kernel.org/linux-nfs/20260929231329.22018-1-snitzer@kernel.org/
v1: https://lore.kernel.org/linux-nfs/20260929173423.16149-1-snitzer@kernel.org/

Thanks,
Mike

Mike Snitzer (7):
  mm: move clearing the dropbehind flag of a found folio into a helper
  mm: take a folio off WB_DONTCACHE_DIRTY only if it was counted there
  mm: expose WB_DONTCACHE_DIRTY in bdi debugfs stats
  mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it
  iomap: keep a DONTCACHE edge folio until a write completes it
  fs: let a DONTCACHE writer that syncs the range itself skip the kick
  NFSD: do not kick DONTCACHE writeback for a WRITE that NFSD syncs

 .../filesystems/nfs/nfsd-io-modes.rst         |  16 +++
 fs/iomap/buffered-io.c                        | 103 ++++++++++++++++--
 fs/nfsd/vfs.c                                 |   5 +-
 include/linux/fs.h                            |   8 +-
 include/linux/pagemap.h                       |   1 +
 mm/backing-dev.c                              |   6 +
 mm/filemap.c                                  |  82 +++++++++++---
 7 files changed, 198 insertions(+), 23 deletions(-)


base-commit: eb76c146d6facf9588b6c1da360e2db41cdda335
-- 
2.52.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-04  7:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  7:38 [PATCH v13 0/7] mm, iomap, NFSD: stop DONTCACHE writes reading back shared pages Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 1/7] mm: move clearing the dropbehind flag of a found folio into a helper Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 2/7] mm: take a folio off WB_DONTCACHE_DIRTY only if it was counted there Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 3/7] mm: expose WB_DONTCACHE_DIRTY in bdi debugfs stats Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 4/7] mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 5/7] iomap: keep a DONTCACHE edge folio until a write completes it Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 6/7] fs: let a DONTCACHE writer that syncs the range itself skip the kick Mike Snitzer
2026-12-04  7:38 ` [PATCH v13 7/7] NFSD: do not kick DONTCACHE writeback for a WRITE that NFSD syncs Mike Snitzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox