Skip to content

Commit 173ce1c

Browse files
dhowellstorvalds
authored andcommitted
afs: Fix potential thrashing in afs writeback
In afs_writepages_region(), if the dirty page we find is undergoing writeback or write to cache, but the sync_mode is WB_SYNC_NONE, we go round the loop trying the same page again and again with no pausing or waiting unless and until another thread manages to clear the writeback and fscache flags. Fix this with three measures: (1) Advance start to after the page we found. (2) Break out of the loop and return if rescheduling is requested. (3) Arbitrarily give up after a maximum of 5 skips. Fixes: 31143d5 ("AFS: implement basic file write support") Reported-by: Marc Dionne <marc.dionne@auristor.com> Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Marc Dionne <marc.dionne@auristor.com> Acked-by: Marc Dionne <marc.dionne@auristor.com> Link: https://lore.kernel.org/r/164692725757.2097000.2060513769492301854.stgit@warthog.procyon.org.uk/ # v1 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4edc076 commit 173ce1c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

fs/afs/write.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static int afs_writepages_region(struct address_space *mapping,
703703
struct folio *folio;
704704
struct page *head_page;
705705
ssize_t ret;
706-
int n;
706+
int n, skips = 0;
707707

708708
_enter("%llx,%llx,", start, end);
709709

@@ -754,8 +754,15 @@ static int afs_writepages_region(struct address_space *mapping,
754754
#ifdef CONFIG_AFS_FSCACHE
755755
folio_wait_fscache(folio);
756756
#endif
757+
} else {
758+
start += folio_size(folio);
757759
}
758760
folio_put(folio);
761+
if (wbc->sync_mode == WB_SYNC_NONE) {
762+
if (skips >= 5 || need_resched())
763+
break;
764+
skips++;
765+
}
759766
continue;
760767
}
761768

0 commit comments

Comments
 (0)