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

From: Ojaswin Mujoo

Date: Sat Apr 18 2026 - 03:34:57 EST


On Fri, Apr 17, 2026 at 06:13:31AM +0200, Pankaj Raghav (Samsung) wrote:
> <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.

Hey Pankaj,

Yes you are right, we need to call folio_wait_writeback() and mkclean()
for partial or complete writes. However, clearing of foliodirty bit and
accounting shall only be done when the complete folio becomes clean, and
hence we call folio_clear_dirty_for_writethrough() only for those cases.

I will add a more clear comment for this in v3.

Thanks,
Ojaswin

>
> --
> Pankaj