@@ -2429,6 +2429,28 @@ static bool should_writeback_folio(struct address_space *mapping,
return true;
}
+static struct folio *writeback_iter_init(struct address_space *mapping,
+ struct writeback_control *wbc)
+{
+ if (wbc->range_cyclic) {
+ wbc->index = mapping->writeback_index; /* prev offset */
+ wbc->end = -1;
+ } else {
+ wbc->index = wbc->range_start >> PAGE_SHIFT;
+ wbc->end = wbc->range_end >> PAGE_SHIFT;
+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
+ wbc->range_whole = 1;
+ }
+ if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
+ tag_pages_for_writeback(mapping, wbc->index, wbc->end);
+
+ wbc->done_index = wbc->index;
+ folio_batch_init(&wbc->fbatch);
+ wbc->err = 0;
+
+ return writeback_get_next(mapping, wbc);
+}
+
/**
* write_cache_pages - walk the list of dirty pages of the given address space and write all of them.
* @mapping: address space structure to write
@@ -2464,31 +2486,14 @@ int write_cache_pages(struct address_space *mapping,
struct writeback_control *wbc, writepage_t writepage,
void *data)
{
+ struct folio *folio;
int error;
- if (wbc->range_cyclic) {
- wbc->index = mapping->writeback_index; /* prev offset */
- wbc->end = -1;
- } else {
- wbc->index = wbc->range_start >> PAGE_SHIFT;
- wbc->end = wbc->range_end >> PAGE_SHIFT;
- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
- wbc->range_whole = 1;
- }
- if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
- tag_pages_for_writeback(mapping, wbc->index, wbc->end);
-
- wbc->done_index = wbc->index;
- folio_batch_init(&wbc->fbatch);
- wbc->err = 0;
-
- for (;;) {
- struct folio *folio = writeback_get_next(mapping, wbc);
+ for (folio = writeback_iter_init(mapping, wbc);
+ folio;
+ folio = writeback_get_next(mapping, wbc)) {
unsigned long nr;
- if (!folio)
- break;
-
wbc->done_index = folio->index;
folio_lock(folio);