Skip to content

Commit

Permalink
writeback: move the folio_prepare_writeback loop out of write_cache_p…
Browse files Browse the repository at this point in the history
…ages()

Move the loop for should-we-write-this-folio to writeback_get_folio.

[hch@lst.de: fold loop into existing helper instead of a separate one per Jan]
Link: https://lkml.kernel.org/r/20240215063649.2164017-13-hch@lst.de
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Dave Chinner <dchinner@redhat.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Matthew Wilcox (Oracle) authored and Andrew Morton committed Feb 24, 2024
1 parent e6d0ab8 commit a2cbc13
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mm/page-writeback.c
Original file line number Diff line number Diff line change
Expand Up @@ -2411,15 +2411,25 @@ static struct folio *writeback_get_folio(struct address_space *mapping,
{
struct folio *folio;

retry:
folio = folio_batch_next(&wbc->fbatch);
if (!folio) {
folio_batch_release(&wbc->fbatch);
cond_resched();
filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc),
wbc_to_tag(wbc), &wbc->fbatch);
folio = folio_batch_next(&wbc->fbatch);
if (!folio)
return NULL;
}

folio_lock(folio);
if (unlikely(!folio_prepare_writeback(mapping, wbc, folio))) {
folio_unlock(folio);
goto retry;
}

trace_wbc_writepage(wbc, inode_to_bdi(mapping->host));
return folio;
}

Expand Down Expand Up @@ -2480,14 +2490,6 @@ int write_cache_pages(struct address_space *mapping,
if (!folio)
break;

folio_lock(folio);
if (!folio_prepare_writeback(mapping, wbc, folio)) {
folio_unlock(folio);
continue;
}

trace_wbc_writepage(wbc, inode_to_bdi(mapping->host));

error = writepage(folio, wbc, data);
wbc->nr_to_write -= folio_nr_pages(folio);

Expand Down

0 comments on commit a2cbc13

Please sign in to comment.