Re: [PATCH 13/17] writeback: Factor writeback_get_folio() out of write_cache_pages()

From: Jan Kara
Date: Thu Dec 21 2023 - 06:42:19 EST


On Mon 18-12-23 16:35:49, Christoph Hellwig wrote:
> From: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
>
> Move the loop for should-we-write-this-folio to its own function.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> Signed-off-by: Christoph Hellwig <hch@xxxxxx>

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

But I'd note that the call stack depth of similarly called helper functions
(with more to come later in the series) is getting a bit confusing. Maybe
we should inline writeback_get_next() into its single caller
writeback_get_folio() to reduce confusion a bit...

Honza

> +static struct folio *writeback_get_folio(struct address_space *mapping,
> + struct writeback_control *wbc)
> +{
> + struct folio *folio;
> +
> + for (;;) {
> + folio = writeback_get_next(mapping, wbc);
> + if (!folio)
> + return NULL;
> + folio_lock(folio);
> + if (likely(should_writeback_folio(mapping, wbc, folio)))
> + break;
> + folio_unlock(folio);
> + }
> +
> + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host));
> + return folio;
> +}
> +
> static struct folio *writeback_iter_init(struct address_space *mapping,
> struct writeback_control *wbc)
> {
> @@ -2455,7 +2474,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping,
>
> wbc->err = 0;
> folio_batch_init(&wbc->fbatch);
> - return writeback_get_next(mapping, wbc);
> + return writeback_get_folio(mapping, wbc);
> }
>
> /**
> @@ -2498,17 +2517,9 @@ int write_cache_pages(struct address_space *mapping,
>
> for (folio = writeback_iter_init(mapping, wbc);
> folio;
> - folio = writeback_get_next(mapping, wbc)) {
> + folio = writeback_get_folio(mapping, wbc)) {
> unsigned long nr;
>
> - folio_lock(folio);
> - if (!should_writeback_folio(mapping, wbc, folio)) {
> - folio_unlock(folio);
> - continue;
> - }
> -
> - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host));
> -
> error = writepage(folio, wbc, data);
> nr = folio_nr_pages(folio);
> wbc->nr_to_write -= nr;
> --
> 2.39.2
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR