Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mm, netfs, fscache: stop read optimisation when folio removed from pa…
…gecache Fscache has an optimisation by which reads from the cache are skipped until we know that (a) there's data there to be read and (b) that data isn't entirely covered by pages resident in the netfs pagecache. This is done with two flags manipulated by fscache_note_page_release(): if (... test_bit(FSCACHE_COOKIE_HAVE_DATA, &cookie->flags) && test_bit(FSCACHE_COOKIE_NO_DATA_TO_READ, &cookie->flags)) clear_bit(FSCACHE_COOKIE_NO_DATA_TO_READ, &cookie->flags); where the NO_DATA_TO_READ flag causes cachefiles_prepare_read() to indicate that netfslib should download from the server or clear the page instead. The fscache_note_page_release() function is intended to be called from ->releasepage() - but that only gets called if PG_private or PG_private_2 is set - and currently the former is at the discretion of the network filesystem and the latter is only set whilst a page is being written to the cache, so sometimes we miss clearing the optimisation. Fix this by following Willy's suggestion[1] and adding an address_space flag, AS_RELEASE_ALWAYS, that causes filemap_release_folio() to always call ->release_folio() if it's set, even if PG_private or PG_private_2 aren't set. Note that this would require folio_test_private() and page_has_private() to become more complicated. To avoid that, in the places[*] where these are used to conditionalise calls to filemap_release_folio() and try_to_release_page(), the tests are removed the those functions just jumped to unconditionally and the test is performed there. [*] There are some exceptions in vmscan.c where the check guards more than just a call to the releaser. I've added a function, folio_needs_release() to wrap all the checks for that. AS_RELEASE_ALWAYS should be set if a non-NULL cookie is obtained from fscache and cleared in ->evict_inode() before truncate_inode_pages_final() is called. Additionally, the FSCACHE_COOKIE_NO_DATA_TO_READ flag needs to be cleared and the optimisation cancelled if a cachefiles object already contains data when we open it. [[email protected]: call folio_mapping() inside folio_needs_release()] Link: DaveWysochanskiRH/kernel@902c990 Link: https://lkml.kernel.org/r/[email protected] Fixes: 1f67e6d ("fscache: Provide a function to note the release of a page") Fixes: 047487c ("cachefiles: Implement the I/O routines") Signed-off-by: David Howells <[email protected]> Signed-off-by: Dave Wysochanski <[email protected]> Reported-by: Rohith Surabattula <[email protected]> Suggested-by: Matthew Wilcox <[email protected]> Tested-by: SeongJae Park <[email protected]> Cc: Daire Byrne <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Steve French <[email protected]> Cc: Shyam Prasad N <[email protected]> Cc: Rohith Surabattula <[email protected]> Cc: Dave Wysochanski <[email protected]> Cc: Dominique Martinet <[email protected]> Cc: Ilya Dryomov <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Jingbo Xu <[email protected]> Cc: "Theodore Ts'o" <[email protected]> Cc: Xiubo Li <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
- Loading branch information