• Brian Foster's avatar
    iomap: make zero range flush conditional on unwritten mappings · 7d9b474e
    Brian Foster authored
    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: default avatarBrian Foster <bfoster@redhat.com>
    Link: https://lore.kernel.org/r/20240830145634.138439-3-bfoster@redhat.comReviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
    7d9b474e
buffered-io.c 59.4 KB