diff mbox series

[06/12] writeback: Use the folio_batch queue iterator

Message ID 20230626173521.459345-7-willy@infradead.org (mailing list archive)
State New
Headers show
Series Convert write_cache_pages() to an iterator | expand

Commit Message

Matthew Wilcox June 26, 2023, 5:35 p.m. UTC
Instead of keeping our own local iterator variable, use the one just
added to folio_batch.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/page-writeback.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

Comments

Christoph Hellwig June 27, 2023, 4:25 a.m. UTC | #1
On Mon, Jun 26, 2023 at 06:35:15PM +0100, Matthew Wilcox (Oracle) wrote:
> Instead of keeping our own local iterator variable, use the one just
> added to folio_batch.

Ok, that's a slightly different twist to what I just suggested.

>  	for (;;) {
> -		struct folio *folio;
> +		struct folio *folio = writeback_get_next(mapping, wbc);
>  
> +		if (!folio)
>  			break;

But as a purely cosmetic nit I still think this would read nicer as:

	while ((folio = writeback_get_next(mapping, wbc))) {
diff mbox series

Patch

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 68f28eeb15ed..f782b48c5b0c 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2378,11 +2378,15 @@  static int writeback_finish(struct address_space *mapping,
 	return wbc->err;
 }
 
-static void writeback_get_batch(struct address_space *mapping,
+static struct folio *writeback_get_next(struct address_space *mapping,
 		struct writeback_control *wbc)
 {
+	struct folio *folio = folio_batch_next(&wbc->fbatch);
 	xa_mark_t tag;
 
+	if (folio)
+		return folio;
+
 	if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
 		tag = PAGECACHE_TAG_TOWRITE;
 	else
@@ -2392,6 +2396,7 @@  static void writeback_get_batch(struct address_space *mapping,
 	cond_resched();
 	filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag,
 			&wbc->fbatch);
+	return folio_batch_next(&wbc->fbatch);
 }
 
 static bool should_writeback_folio(struct address_space *mapping,
@@ -2461,7 +2466,6 @@  int write_cache_pages(struct address_space *mapping,
 		      void *data)
 {
 	int error;
-	int i = 0;
 
 	if (wbc->range_cyclic) {
 		wbc->index = mapping->writeback_index; /* prev offset */
@@ -2480,17 +2484,11 @@  int write_cache_pages(struct address_space *mapping,
 	wbc->err = 0;
 
 	for (;;) {
-		struct folio *folio;
+		struct folio *folio = writeback_get_next(mapping, wbc);
 
-		if (i == wbc->fbatch.nr) {
-			writeback_get_batch(mapping, wbc);
-			i = 0;
-		}
-		if (wbc->fbatch.nr == 0)
+		if (!folio)
 			break;
 
-		folio = wbc->fbatch.folios[i++];
-
 		wbc->done_index = folio->index;
 
 		folio_lock(folio);