Re: [PATCH v10 2/6] mm: swap: associate swap devices with tiers

From: Youngjun Park

Date: Mon Jul 13 2026 - 11:52:47 EST


On Mon, Jul 13, 2026 at 07:28:53AM -0700, Usama Arif wrote:

> > #endif /* _SWAP_TIER_H */
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index ff567ad893a4..f3cff586cf30 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -3041,6 +3041,8 @@ static void _enable_swap_info(struct swap_info_struct *si)
> >
> > /* Add back to available list */
> > add_to_avail_list(si, true);
> > +
> > + swap_tiers_assign_dev(si);
>
> Could we move the assignment before the device is added to the active and
> available lists?
>
> After patch 4, swap allocation checks si->tier_mask while holding only
> swap_avail_lock. But here the new device is added to swap_avail_head
> before swap_tiers_assign_dev() initializes its mask.
>
> That creates a small window where reclaim can see this swap_info_struct
> with a stale tier_mask. swap_info_struct instances are reused across
> swapoff/swapon, so the stale mask can come from the previous device that
> occupied this slot. A memcg allowed to use the old tier could then
> temporarily allocate from the newly enabled device even if that device
> belongs to a different tier.

Hello Usama.
Thanks for the review!

Good catch! You're right.
the device becomes visible to swap_alloc_slow() the moment add_to_avail_list() drops swap_avail_lock,
before the mask is assigned.

Will move the assignment before the list insertions in v11.

Youngjun