Re: [RFC PATCH v5 2/4] mm: distinguish large folio swap allocation failures
From: Barry Song
Date: Fri Aug 07 2026 - 19:12:47 EST
On Thu, Jul 30, 2026 at 8:23 PM Xueyuan Chen <xueyuan.chen21@xxxxxxxxx> wrote:
>
> folio_alloc_swap() reports most allocation failures with a generic
> negative error code. Reclaim cannot tell whether splitting a large folio
> could make progress or whether there is no backing space at all.
>
> Keep the global free swap count and the remaining hierarchical memcg swap
> margin as separate inputs. The memcg charge path reports only its own
> margin; folio_alloc_swap() combines the two layers when classifying an
> allocation failure.
>
> Return -E2BIG for large folios when a smaller allocation might still fit,
> -ENOSPC when no global swap space is available, and -ENOMEM when the
> failure is not helped by splitting.
>
> For early large-folio rejections, check global and memcg swap availability
> instead of returning -E2BIG unconditionally. On a memcg charge failure,
> swap slot allocation has already succeeded, so use the remaining memcg
> margin to decide whether a smaller charge might fit.
>
> This only refines folio_alloc_swap() return codes. The reclaim callers are
> updated separately.
>
[...]
> +
> +failed:
> + if (get_nr_swap_pages() <= 0)
> + return -ENOSPC;
I wonder if we can do this earlier when swap is full or disabled.
We could exit immediately and avoid trying many redundant paths.
Have you tried this?
> + if (swap_margin <= 0)
> + return -ENOMEM;
> +
> + return order ? -E2BIG : -ENOMEM;
Best Regards
Barry