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

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.com


Signed-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
Loading
Loading
Loading
Loading
+59 −57
Original line number Diff line number Diff line
@@ -704,21 +704,24 @@ static int afs_writepages_region(struct address_space *mapping,
				 bool max_one_loop)
{
	struct folio *folio;
	struct page *head_page;
	struct folio_batch fbatch;
	ssize_t ret;
	unsigned int i;
	int n, skips = 0;

	_enter("%llx,%llx,", start, end);
	folio_batch_init(&fbatch);

	do {
		pgoff_t index = start / PAGE_SIZE;

		n = find_get_pages_range_tag(mapping, &index, end / PAGE_SIZE,
					     PAGECACHE_TAG_DIRTY, 1, &head_page);
		n = filemap_get_folios_tag(mapping, &index, end / PAGE_SIZE,
					PAGECACHE_TAG_DIRTY, &fbatch);

		if (!n)
			break;

		folio = page_folio(head_page);
		for (i = 0; i < n; i++) {
			folio = fbatch.folios[i];
			start = folio_pos(folio); /* May regress with THPs */

			_debug("wback %lx", folio_index(folio));
@@ -731,21 +734,18 @@ static int afs_writepages_region(struct address_space *mapping,
			if (wbc->sync_mode != WB_SYNC_NONE) {
				ret = folio_lock_killable(folio);
				if (ret < 0) {
				folio_put(folio);
					folio_batch_release(&fbatch);
					return ret;
				}
			} else {
			if (!folio_trylock(folio)) {
				folio_put(folio);
				return 0;
			}
				if (!folio_trylock(folio))
					continue;
			}

		if (folio_mapping(folio) != mapping ||
			if (folio->mapping != mapping ||
			    !folio_test_dirty(folio)) {
				start += folio_size(folio);
				folio_unlock(folio);
			folio_put(folio);
				continue;
			}

@@ -760,10 +760,12 @@ static int afs_writepages_region(struct address_space *mapping,
				} else {
					start += folio_size(folio);
				}
			folio_put(folio);
				if (wbc->sync_mode == WB_SYNC_NONE) {
				if (skips >= 5 || need_resched())
					break;
					if (skips >= 5 || need_resched()) {
						*_next = start;
						_leave(" = 0 [%llx]", *_next);
						return 0;
					}
					skips++;
				}
				continue;
@@ -771,18 +773,18 @@ static int afs_writepages_region(struct address_space *mapping,

			if (!folio_clear_dirty_for_io(folio))
				BUG();
		ret = afs_write_back_from_locked_folio(mapping, wbc, folio, start, end);
		folio_put(folio);
			ret = afs_write_back_from_locked_folio(mapping, wbc,
					folio, start, end);
			if (ret < 0) {
				_leave(" = %zd", ret);
				folio_batch_release(&fbatch);
				return ret;
			}

			start += ret;
		}

		if (max_one_loop)
			break;

		folio_batch_release(&fbatch);
		cond_resched();
	} while (wbc->nr_to_write > 0);