Re: [PATCH 1/2] mm/huge_memory: use NOFS when allocating while splitting folios
From: Barry Song
Date: Sun Nov 22 2026 - 20:14:41 EST
On Mon, Nov 23, 2026 at 2:46 AM Gregory Price (Meta) <gourry@xxxxxxxxxx> wrote:
>
> On 2026-11-22 13:42 +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)
> >
> > This requires that nothing else holds a reference on the inode, and can
> > be triggered most easily with FUSE, which evicts inodes on the last
> > reference.
> >
> > Further, xas_split_alloc() charges the XArray nodes to the memcg, and on
> > cgroup v1, memcg reclaim waits for file folios under writeback if
> > __GFP_FS is set. That can deadlock if writeback waits for a folio lock
> > that we hold, for example with ext4.
> >
> > Let's fix it by splitting folios in a NOFS scope, so callers don't have
> > to care. A NOFS scope also covers allocations that filesystems make with
> > their own gfp flags, for example in filemap_release_folio().
> >
> > On NFS, splitting folios with pending writes or ongoing writes to
> > fscache might now fail slightly more often, until these writes have
> > completed. On netfs, only folios that are being written to fscache are
> > affected. All fairly irrelevant.
> >
> > This has medium urgency.
> >
> > Fixes: 6b24ca4a1a8d ("mm: Use multi-index entries in the page cache")
> > Fixes: eef88fe45ac9 ("s390/uv: Split large folios in gmap_make_secure()")
> > Fixes: 789763523fb4 ("xarray: honor XA_FLAGS_ACCOUNT in xas_split_alloc()")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Reported-by: Chris Mason <mason@xxxxxxxxxx>
> > Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> Reproduced the hang determnistically.
> Base deadlocked.
> With patch 1: -ENOMEM (safe)
Hi Gregory,
Just curious how those -ENOMEM failures occur. With GFP_NOFS, we
should still be able to reclaim anonymous folios (except in
SWAP_OPS_F_REQUIRE_NOFS cases) and clean page cache folios, right?
> With patch 2: split succeeds
>
> Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
>
+1 for the patch itself.
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>
Thanks,
Barry