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

Youngjun Park <[email protected]>
Newsgroups org.kernel.vger.cgroups,org.kernel.vger.linux-kernel
Message-ID <alUCTVQSVH/gPbjo@yjaykim-PowerEdge-T330>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.