[PATCH 0/2] mm: fix deadlock on the folio lock due to inode eviction

From: David Hildenbrand (Arm)

Date: Sun Nov 22 2026 - 07:42:44 EST


Whenever we allocate memory with folio locks held and trigger direct
reclaim, we might end up trying to evict an unused inode. Evicting
inodes with a populated page cache takes folio locks, and if we happen
to need one of the folio locks we already hold, we'll deadlock.

This can, in general, not happen if we also pin the folio's inode: for
example, through a VMA that cannot go away concurrently. However, we
have some scenarios where we hold folio locks without pinning inodes.
Examples include page migration and some folio split users.

FUSE makes this easier to trigger, because it evicts inodes on the last
reference. A similar deadlock with FUSE was recently fixed in FUSE [1].

Let's handle folio splitting by simply running in NOFS context. We only
perform small allocations, so it doesn't really make a difference.
Interestingly, this also fixes one of a handful of possible memcg v1
deadlocks.

For page migration, change the code to allocate destination folios
without holding folio locks, which is in any case the right thing to do
to reduce folio lock holding times.

Some of this might also be fixable using Jan's work on deferred inode
reclaim [2]. However, that is not stable material, and not allocating
folios while holding other folio locks is an improvement on its own.

Unprivileged users can trigger this deadlock with FUSE and
mbind()/migrate_pages(), however, it requires multiple NUMA nodes and
quite some luck.

I reproduced the original deadlocks with FUSE and made sure they can no
longer be triggered with these fixes. Further, I ran the usual migration
and folio splitting selftests.

[1] https://lore.kernel.org/all/20250925224404.2058035-1-joannelkoong@xxxxxxxxx/
[2] https://lore.kernel.org/all/20261009133253.20102-1-jack@xxxxxxx/

Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
David Hildenbrand (Arm) (2):
mm/huge_memory: use NOFS when allocating while splitting folios
mm/migrate: allocate destination folios before locking a batch

mm/huge_memory.c | 10 +++++
mm/migrate.c | 134 ++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 107 insertions(+), 37 deletions(-)
---
base-commit: eb01811cc3713af1f78dfe18fa89c5270ebfc767
change-id: 20261121-migrate_reclaim_deadlock-44e28e226b9d

Best regards,
--
David Hildenbrand (Arm) <david@xxxxxxxxxx>