Re: [PATCH 03/12] writeback: Factor should_writeback_folio() out of write_cache_pages()

From: Matthew Wilcox
Date: Tue Jun 27 2023 - 10:51:41 EST


On Tue, Jun 27, 2023 at 12:16:34PM +0100, Matthew Wilcox wrote:
> This might be a good point to share that I'm considering (eventually)
> not taking the folio lock here.
>
> My plan looks something like this (not fully baked):
>
> truncation (and similar) paths currently lock the folio, They would both
> lock the folio _and_ claim that they were doing writeback on the folio.
>
> Filesystems would receive the folio from the writeback iterator with
> the writeback flag already set.
>
>
> This allows, eg, folio mapping/unmapping to take place completely
> independent of writeback. That seems like a good thing; I can't see
> why the two should be connected.

Ah, i_size is a problem. With an extending write, i_size is updated
while holding the folio lock. If we're writing back a partial folio,
we zero the tail. That must not race with an extending write. So
either we'd need to take both the folio lock & wb_lock when updating
i_size, or we'd need to take both the lock and wb_lock when writing
back the last page of a file.