Re: [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 - 04:50:21 EST
On 11/24/26 08:56, David Hildenbrand (Arm) wrote:
> 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.
@Jose, could you find and fix other cases where we allocate under the folio lock
with __GFP_FS (and direct reclaim enabled?).
I think at least do_set_pmd() might have a problem when allocating a page table
through pte_alloc_one(). And I'm sure there's more.
--
Cheers,
David