Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796369950; b=UKn8oU4DJlZ/5HflB/V2MYqiVsO7jGS55FKqpvu1UQhqKOr9oOCxEK5Hnfk7WjOfttSN VQA+ONQA+kac4AKegrXzmuYr6zEFiMRB+H1CH75MoqkQ6IVZnw+EAO8Dn7N9tnlMAwSSo MvwBIlzPnr36pzhHfNy1p1cEt4YANUFs5ooPWRnwGaeB1eHjVPApVg5tMBcP8plpIPBvW N+rJuAqiVH0iznpneZfCKvUv7SyL+C9OM0RGiqcKde5erIyfJ5cvfsnDIdws6KxuZVSWj pBBFPzlzccefSak/aza1V+Jyp0Ss6f0ZpneCLf848bwjQL+HhzORE2b8BckCWyXsdmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796369950; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=88r+nWMv6Yt2u4g4ZMA6qvUl6UlqwggOlZQRZju3Qnk=; b=eNlHRZP4gTl8aVBhHU9l+RI7DuIsoGVSpGpW6ocIGiLJceb6Ye6Q+/PkZryZxOrGFR2S SQsMDb6p7VY3wWLFsY5wwUzSwrsUPZ1arUxmxL1u3BV249pgDJpfHzsiMzq2LT8Yrn9Ix Tbgh4WSE92Rr2fFmeyk72xc5EyaUf+vRJIfvXKGzTld3Ve6oUzNYee9d4FEGdJFlLBX+R cnFZmKqcFrNwqg5ozSCntr03SAFlQ4rcpTyej2sSWzDjAe25bypTGBFrT7Pk74MmmrwRE hexO7fpQwW7CrECrgdlW+jIEl8sW2/uUJyKBKXoFTXucqwKiWnvrpXHEwX9p+4JqCRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WovHJqLz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31B02606A32F for ; Fri, 4 Dec 2026 07:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WovHJqLz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89E221F00936; Fri, 4 Dec 2026 07:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796369949; bh=88r+nWMv6Yt2u4g4ZMA6qvUl6UlqwggOlZQRZju3Qnk=; h=From:To:Subject:Date:In-Reply-To:References; b=WovHJqLz3tMynS+ZHxXM+MCLD6PZy9cYJej+OZ13+JXGBHFzShMYsTML9PHAgS3HR +wFde2kx8vwrluiY/0lwJibSkeYgXVy3vBEwaJDRyPUJbLouG6C/VmGgVUAkpaXp2w pUZ2Tf6nVNib/RJ2WpNPiIE5bPy5MkJLaQQf9N4ysXB7j6krvLhVw5v+bg9ZzQaajB 40wUrTyOljdxBk6H3Jvh8UBVP1L9UxCVLnep6owJSpfLvj4743S1fz3ZxkCaimmSk1 Br1M4RV6oedpitZhY2wNYyEY+8Vl/B4xqRvS0kmRO+KO4W3xJl1L9fpHqGkVmUCv67 kmcf/CCfVyuew== From: Mike Snitzer To: Matthew Wilcox , Jan Kara , linux-mm@kvack.org, Christian Brauner , 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 Message-ID: <6d449a5fa8ed7d1ed8bb997383ff8fae040e448b.1796367526.git.snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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