Re: [PATCH 1/2] mm/huge_memory: use NOFS when allocating while splitting folios
From: Matthew Wilcox
Date: Mon Nov 23 2026 - 15:23:12 EST
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)
See this discussion:
https://lore.kernel.org/all/20200214065504.GK31689@xxxxxxxxxxxxxx/
which led to patch f2c817bed58d in June 2020.
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?