diff mbox series

[11/17] writeback: Use the folio_batch queue iterator

Message ID 20231218153553.807799-12-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/17] writeback: fix done_index when hitting the wbc->nr_to_write | expand

Commit Message

Christoph Hellwig Dec. 18, 2023, 3:35 p.m. UTC
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

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>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/page-writeback.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Jan Kara Dec. 21, 2023, 11:28 a.m. UTC | #1
On Mon 18-12-23 16:35:47, Christoph Hellwig wrote:
> From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> 
> 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>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Nice. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  mm/page-writeback.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index c7983ea3040be4..70f42fd9a95b5d 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -2397,13 +2397,19 @@ static pgoff_t wbc_end(struct writeback_control *wbc)
>  	return wbc->range_end >> PAGE_SHIFT;
>  }
>  
> -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);
> +
> +	if (folio)
> +		return folio;
> +
>  	folio_batch_release(&wbc->fbatch);
>  	cond_resched();
>  	filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc),
>  			wbc_to_tag(wbc), &wbc->fbatch);
> +	return folio_batch_next(&wbc->fbatch);
>  }
>  
>  static bool should_writeback_folio(struct address_space *mapping,
> @@ -2473,7 +2479,6 @@ int write_cache_pages(struct address_space *mapping,
>  {
>  	int error;
>  	pgoff_t end;		/* Inclusive */
> -	int i = 0;
>  
>  	if (wbc->range_cyclic) {
>  		wbc->index = mapping->writeback_index; /* prev offset */
> @@ -2489,18 +2494,12 @@ int write_cache_pages(struct address_space *mapping,
>  	wbc->err = 0;
>  
>  	for (;;) {
> -		struct folio *folio;
> +		struct folio *folio = writeback_get_next(mapping, wbc);
>  		unsigned long nr;
>  
> -		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++];
> -
>  		folio_lock(folio);
>  		if (!should_writeback_folio(mapping, wbc, folio)) {
>  			folio_unlock(folio);
> -- 
> 2.39.2
>
diff mbox series

Patch

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index c7983ea3040be4..70f42fd9a95b5d 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2397,13 +2397,19 @@  static pgoff_t wbc_end(struct writeback_control *wbc)
 	return wbc->range_end >> PAGE_SHIFT;
 }
 
-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);
+
+	if (folio)
+		return folio;
+
 	folio_batch_release(&wbc->fbatch);
 	cond_resched();
 	filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc),
 			wbc_to_tag(wbc), &wbc->fbatch);
+	return folio_batch_next(&wbc->fbatch);
 }
 
 static bool should_writeback_folio(struct address_space *mapping,
@@ -2473,7 +2479,6 @@  int write_cache_pages(struct address_space *mapping,
 {
 	int error;
 	pgoff_t end;		/* Inclusive */
-	int i = 0;
 
 	if (wbc->range_cyclic) {
 		wbc->index = mapping->writeback_index; /* prev offset */
@@ -2489,18 +2494,12 @@  int write_cache_pages(struct address_space *mapping,
 	wbc->err = 0;
 
 	for (;;) {
-		struct folio *folio;
+		struct folio *folio = writeback_get_next(mapping, wbc);
 		unsigned long nr;
 
-		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++];
-
 		folio_lock(folio);
 		if (!should_writeback_folio(mapping, wbc, folio)) {
 			folio_unlock(folio);