Skip to content

Commit 095f627

Browse files
axboebrauner
authored andcommitted
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: fb7d3bc ("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]>
1 parent 015a99f commit 095f627

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mm/filemap.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,16 @@ int folio_wait_private_2_killable(struct folio *folio)
15891589
}
15901590
EXPORT_SYMBOL(folio_wait_private_2_killable);
15911591

1592+
static void filemap_end_dropbehind(struct folio *folio)
1593+
{
1594+
struct address_space *mapping = folio->mapping;
1595+
1596+
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
1597+
1598+
if (mapping && !folio_test_writeback(folio) && !folio_test_dirty(folio))
1599+
folio_unmap_invalidate(mapping, folio, 0);
1600+
}
1601+
15921602
/*
15931603
* If folio was marked as dropbehind, then pages should be dropped when writeback
15941604
* 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)
16041614
* invalidation in that case.
16051615
*/
16061616
if (in_task() && folio_trylock(folio)) {
1607-
if (folio->mapping)
1608-
folio_unmap_invalidate(folio->mapping, folio, 0);
1617+
filemap_end_dropbehind(folio);
16091618
folio_unlock(folio);
16101619
}
16111620
}

0 commit comments

Comments
 (0)