linux/fs/iomap
Brian Foster 7d9b474ee4 iomap: make zero range flush conditional on unwritten mappings
iomap_zero_range() flushes pagecache to mitigate consistency
problems with dirty pagecache and unwritten mappings. The flush is
unconditional over the entire range because checking pagecache state
after mapping lookup is racy with writeback and reclaim. There are
ways around this using iomap's mapping revalidation mechanism, but
this is not supported by all iomap based filesystems and so is not a
generic solution.

There is another way around this limitation that is good enough to
filter the flush for most cases in practice. If we check for dirty
pagecache over the target range (instead of unconditionally flush),
we can keep track of whether the range was dirty before lookup and
defer the flush until/unless we see a combination of dirty cache
backed by an unwritten mapping. We don't necessarily know whether
the dirty cache was backed by the unwritten maping or some other
(written) part of the range, but the impliciation of a false
positive here is a spurious flush and thus relatively harmless.

Note that we also flush for hole mappings because iomap_zero_range()
is used for partial folio zeroing in some cases. For example, if a
folio straddles EOF on a sub-page FSB size fs, the post-eof portion
is hole-backed and dirtied/written via mapped write, and then i_size
increases before writeback can occur (which otherwise zeroes the
post-eof portion of the EOF folio), then the folio becomes
inconsistent with disk until reclaimed. A flush in this case
executes partial zeroing from writeback, and iomap knows that there
is otherwise no I/O to submit for hole backed mappings.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Link: https://lore.kernel.org/r/20240830145634.138439-3-bfoster@redhat.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-09-03 15:01:24 +02:00
..
buffered-io.c iomap: make zero range flush conditional on unwritten mappings 2024-09-03 15:01:24 +02:00
direct-io.c iomap: remove set_memor_ro() on zero page 2024-09-03 15:01:23 +02:00
fiemap.c fs: Move many prototypes to pagemap.h 2022-03-21 12:59:02 -04:00
iter.c iomap: write iomap validity checks 2022-11-29 09:09:17 +11:00
Makefile kbuild: use $(src) instead of $(srctree)/$(src) for source directory 2024-05-10 04:34:52 +09:00
seek.c iomap: switch iomap_seek_data to use iomap_iter 2021-08-16 21:26:33 -07:00
swapfile.c mm/swap: consider max pages in iomap_swapfile_add_extent 2021-08-18 12:47:52 -07:00
trace.c iomap: Add DIO tracepoints 2023-04-21 08:54:47 -07:00
trace.h iomap: Add processed for iomap_iter 2024-02-21 08:37:50 +01:00