Re: [RFC PATCH v5 2/4] mm: distinguish large folio swap allocation failures
Xueyuan Chen <[email protected]>
| Newsgroups | org.kernel.vger.cgroups,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <CA+qSx6w_EY23GzgfaypXz5pd=h9JoBjiyX5+4Po487QYb4R=aQ@mail.gmail.com> |
On Sat, Aug 8, 2026 at 7:12 AM Barry Song <[email protected]> wrote: > > On Thu, Jul 30, 2026 at 8:23 PM Xueyuan Chen <[email protected]> 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? > Hi Barry, Regarding moving the check earlier, I currently have two concerns: 1. It would add an extra get_nr_swap_pages() atomic read to every successful allocation path. 2. If the failure-time check is removed, the earlier snapshot could become stale while the allocation is attempted. The failure path could then return -E2BIG even if global swap has since been exhausted. Thanks, Xueyuan > > + if (swap_margin <= 0) > > + return -ENOMEM; > > + > > + return order ? -E2BIG : -ENOMEM; > > Best Regards > Barry