
From: Jens Axboe <axboe@kernel.dk> mainline inclusion from mainline-v6.15 commit a1d98e4ffb972ab007f5de850ef53c2a46cacf15 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICPOEB CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- 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> Conflicts: mm/filemap.c [Context conflicts] Signed-off-by: Long Li <leo.lilong@huawei.com> --- mm/filemap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 3626330d9d94..cca581bcd302 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1617,7 +1617,11 @@ static void filemap_end_dropbehind(struct folio *folio) 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); } @@ -1628,6 +1632,9 @@ static void filemap_end_dropbehind(struct folio *folio) */ 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 @@ -1647,8 +1654,6 @@ static void filemap_end_dropbehind_write(struct folio *folio) */ void folio_end_writeback(struct folio *folio) { - bool folio_dropbehind = false; - /* * folio_test_clear_reclaim() could be used here but it is an * atomic operation and overkill in this particular case. Failing @@ -1668,17 +1673,13 @@ void folio_end_writeback(struct folio *folio) * reused before the folio_wake(). */ folio_get(folio); - if (!folio_test_dirty(folio)) - folio_dropbehind = folio_test_clear_dropbehind(folio); if (!__folio_end_writeback(folio)) BUG(); smp_mb__after_atomic(); folio_wake(folio, PG_writeback); + filemap_end_dropbehind_write(folio); acct_reclaim_writeback(folio); - - if (folio_dropbehind) - filemap_end_dropbehind_write(folio); folio_put(folio); } EXPORT_SYMBOL(folio_end_writeback); @@ -2691,8 +2692,7 @@ static void filemap_end_dropbehind_read(struct folio *folio) 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); } } -- 2.39.2