79 lines
2.5 KiB
Diff
79 lines
2.5 KiB
Diff
From 6003153e1bc4ad4952773081d7b89aa1ab2274c3 Mon Sep 17 00:00:00 2001
|
|
From: Jens Axboe <axboe@kernel.dk>
|
|
Date: Tue, 27 May 2025 07:28:56 -0600
|
|
Subject: mm/filemap: unify dropbehind flag testing and clearing
|
|
|
|
The read and write side does this a bit differently, unify it such that
|
|
the _{read,write} helpers check the bit before locking, and the generic
|
|
handler is in charge of clearing the bit and invalidating, once under
|
|
the folio lock.
|
|
|
|
Signed-off-by: Jens Axboe <axboe@kernel.dk>
|
|
Link: https://lore.kernel.org/20250527133255.452431-6-axboe@kernel.dk
|
|
Signed-off-by: Christian Brauner <brauner@kernel.org>
|
|
---
|
|
mm/filemap.c | 21 +++++++++++----------
|
|
1 file changed, 11 insertions(+), 10 deletions(-)
|
|
|
|
--- a/mm/filemap.c
|
|
+++ b/mm/filemap.c
|
|
@@ -1595,7 +1595,11 @@ static void filemap_end_dropbehind(struc
|
|
|
|
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
|
|
|
|
- if (mapping && !folio_test_writeback(folio) && !folio_test_dirty(folio))
|
|
+ if (folio_test_writeback(folio) || folio_test_dirty(folio))
|
|
+ return;
|
|
+ if (!folio_test_clear_dropbehind(folio))
|
|
+ return;
|
|
+ if (mapping)
|
|
folio_unmap_invalidate(mapping, folio, 0);
|
|
}
|
|
|
|
@@ -1606,6 +1610,9 @@ static void filemap_end_dropbehind(struc
|
|
*/
|
|
static void filemap_end_dropbehind_write(struct folio *folio)
|
|
{
|
|
+ if (!folio_test_dropbehind(folio))
|
|
+ return;
|
|
+
|
|
/*
|
|
* Hitting !in_task() should not happen off RWF_DONTCACHE writeback,
|
|
* but can happen if normal writeback just happens to find dirty folios
|
|
@@ -1629,8 +1636,6 @@ static void filemap_end_dropbehind_write
|
|
*/
|
|
void folio_end_writeback(struct folio *folio)
|
|
{
|
|
- bool folio_dropbehind = false;
|
|
-
|
|
VM_BUG_ON_FOLIO(!folio_test_writeback(folio), folio);
|
|
|
|
/*
|
|
@@ -1652,14 +1657,11 @@ void folio_end_writeback(struct folio *f
|
|
* reused before the folio_wake_bit().
|
|
*/
|
|
folio_get(folio);
|
|
- if (!folio_test_dirty(folio))
|
|
- folio_dropbehind = folio_test_clear_dropbehind(folio);
|
|
if (__folio_end_writeback(folio))
|
|
folio_wake_bit(folio, PG_writeback);
|
|
- acct_reclaim_writeback(folio);
|
|
|
|
- if (folio_dropbehind)
|
|
- filemap_end_dropbehind_write(folio);
|
|
+ filemap_end_dropbehind_write(folio);
|
|
+ acct_reclaim_writeback(folio);
|
|
folio_put(folio);
|
|
}
|
|
EXPORT_SYMBOL(folio_end_writeback);
|
|
@@ -2651,8 +2653,7 @@ static void filemap_end_dropbehind_read(
|
|
if (folio_test_writeback(folio) || folio_test_dirty(folio))
|
|
return;
|
|
if (folio_trylock(folio)) {
|
|
- if (folio_test_clear_dropbehind(folio))
|
|
- filemap_end_dropbehind(folio);
|
|
+ filemap_end_dropbehind(folio);
|
|
folio_unlock(folio);
|
|
}
|
|
}
|