52 lines
1.9 KiB
Diff
52 lines
1.9 KiB
Diff
From bc86aaf0e0256220ca787fdbb57a73429ade1129 Mon Sep 17 00:00:00 2001
|
|
From: Jens Axboe <axboe@kernel.dk>
|
|
Date: Tue, 27 May 2025 07:28:52 -0600
|
|
Subject: 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: stable@vger.kernel.org
|
|
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
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 <axboe@kernel.dk>
|
|
Link: https://lore.kernel.org/20250527133255.452431-2-axboe@kernel.dk
|
|
Signed-off-by: Christian Brauner <brauner@kernel.org>
|
|
---
|
|
mm/filemap.c | 13 +++++++++++--
|
|
1 file changed, 11 insertions(+), 2 deletions(-)
|
|
|
|
--- a/mm/filemap.c
|
|
+++ b/mm/filemap.c
|
|
@@ -1589,6 +1589,16 @@ int folio_wait_private_2_killable(struct
|
|
}
|
|
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(s
|
|
* 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);
|
|
}
|
|
}
|