Re: [PATCH 2/2] mm/swap: publish cluster tables after reacquiring allocator locks

From: Nhat Pham

Date: Mon Nov 09 2026 - 12:08:15 EST


On Sat, Nov 7, 2026 at 11:03 AM Kairui Song <ryncsn@xxxxxxxxx> wrote:
>
> On Sat, Nov 7, 2026 at 3:59 AM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> >
> > On Fri, Nov 6, 2026 at 9:04 AM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> > >
> > > Under memory pressure, swap_cluster_populate() can publish a table
> > > while its locks are dropped for a sleeping allocation. A cached
> > > allocator can consume and free that table before the populating
> > > allocator resumes, leaving the resumed scan with a NULL table.
> > >
> > > CPU0 CPU1
> > > swap_cluster_populate()
> > > drop local/global/ci locks
> > > allocate and publish table
> > > swap_alloc_fast()
> > > consume the table
> > > charge failure cleanup
> > > free the table
> > > reacquire local/global/ci
> > > return ci
> > > alloc_swap_scan_cluster()
> > > read the missing table
> > >
> > > Keep the count table, cgroup table and zero bitmap private until
> > > swap_cluster_alloc_table() restores all allocator locks. Install them
> > > under the cluster lock and retain it through the scan. Initial bad-slot
> > > setup takes only the cluster lock because the device is unpublished.
> > >
> > > A stale reclaimer can return the isolated cluster to allocation while
> > > its locks are dropped. Abandon installation if the list state changes or
> > > a table appears, freeing only private allocations. Restore locks on
> > > allocation failure too, so the caller can return a still-isolated
> > > cluster to its free list.
> > >
> > > Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> > > Link: https://lore.kernel.org/all/sashiko-outbox-181084@xxxxxxxxxx/
> > > Link: https://lore.kernel.org/all/sashiko-outbox-181086@xxxxxxxxxx/
> > > Co-developed-by: Kairui Song <ryncsn@xxxxxxxxx>
> >
> > I think I need a
> >
> > Signed-off-by: Kairui Song <ryncsn@xxxxxxxxx>
> >
> > here as well...
> >
> > (Kairui - up to you if you feel like Co-developed-by + Signed-off-by
> > or Suggested-by + Acked-by is more appropriate here. I just filled in
> > the sketch you gave me.)
>
> Let's go with Suggested-by then :), I didn't even check if that sketch
> actually works, so thanks for taking care of that!

Okie dokie - will update that in v2. Sashiko picked out another issue,
so I'll use this opportunity to fix it too :)

If something sticks out as obviously wrong to you though please let me know!