Re: [PATCH 1/2] mm/huge_memory: use NOFS when allocating while splitting folios
From: David Hildenbrand (Arm)
Date: Mon Nov 23 2026 - 15:45:06 EST
On 11/23/26 21:22, Matthew Wilcox wrote:
> On Sun, Nov 22, 2026 at 01:42:17PM +0100, David Hildenbrand (Arm) wrote:
>> Various callers (migration, memory-failure, s390_wiggle_split_folio) split
>> locked folios without holding a reference on the folio's inode.
>>
>> Splitting a file folio might allocate memory for the xarray and call
>> filemap_release_folio(). If either ends up in direct reclaim with
>> __GFP_FS, reclaim can evict the inode through the dcache shrinker, and
>> wait in truncate_inode_pages_final() for the folio that we hold locked:
>>
>> try_split_folio()
>> folio_lock(A)
>> split_folio_to_list(A)
>> xas_split_alloc()
>> try_to_free_pages()
>> super_cache_scan()
>> prune_dcache_sb()
>> iput_final()
>> evict()
>> truncate_inode_pages_final()
>> folio_lock(A)
>
> The "holding a reference to the inode" piece is a red herring. We can
> deadlock even without it (although maybe the AI can't see it). If we
> don't remove __GFP_FS, we can hit this path:
>
> folio_lock(A)
> kmalloc
> alloc_pages
> try_to_compact_pages
> compact_zone_order
> compact_zone(MIGRATE_SYNC_LIGHT)
> migrate_pages
> migrate_pages_sync
> migrate_pages_batch
> try_split_folio
> folio_lock(A)
Quite nasty, thanks for these details. I was aware that memcg v1 would run into
deadlocks whenever we would perform a charged allocation, but sync compaction
triggering it is even worse.
>
> See this discussion:
> https://lore.kernel.org/all/20200214065504.GK31689@xxxxxxxxxxxxxx/
> which led to patch f2c817bed58d in June 2020.
Thanks for the pointer.
>
> So yes, anywhere we're allocating memory with a file folio locked, we
> should enter nofs scope. Perhaps we can teach the AI that rule?
I have a couple of reports here regarding memcg v1 deadlocks, so it's not
completely aware of the issues yet.
We should document the rules of what you can or can't do while holding the folio
lock somewhere, yes!
--
Cheers,
David