Re: [PATCH 05/32] mm/shmem: don't pin inodes with eviction held off in the huge shrinker

From: Baolin Wang

Date: Wed Dec 02 2026 - 03:47:53 EST




On 11/29/26 6:06 PM, David Hildenbrand (Arm) wrote:
shmem_unuse() disallows eviction of an inode while swapping in its
pages, and shmem_evict_inode() waits until eviction is allowed again.

However, swapping in folios will end up allocating memory with __GFP_FS,
possibly triggering direct reclaim, where the superblock shrinkers can
drop the last reference to that very inode.

For example, shmem_unused_huge_shrink() takes and drops an inode reference
to split large folios beyond i_size:

swapoff another task
======= ============
shmem_unuse()
shmem_disallow_eviction()
shmem_swapin_folio()
direct reclaim
shmem_unused_huge_shrink()
igrab()
unlink(), close()
iput()
shmem_evict_inode()
waits for eviction to be allowed

Consequently, swapoff can deadlock against itself.

Let's fix it by not pinning inodes whose eviction is disallowed in
shmem_unused_huge_shrink(), effectively skipping them in this reclaim pass.
Within shmem, shmem_unused_huge_shrink() is the only place where reclaim
takes and drops a temporary reference to a shmem inode.

We could also avoid the deadlock by swapping in under NOFS scope in
shmem_unuse(). However, allocating a lot of folios under NOFS does not
sound like the right approach.

This has low urgency, as the race is hard to hit and swapoff is
privileged.

Fixes: af53d3e9e040 ("mm: swapoff: shmem_unuse() stop eviction without igrab()")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Chris Mason <mason@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---

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