Commit acc8d858 authored by Vishal Moola (Oracle)'s avatar Vishal Moola (Oracle) Committed by Andrew Morton

afs: convert afs_writepages_region() to use filemap_get_folios_tag()

Convert to use folios throughout.  This function is in preparation to
remove find_get_pages_range_tag().

Also modify this function to write the whole batch one at a time, rather
than calling for a new set every single write.

Link: https://lkml.kernel.org/r/20230104211448.4804-6-vishal.moola@gmail.comSigned-off-by: default avatarVishal Moola (Oracle) <vishal.moola@gmail.com>
Tested-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0fff435f
...@@ -704,85 +704,87 @@ static int afs_writepages_region(struct address_space *mapping, ...@@ -704,85 +704,87 @@ static int afs_writepages_region(struct address_space *mapping,
bool max_one_loop) bool max_one_loop)
{ {
struct folio *folio; struct folio *folio;
struct page *head_page; struct folio_batch fbatch;
ssize_t ret; ssize_t ret;
unsigned int i;
int n, skips = 0; int n, skips = 0;
_enter("%llx,%llx,", start, end); _enter("%llx,%llx,", start, end);
folio_batch_init(&fbatch);
do { do {
pgoff_t index = start / PAGE_SIZE; pgoff_t index = start / PAGE_SIZE;
n = find_get_pages_range_tag(mapping, &index, end / PAGE_SIZE, n = filemap_get_folios_tag(mapping, &index, end / PAGE_SIZE,
PAGECACHE_TAG_DIRTY, 1, &head_page); PAGECACHE_TAG_DIRTY, &fbatch);
if (!n) if (!n)
break; break;
for (i = 0; i < n; i++) {
folio = fbatch.folios[i];
start = folio_pos(folio); /* May regress with THPs */
folio = page_folio(head_page); _debug("wback %lx", folio_index(folio));
start = folio_pos(folio); /* May regress with THPs */
_debug("wback %lx", folio_index(folio));
/* At this point we hold neither the i_pages lock nor the /* At this point we hold neither the i_pages lock nor the
* page lock: the page may be truncated or invalidated * page lock: the page may be truncated or invalidated
* (changing page->mapping to NULL), or even swizzled * (changing page->mapping to NULL), or even swizzled
* back from swapper_space to tmpfs file mapping * back from swapper_space to tmpfs file mapping
*/ */
if (wbc->sync_mode != WB_SYNC_NONE) { if (wbc->sync_mode != WB_SYNC_NONE) {
ret = folio_lock_killable(folio); ret = folio_lock_killable(folio);
if (ret < 0) { if (ret < 0) {
folio_put(folio); folio_batch_release(&fbatch);
return ret; return ret;
} }
} else { } else {
if (!folio_trylock(folio)) { if (!folio_trylock(folio))
folio_put(folio); continue;
return 0;
} }
}
if (folio_mapping(folio) != mapping || if (folio->mapping != mapping ||
!folio_test_dirty(folio)) { !folio_test_dirty(folio)) {
start += folio_size(folio); start += folio_size(folio);
folio_unlock(folio); folio_unlock(folio);
folio_put(folio); continue;
continue; }
}
if (folio_test_writeback(folio) || if (folio_test_writeback(folio) ||
folio_test_fscache(folio)) { folio_test_fscache(folio)) {
folio_unlock(folio); folio_unlock(folio);
if (wbc->sync_mode != WB_SYNC_NONE) { if (wbc->sync_mode != WB_SYNC_NONE) {
folio_wait_writeback(folio); folio_wait_writeback(folio);
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
folio_wait_fscache(folio); folio_wait_fscache(folio);
#endif #endif
} else { } else {
start += folio_size(folio); start += folio_size(folio);
}
if (wbc->sync_mode == WB_SYNC_NONE) {
if (skips >= 5 || need_resched()) {
*_next = start;
_leave(" = 0 [%llx]", *_next);
return 0;
}
skips++;
}
continue;
} }
folio_put(folio);
if (wbc->sync_mode == WB_SYNC_NONE) { if (!folio_clear_dirty_for_io(folio))
if (skips >= 5 || need_resched()) BUG();
break; ret = afs_write_back_from_locked_folio(mapping, wbc,
skips++; folio, start, end);
if (ret < 0) {
_leave(" = %zd", ret);
folio_batch_release(&fbatch);
return ret;
} }
continue;
}
if (!folio_clear_dirty_for_io(folio)) start += ret;
BUG();
ret = afs_write_back_from_locked_folio(mapping, wbc, folio, start, end);
folio_put(folio);
if (ret < 0) {
_leave(" = %zd", ret);
return ret;
} }
start += ret; folio_batch_release(&fbatch);
if (max_one_loop)
break;
cond_resched(); cond_resched();
} while (wbc->nr_to_write > 0); } while (wbc->nr_to_write > 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment