afs: Fix page leak
authorDavid Howells <dhowells@redhat.com>
Wed, 1 Sep 2021 08:15:21 +0000 (09:15 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 10 Sep 2021 21:14:51 +0000 (22:14 +0100)
commit581b2027af0018944ba301d68e7af45c6d1128b5
tree1e49e0a6e41930ad1f8a6b5c9a25ea105bdec82c
parent345e1ae0c6ba54f6a4d32154e80cadc2ee2ef1af
afs: Fix page leak

There's a loop in afs_extend_writeback() that adds extra pages to a write
we want to make to improve the efficiency of the writeback by making it
larger.  This loop stops, however, if we hit a page we can't write back
from immediately, but it doesn't get rid of the page ref we speculatively
acquired.

This was caused by the removal of the cleanup loop when the code switched
from using find_get_pages_contig() to xarray scanning as the latter only
gets a single page at a time, not a batch.

Fix this by putting the page on a ref on an early break from the loop.
Unfortunately, we can't just add that page to the pagevec we're employing
as we'll go through that and add those pages to the RPC call.

This was found by the generic/074 test.  It leaks ~4GiB of RAM each time it
is run - which can be observed with "top".

Fixes: e87b03f5830e ("afs: Prepare for use of THPs")
Reported-by: Marc Dionne <marc.dionne@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-and-tested-by: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/163111666635.283156.177701903478910460.stgit@warthog.procyon.org.uk/
fs/afs/write.c