Re: [PATCH 13/16] mm/shmem: preserve allocation errors when swapping in large entries
From: Kiryl Shutsemau
Date: Mon Oct 26 2026 - 13:50:51 EST
On Mon, Oct 26, 2026 at 10:40:46AM +0100, David Hildenbrand (Arm) wrote:
> shmem_swapin_folio() adjusts swap to the requested slot within a large
> swap entry before allocating a folio. If allocation or charging fails,
> the error path compares this adjusted value with the original entry
> still stored in the XArray in shmem_confirm_swap().
>
> Unless the index is at the start of the entry, this turns -ENOMEM into
> -EEXIST even though nothing changed.
>
> The caller retries -EEXIST, so persistent allocation failures can leave
> the task spinning instead of returning the error.
>
> Restore swap to index_entry on allocation failure so the existing error
> path checks the original entry. This preserves the allocation error if
> the entry is unchanged and still retries if it changed concurrently.
>
> Original fix generated by an LLM and sent by Josef Bacik in private.
>
> Fixes: 91ab656ece13 ("mm/shmem, swap: tidy up swap entry splitting")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Acked-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
--
Kiryl Shutsemau / Kirill A. Shutemov