Re: [RFC PATCH v4 18/18] mm/swap: redistribute queue readers after membership changes
From: Kairui Song
Date: Sun Nov 15 2026 - 22:30:39 EST
On Sat, Nov 14, 2026 at 10:53 PM Lian Wang <lianux.mm@xxxxxxxxx> wrote:
>
> Adding a device to an existing priority ring reuses the per-CPU reader
> storage. A ring that previously contained one device can therefore keep
> every CPU at the old common starting offset after peers are added.
> Deleting devices or rings can likewise leave offsets and quotas that
> describe the previous membership.
>
> Reset the valid per-CPU ring offsets and quotas after peer insertion and
> every nonempty deletion. Run the initialization helper under the topology
> writer, which excludes allocation walks, without allocating new reader
> storage or adding selector hot-path work.
>
> Use cpu-id modulo placement for a fresh best-effort rotation across all
> valid rings. This does not move existing slots or guarantee strict balance
> for every active CPU subset. Mask and availability transitions do not
> trigger the topology reset.
>
> Signed-off-by: Lian Wang <lianux.mm@xxxxxxxxx>
> ---
> mm/swapfile.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 0c192844b121..eb2128132455 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -497,6 +497,7 @@ static int swap_queue_add(struct swap_info_struct *si,
> spin_unlock(&swap_queue_update_lock);
> memalloc_noreclaim_restore(noreclaim_flag);
> kfree(old_ring);
> + swap_queue_reset_readers();
> return 0;
>
> failed:
> @@ -569,6 +570,8 @@ static void swap_queue_del(struct swap_info_struct *si)
> swap_queue_install_readers(NULL, 0);
> }
> spin_unlock(&swap_queue_update_lock);
> + if (swap_queue_len)
> + swap_queue_reset_readers();
>
> kfree(old_ring);
> kfree(old_queue);
>
Makes sense, thanks!
Reviewed-by: Kairui Song <kasong@xxxxxxxxxxx>