Re: [RFC PATCH v2 2/5] iomap: Add initial support for buffered RWF_WRITETHROUGH

From: Pankaj Raghav (Samsung)

Date: Fri Apr 17 2026 - 00:17:27 EST


<snip>
> 3.3. Wait for any current writeback to complete and then call
> folio_mkclean() to prevent mmap writes from changing it.
> 3.4. Start writeback on the folio
<snip>
> +
> +/**
> + * iomap_writethrough_begin - prepare the various structures for writethrough
> + * @folio: folio to prepare for writethrough
> + * @off: offset of write within folio
> + * @len: len of write within folio
> + *
> + * This function does the major preparation work needed before starting the
> + * writethrough. The main task is to prepare folio for writeththrough by blocking
> + * mmap writes and setting writeback on it. Further, we must clear the write range
> + * to non-dirty. If this results in the complete folio becoming non-dirty, then we
> + * need to clear the master dirty bit.
> + */
> +static void iomap_folio_prepare_writethrough(struct folio *folio, size_t off,
> + size_t len)
> +{
> + bool fully_written;
> + u64 zero = 0;
> +
> + if (folio_test_writeback(folio))
> + folio_wait_writeback(folio);
> +
> + if (folio_mkclean(folio))
> + folio_mark_dirty(folio);
> +
> + /*
> + * We might either write through the complete folio or a partial folio
> + * writethrough might result in all blocks becoming non-dirty, so we need to
> + * check and mark the folio clean if that is the case.
> + */
> + fully_written = (off == 0 && len == folio_size(folio));
> + iomap_clear_range_dirty(folio, off, len);
> + if (fully_written ||
> + !iomap_find_dirty_range(folio, &zero, folio_size(folio)))
> + folio_clear_dirty_for_writethrough(folio);

I get the point where you want to prevent mmap writes before the current
writeback completes. It is not very obvious to me why folio_mkclean
and folio_mark_dirty had to be moved out and then we call the
folio_clear_dirty_for_writethrough wrapper. Anyway those calls are made
after we do folio_wait_writeback right?
Is to cover the cases where we do partial write in which case we don't
end up calling folio_clear_dirty_for_io? If that is the case, then a small
comment on top of folio_mkclean would make it a bit more clear.

--
Pankaj