Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	linux-mm@kvack.org, Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH v13 7/7] NFSD: do not kick DONTCACHE writeback for a WRITE that NFSD syncs
Date: Fri,  4 Dec 2026 02:38:56 -0500	[thread overview]
Message-ID: <6d449a5fa8ed7d1ed8bb997383ff8fae040e448b.1796367526.git.snitzer@kernel.org> (raw)
In-Reply-To: <cover.1796367526.git.snitzer@kernel.org>

NFSD splits a misaligned direct-mode WRITE into a direct middle and
buffered DONTCACHE ends.  Each end covers its first or last unit, the
smallest folio the mapping allows, only partially.  The other WRITEs
that cover the rest of that unit share it.  The page cache keeps such a
unit until a write completes it, and the write that completes it marks
it dropbehind.

For a split WRITE that the client sends as FILE_SYNC or DATA_SYNC, NFSD
takes IOCB_DSYNC off each segment and runs one vfs_fsync_range() over
the whole WRITE.  Without IOCB_DSYNC, each buffered segment kicks
DONTCACHE writeback, for folios that NFSD's own sync is about to write.
Set IOCB_DONTCACHE_NOKICK on the segments of such a WRITE.

Describe in nfsd-io-modes.rst how the shared pages are kept and
dropped.

Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 Documentation/filesystems/nfs/nfsd-io-modes.rst | 16 ++++++++++++++++
 fs/nfsd/vfs.c                                   |  5 ++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Documentation/filesystems/nfs/nfsd-io-modes.rst b/Documentation/filesystems/nfs/nfsd-io-modes.rst
index 28235eceb0c7d..b59fa6e3fd44a 100644
--- a/Documentation/filesystems/nfs/nfsd-io-modes.rst
+++ b/Documentation/filesystems/nfs/nfsd-io-modes.rst
@@ -197,6 +197,22 @@ Misaligned WRITE:
     above. Set it to N for a workload that reads back or rewrites what
     it just wrote.
 
+    The page holding a start or end segment is shared with the other
+    WRITEs that cover the rest of the page, which may arrive before,
+    after or at the same time, from any client. So that the later WRITEs
+    to such a page do not have to read it back from disk, the page cache
+    keeps a page that a DONTCACHE write covers only partially until a
+    write completes it, and drops it once it is written back. A page
+    that no other WRITE completes stays cached until it is reclaimed.
+    The first and last pages of a WRITE that is not split are handled
+    the same way. A split FILE_SYNC or DATA_SYNC WRITE does not kick
+    DONTCACHE writeback for its buffered segments: its own sync writes
+    them back.
+
+    None of this applies when the start and end segments are normal
+    buffered IO, or for a filesystem that does not use iomap for
+    buffered writes.
+
 Tracing:
     The nfsd_read_direct trace event marks a READ that NFSD issues as
     O_DIRECT. It records the offset and length the client requested.
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index a990c76dce0fc..67f4d3c7faaff 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1556,7 +1556,8 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	 * Sync a split WRITE once, after its last segment, instead of after
 	 * each segment that carries IOCB_DSYNC. A single segment keeps the
 	 * flag so a direct overwrite can complete with FUA instead of a cache
-	 * flush.
+	 * flush. The sync writes back the buffered DONTCACHE segments, so
+	 * they do not kick DONTCACHE writeback.
 	 */
 	sync_flags = kiocb->ki_flags & (IOCB_DSYNC | IOCB_SYNC);
 	if (nsegs == 1)
@@ -1565,6 +1566,8 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	*cnt = 0;
 	for (i = 0; i < nsegs; i++) {
 		kiocb->ki_flags = segments[i].flags & ~sync_flags;
+		if (sync_flags)
+			kiocb->ki_flags |= IOCB_DONTCACHE_NOKICK;
 		trace_nfsd_write_direct(rqstp, fhp, kiocb->ki_pos,
 					segments[i].iter.count,
 					kiocb->ki_flags);
-- 
2.52.0



      parent reply	other threads:[~2026-12-04  7:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Mike Snitzer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d449a5fa8ed7d1ed8bb997383ff8fae040e448b.1796367526.git.snitzer@kernel.org \
    --to=snitzer@kernel.org \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox