diff options
| author | Jens Axboe <[email protected]> | 2025-05-27 13:28:52 +0000 |
|---|---|---|
| committer | Christian Brauner <[email protected]> | 2025-05-27 19:06:24 +0000 |
| commit | 095f627add86a6ddda2c2cfd563b0ee05d0172b2 (patch) | |
| tree | d8d21d57e987bffd142297322a2e234ab9f4072c /mm/filemap.c | |
| parent | Merge tag 'nolibc-20250526-for-6.16-1' of git://git.kernel.org/pub/scm/linux/... (diff) | |
| download | kernel-095f627add86a6ddda2c2cfd563b0ee05d0172b2.tar.gz kernel-095f627add86a6ddda2c2cfd563b0ee05d0172b2.zip | |
mm/filemap: gate dropbehind invalidate on folio !dirty && !writeback
It's possible for the folio to either get marked for writeback or
redirtied. Add a helper, filemap_end_dropbehind(), which guards the
folio_unmap_invalidate() call behind check for the folio being both
non-dirty and not under writeback AFTER the folio lock has been
acquired. Use this helper folio_end_dropbehind_write().
Cc: [email protected]
Reported-by: Al Viro <[email protected]>
Fixes: fb7d3bc41493 ("mm/filemap: drop streaming/uncached pages when writeback completes")
Link: https://lore.kernel.org/linux-fsdevel/20250525083209.GS2023217@ZenIV/
Signed-off-by: Jens Axboe <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Christian Brauner <[email protected]>
Diffstat (limited to 'mm/filemap.c')
| -rw-r--r-- | mm/filemap.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/mm/filemap.c b/mm/filemap.c index 7b90cbeb4a1a..008a55290f34 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1589,6 +1589,16 @@ int folio_wait_private_2_killable(struct folio *folio) } EXPORT_SYMBOL(folio_wait_private_2_killable); +static void filemap_end_dropbehind(struct folio *folio) +{ + struct address_space *mapping = folio->mapping; + + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + + if (mapping && !folio_test_writeback(folio) && !folio_test_dirty(folio)) + folio_unmap_invalidate(mapping, folio, 0); +} + /* * If folio was marked as dropbehind, then pages should be dropped when writeback * completes. Do that now. If we fail, it's likely because of a big folio - @@ -1604,8 +1614,7 @@ static void folio_end_dropbehind_write(struct folio *folio) * invalidation in that case. */ if (in_task() && folio_trylock(folio)) { - if (folio->mapping) - folio_unmap_invalidate(folio->mapping, folio, 0); + filemap_end_dropbehind(folio); folio_unlock(folio); } } |
