From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93169606A337 for ; Fri, 4 Dec 2026 07:39:04 +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=Vqe760oi Received: by kanga.kvack.org (Postfix) id 94BD96B05B1; Fri, 4 Dec 2026 02:39:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FCE06B05B2; Fri, 4 Dec 2026 02:39:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 812856B05B3; Fri, 4 Dec 2026 02:39:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6061C6B05B1 for ; Fri, 4 Dec 2026 02:39:03 -0500 (EST) Received: from smtpin16.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E07351A015B for ; Fri, 4 Dec 2026 07:39:02 +0000 (UTC) X-FDA: 85505499324.16.07F5CA0 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf02.hostedemail.com (Postfix) with ESMTP id 671BE80009 for ; Fri, 4 Dec 2026 07:39:01 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Vqe760oi; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of snitzer@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=snitzer@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796369941; b=x8Pl8iIBE2C5EtMBJeIazIDmG5jmH9xvkDom5s0Q9AIAXGoKKEG8EqBGHx7qH4Avl3aTk8 pFFXpNF4qUDh3B4CTcwZyraY3r5atBLCieBJ9kafzEiHmSA9UlkQdjd47qmB9use3KLWhp 69qmuOjSc496CIfziyTJrHJ48KyC4qQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796369941; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=QnBHVHdizLckSntHvVTHXIta6LB2CNRPb6oR6sGkWZs=; b=MnQgPqJRT6oKp1sozS4FXhkKFaM1dRNuuhQIJDuxUjJc2jHgiLR02V8Wq4y/Me1nQeZY+H u4vMc6ZjoZlVrd8dbTAmK/oAYuaDJca7ZPMBQ4utye9WRYMp3fGOOfzbQ5XG5Bpv4NWxNu lLoK+408iE6qNWpCIadF0eXpFCkPP/Q= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Vqe760oi; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of snitzer@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=snitzer@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 05A7D61806; Fri, 4 Dec 2026 07:39:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 796FB1F000C2; Fri, 4 Dec 2026 07:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796369940; bh=QnBHVHdizLckSntHvVTHXIta6LB2CNRPb6oR6sGkWZs=; h=From:To:Subject:Date; b=Vqe760oi3VMRy/Dt9B+7dQQM2HtERMQEQCQ9OHjpRPLExGovlaNNUS1zPKOL/YGFC 0JmZWhGPBnzJOnUvPSiHjyYu1FCT1zdikue16eBfqb9CgxS5UE8vSsHdsg30rP306v wdlwE7+YxmUerPieWaXEQemYVNvEsQxjclz1SZHe6awRqecMmK8iii+7CNl+i0wdoB KvWU73vD/qVVtz9ADFSB8QcYB2ldPeetYSeMqqX4FN56W0tSbfxySGEEaYo9LbpgRS eiDeL0LGgPdlut14u4M8W/MnMdWMbppE0YBqZU3ZCwa4WnwQnAybQxzTHiE8GFFDWA FZ4UszzLoichw== From: Mike Snitzer To: Matthew Wilcox , Jan Kara , linux-mm@kvack.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH v13 0/7] mm, iomap, NFSD: stop DONTCACHE writes reading back shared pages Date: Fri, 4 Dec 2026 02:38:49 -0500 Message-ID: X-Mailer: git-send-email 2.44.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam04 X-Rspam-User: X-Rspamd-Queue-Id: 671BE80009 X-Stat-Signature: x6n7bwoyafuntbtk39h4uft9ek3sgqxn X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796369941-926597 X-HE-Meta: U2FsdGVkX19Y89haUhVl1gRnX1y7j8M030rN8NqhyEo2RupKXYw9o2wU2drFwuhHh6yJWXHnDfHleiACjYVxqlQcdMOxdaRwv3jt+nGZjttp7SF4JPxnQwaDk8Bdgkw04wdwuJqA4JDKXh1RfKTrx7jnYlI74b9VnoqboTp9sB89oAPJTZ+Y0hdpBoA4mJWE5xOTcMFB0KHrlO4/t0San11x+gTuoQRZ9w+X+5cd6BPDnIeqOeAj59dYRsMZcdXJUzCazbXveQ3vTDnQI+H4GLuYcTuO6VTDEGovIcIYXDQ3afXHkcMF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XlhF596+jKpet8jx4KZk2We+Rb9FTssGNmnlUX4bi9j+9wM= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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