[PATCH v2 0/2] mm: fix deadlock on the folio lock when migrating and splitting folios
From: David Hildenbrand (Arm)
Date: Tue Nov 24 2026 - 02:56:58 EST
Whenever we allocate memory with __GFP_FS while holding folio locks, we
can deadlock on the folio lock when triggering direct reclaim or
compaction.
For example, 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.
FUSE makes this example 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>
---
Changes in v2:
- Adjust cover letter (incl. subject), the patch descriptions and code
comments: allocating with __GFP_FS while holding folio locks can
deadlock also through compaction, independent of inode references
- Collect tags
- Link to v1: https://patch.msgid.link/20261122-migrate_reclaim_deadlock-v1-0-83c56185b0fb@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 | 133 +++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 106 insertions(+), 37 deletions(-)
---
base-commit: eb01811cc3713af1f78dfe18fa89c5270ebfc767
change-id: 20261121-migrate_reclaim_deadlock-44e28e226b9d
Best regards,
--
David Hildenbrand (Arm) <david@xxxxxxxxxx>