Skip to content

Commit

Permalink
mm/filemap: use filemap_end_dropbehind() for read invalidation
Browse files Browse the repository at this point in the history
commit 25b065a upstream.

Use the filemap_end_dropbehind() helper rather than calling
folio_unmap_invalidate() directly, as we need to check if the folio has
been redirtied or marked for writeback once the folio lock has been
re-acquired.

Cc: stable@vger.kernel.org
Reported-by: Trond Myklebust <trondmy@hammerspace.com>
Fixes: 8026e49 ("mm/filemap: add read support for RWF_DONTCACHE")
Link: https://lore.kernel.org/linux-fsdevel/ba8a9805331ce258a622feaca266b163db681a10.camel@hammerspace.com/
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/20250527133255.452431-3-axboe@kernel.dk
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jens Axboe authored and Greg Kroah-Hartman committed Jun 19, 2025
1 parent 0a471b2 commit 411bf2a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2644,16 +2644,15 @@ static inline bool pos_same_folio(loff_t pos1, loff_t pos2, struct folio *folio)
return (pos1 >> shift == pos2 >> shift);
}

static void filemap_end_dropbehind_read(struct address_space *mapping,
struct folio *folio)
static void filemap_end_dropbehind_read(struct folio *folio)
{
if (!folio_test_dropbehind(folio))
return;
if (folio_test_writeback(folio) || folio_test_dirty(folio))
return;
if (folio_trylock(folio)) {
if (folio_test_clear_dropbehind(folio))
folio_unmap_invalidate(mapping, folio, 0);
filemap_end_dropbehind(folio);
folio_unlock(folio);
}
}
Expand Down Expand Up @@ -2774,7 +2773,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
for (i = 0; i < folio_batch_count(&fbatch); i++) {
struct folio *folio = fbatch.folios[i];

filemap_end_dropbehind_read(mapping, folio);
filemap_end_dropbehind_read(folio);
folio_put(folio);
}
folio_batch_init(&fbatch);
Expand Down

0 comments on commit 411bf2a

Please sign in to comment.