Re: [PATCH 05/32] mm/shmem: don't pin inodes with eviction held off in the huge shrinker
From: Gregory Price (Meta)
Date: Wed Dec 02 2026 - 16:29:24 EST
On 2026-11-29 11:06 +0100, 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>
I was able to produce the condition where the inode was grabbed /
eviction stopping - but i could not produce the actual deadlock.
regardless, the change looks reasonable and avoiding the grab seems
correct either way.
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory