[PATCH RFC 3/5] mm/vmscan: avoid releasing FS metadata for !FOLL_PIN gup folios

From: Pedro Falcato

Date: Thu Nov 19 2026 - 15:12:00 EST


The check added in commit d824ec2a1546
("mm: do not reclaim private data from pinned page")
is correct. However, it only handles pages pinned for DMA, using
pin_user_pages(). It completely skips any other get_user_pages() user,
that does not pass FOLL_PIN.

Replace the folio_maybe_dma_pinned() check with
filemap_may_release_folio().

Reported-by: David Hildenbrand <david@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Fixes: d824ec2a1546 ("mm: do not reclaim private data from pinned page")
Signed-off-by: Pedro Falcato <pfalcato@xxxxxxx>
---
mm/vmscan.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a1af9b92349..d80bbb607a15 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1464,16 +1464,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
}
}

- /*
- * Folio is unmapped now so it cannot be newly pinned anymore.
- * No point in trying to reclaim folio if it is pinned.
- * Furthermore we don't want to reclaim underlying fs metadata
- * if the folio is pinned and thus potentially modified by the
- * pinning process as that may upset the filesystem.
- */
- if (folio_maybe_dma_pinned(folio))
- goto activate_locked;
-
mapping = folio_mapping(folio);
if (folio_test_dirty(folio)) {
if (folio_is_file_lru(folio)) {
@@ -1566,7 +1556,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
* the folio on the LRU so it is swappable.
*/
if (folio_needs_release(folio)) {
- if (!filemap_release_folio(folio, sc->gfp_mask))
+ if (!filemap_may_release_folio(folio, 1) ||
+ !filemap_release_folio(folio, sc->gfp_mask))
goto activate_locked;
if (!mapping && folio_ref_count(folio) == 1) {
folio_unlock(folio);

--
2.56.1