mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm: fix deadlock on the folio lock when migrating and splitting folios
@ 2026-11-24  7:56 David Hildenbrand (Arm)
  2026-11-24  7:56 ` [PATCH v2 1/2] mm/huge_memory: use NOFS when allocating while " David Hildenbrand (Arm)
  2026-11-24  7:56 ` [PATCH v2 2/2] mm/migrate: allocate destination folios before locking a batch David Hildenbrand (Arm)
  0 siblings, 2 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-24  7:56 UTC (permalink / raw)
  To: Zi Yan, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts,
	Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau,
	Andrew Morton, Matthew Wilcox (Oracle),
	William Kucharski, Heiko Carstens, Alexander Gordeev,
	Claudio Imbrenda, Johannes Weiner, Lorenzo Stoakes (ARM),
	Matthew Brost, Joshua Hahn, Byungchul Park, Gregory Price,
	Ying Huang, Alistair Popple, Christian Brauner, Jan Kara,
	Miklos Szeredi, Joanne Koong
  Cc: linux-mm, linux-kernel, linux-fsdevel, David Hildenbrand (Arm),
	stable, Chris Mason, Jose A. Perez de Azpillaga, Chris Down

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@gmail.com/
[2] https://lore.kernel.org/all/20261009133253.20102-1-jack@suse.cz/

Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
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@kernel.org

---
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@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24  7:56 [PATCH v2 0/2] mm: fix deadlock on the folio lock when migrating and splitting folios David Hildenbrand (Arm)
2026-11-24  7:56 ` [PATCH v2 1/2] mm/huge_memory: use NOFS when allocating while " David Hildenbrand (Arm)
2026-11-24  7:56 ` [PATCH v2 2/2] mm/migrate: allocate destination folios before locking a batch David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®