From: Jens Axboe <axboe@kernel.dk>
To: linux-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, djwong@kernel.org, brauner@kernel.org,
torvalds@linux-foundation.org, trondmy@hammerspace.com,
Jens Axboe <axboe@kernel.dk>,
stable@vger.kernel.org
Subject: [PATCH 1/5] mm/filemap: gate dropbehind invalidate on folio !dirty && !writeback
Date: Tue, 27 May 2025 07:28:52 -0600 [thread overview]
Message-ID: <20250527133255.452431-2-axboe@kernel.dk> (raw)
In-Reply-To: <20250527133255.452431-1-axboe@kernel.dk>
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>
---
mm/filemap.c | 13 +++++++++++--
1 file 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);
}
}
--
2.49.0
next prev parent reply other threads:[~2025-05-27 13:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 13:28 [PATCHSET 0/5] dropbehind fixes and cleanups Jens Axboe
2025-05-27 13:28 ` Jens Axboe [this message]
2025-05-28 8:12 ` [PATCH 1/5] mm/filemap: gate dropbehind invalidate on folio !dirty && !writeback Christoph Hellwig
2025-05-27 13:28 ` [PATCH 2/5] mm/filemap: use filemap_end_dropbehind() for read invalidation Jens Axboe
2025-05-28 8:13 ` Christoph Hellwig
2025-05-27 13:28 ` [PATCH 3/5] Revert "Disable FOP_DONTCACHE for now due to bugs" Jens Axboe
2025-05-28 8:14 ` Christoph Hellwig
2025-05-27 13:28 ` [PATCH 4/5] mm/filemap: unify read/write dropbehind naming Jens Axboe
2025-05-28 8:14 ` Christoph Hellwig
2025-05-27 13:28 ` [PATCH 5/5] mm/filemap: unify dropbehind flag testing and clearing Jens Axboe
2025-05-28 8:15 ` Christoph Hellwig
2025-05-27 19:10 ` [PATCHSET 0/5] dropbehind fixes and cleanups Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250527133255.452431-2-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=trondmy@hammerspace.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).