Move the code in __filemap_get_folio_mpol() that clears PG_dropbehind on a folio found by a cached lookup, and takes the folio off WB_DONTCACHE_DIRTY, into filemap_clear_dropbehind(). No functional change. The next patch changes the helper. Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Signed-off-by: Mike Snitzer --- mm/filemap.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 3bf31cc9d2709..0e7b02d5abb60 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1956,6 +1956,24 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index) return folio; } +/* Clear the dropbehind flag of a folio that a cached lookup found. */ +static void filemap_clear_dropbehind(struct address_space *mapping, + struct folio *folio) +{ + if (!folio_test_clear_dropbehind(folio)) + return; + if (folio_test_dirty(folio) && mapping_can_writeback(mapping)) { + struct inode *inode = mapping->host; + struct bdi_writeback *wb; + struct wb_lock_cookie cookie = {}; + long nr = folio_nr_pages(folio); + + wb = unlocked_inode_to_wb_begin(inode, &cookie); + wb_stat_mod(wb, WB_DONTCACHE_DIRTY, -nr); + unlocked_inode_to_wb_end(inode, &cookie); + } +} + /** * __filemap_get_folio_mpol - Find and get a reference to a folio. * @mapping: The address_space to search. @@ -2087,19 +2105,8 @@ struct folio *__filemap_get_folio_mpol(struct address_space *mapping, if (!folio) return ERR_PTR(-ENOENT); /* not an uncached lookup, clear uncached if set */ - if (!(fgp_flags & FGP_DONTCACHE) && folio_test_clear_dropbehind(folio)) { - if (folio_test_dirty(folio) && - mapping_can_writeback(mapping)) { - struct inode *inode = mapping->host; - struct bdi_writeback *wb; - struct wb_lock_cookie cookie = {}; - long nr = folio_nr_pages(folio); - - wb = unlocked_inode_to_wb_begin(inode, &cookie); - wb_stat_mod(wb, WB_DONTCACHE_DIRTY, -nr); - unlocked_inode_to_wb_end(inode, &cookie); - } - } + if (!(fgp_flags & FGP_DONTCACHE)) + filemap_clear_dropbehind(mapping, folio); return folio; } EXPORT_SYMBOL(__filemap_get_folio_mpol); -- 2.52.0