Unverified Commit 776a853a authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Christian Brauner
Browse files

i915: Use writeback_iter()



Convert from an inefficient loop to the standard writeback iterator.

Signed-off-by: default avatar"Matthew Wilcox (Oracle)" <willy@infradead.org>
Link: https://lore.kernel.org/r/20250402150005.2309458-7-willy@infradead.org


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 7b73c12c
Loading
Loading
Loading
Loading
+8 −24
Original line number Diff line number Diff line
@@ -305,36 +305,20 @@ void __shmem_writeback(size_t size, struct address_space *mapping)
		.range_end = LLONG_MAX,
		.for_reclaim = 1,
	};
	unsigned long i;
	struct folio *folio = NULL;
	int error = 0;

	/*
	 * Leave mmapings intact (GTT will have been revoked on unbinding,
	 * leaving only CPU mmapings around) and add those pages to the LRU
	 * leaving only CPU mmapings around) and add those folios to the LRU
	 * instead of invoking writeback so they are aged and paged out
	 * as normal.
	 */

	/* Begin writeback on each dirty page */
	for (i = 0; i < size >> PAGE_SHIFT; i++) {
		struct page *page;

		page = find_lock_page(mapping, i);
		if (!page)
			continue;

		if (!page_mapped(page) && clear_page_dirty_for_io(page)) {
			int ret;

			SetPageReclaim(page);
			ret = mapping->a_ops->writepage(page, &wbc);
			if (!PageWriteback(page))
				ClearPageReclaim(page);
			if (!ret)
				goto put;
		}
		unlock_page(page);
put:
		put_page(page);
	while ((folio = writeback_iter(mapping, &wbc, folio, &error))) {
		if (folio_mapped(folio))
			folio_redirty_for_writepage(&wbc, folio);
		else
			error = shmem_writeout(folio, &wbc);
	}
}