Skip to content

Commit

Permalink
writeback: account the number of pages written back
Browse files Browse the repository at this point in the history
nr_to_write is a count of pages, so we need to decrease it by the number
of pages in the folio we just wrote, not by 1.  Most callers specify
either LONG_MAX or 1, so are unaffected, but writeback_sb_inodes() might
end up writing 512x as many pages as it asked for.

Dave added:

: XFS is the only filesystem this would affect, right?  AFAIA, nothing
: else enables large folios and uses writeback through
: write_cache_pages() at this point...
: 
: In which case, I'd be surprised if much difference, if any, gets
: noticed by anyone.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 793917d ("mm/readahead: Add large folio readahead")
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Dave Chinner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) authored and akpm00 committed Jul 8, 2023
1 parent 6dca4ac commit 8344a3d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mm/page-writeback.c
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,7 @@ int write_cache_pages(struct address_space *mapping,

for (i = 0; i < nr_folios; i++) {
struct folio *folio = fbatch.folios[i];
unsigned long nr;

done_index = folio->index;

Expand Down Expand Up @@ -2471,6 +2472,7 @@ int write_cache_pages(struct address_space *mapping,

trace_wbc_writepage(wbc, inode_to_bdi(mapping->host));
error = writepage(folio, wbc, data);
nr = folio_nr_pages(folio);
if (unlikely(error)) {
/*
* Handle errors according to the type of
Expand All @@ -2489,8 +2491,7 @@ int write_cache_pages(struct address_space *mapping,
error = 0;
} else if (wbc->sync_mode != WB_SYNC_ALL) {
ret = error;
done_index = folio->index +
folio_nr_pages(folio);
done_index = folio->index + nr;
done = 1;
break;
}
Expand All @@ -2504,7 +2505,8 @@ int write_cache_pages(struct address_space *mapping,
* keep going until we have written all the pages
* we tagged for writeback prior to entering this loop.
*/
if (--wbc->nr_to_write <= 0 &&
wbc->nr_to_write -= nr;
if (wbc->nr_to_write <= 0 &&
wbc->sync_mode == WB_SYNC_NONE) {
done = 1;
break;
Expand Down

0 comments on commit 8344a3d

Please sign in to comment.