Re: [PATCH 1/2] mm/huge_memory: use NOFS when allocating while splitting folios

From: Baolin Wang

Date: Mon Nov 23 2026 - 03:20:12 EST




On 11/22/26 8:42 PM, 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>
---

Make sense.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>