Skip to content

Commit 8344a3d

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
writeback: account the number of pages written back
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]>
1 parent 6dca4ac commit 8344a3d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mm/page-writeback.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,7 @@ int write_cache_pages(struct address_space *mapping,
24342434

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

24382439
done_index = folio->index;
24392440

@@ -2471,6 +2472,7 @@ int write_cache_pages(struct address_space *mapping,
24712472

24722473
trace_wbc_writepage(wbc, inode_to_bdi(mapping->host));
24732474
error = writepage(folio, wbc, data);
2475+
nr = folio_nr_pages(folio);
24742476
if (unlikely(error)) {
24752477
/*
24762478
* Handle errors according to the type of
@@ -2489,8 +2491,7 @@ int write_cache_pages(struct address_space *mapping,
24892491
error = 0;
24902492
} else if (wbc->sync_mode != WB_SYNC_ALL) {
24912493
ret = error;
2492-
done_index = folio->index +
2493-
folio_nr_pages(folio);
2494+
done_index = folio->index + nr;
24942495
done = 1;
24952496
break;
24962497
}
@@ -2504,7 +2505,8 @@ int write_cache_pages(struct address_space *mapping,
25042505
* keep going until we have written all the pages
25052506
* we tagged for writeback prior to entering this loop.
25062507
*/
2507-
if (--wbc->nr_to_write <= 0 &&
2508+
wbc->nr_to_write -= nr;
2509+
if (wbc->nr_to_write <= 0 &&
25082510
wbc->sync_mode == WB_SYNC_NONE) {
25092511
done = 1;
25102512
break;

0 commit comments

Comments
 (0)