Re: [RFC PATCH v4 17/18] mm/swap: skip reader rotation for single-device priority rings
From: Kunwu Chan
Date: Thu Nov 19 2026 - 23:38:37 EST
Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
Thanks,
Kunwu
>
> A priority ring with one device cannot benefit from rotating its starting
> offset or maintaining a quota. Read its only entry directly while the
> caller continues to hold the topology read lock and migration protection.
>
> Consume the cursor attempt and check the full/disabled pointer tag through
> the common path. A masked singleton therefore terminates or falls through
> with the same bounded behavior as a multi-device ring. Keep the existing
> large-folio same-priority failure boundary.
>
> This removes reader-local state updates for the common single-device case
> without bypassing device lifetime or availability checks.
>
> Signed-off-by: Lian Wang <lianux.mm@xxxxxxxxx>
> ---
> mm/swapfile.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 616339c5ae5b..0c192844b121 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -334,6 +334,11 @@ swap_queue_get_device(long nr_alloc, struct swap_queue_cursor *cursor)
>
> /* Consume masked peers too, so every walk remains bounded. */
> nr_iter = cursor->nr_iter++;
> + if (ring->size == 1) {
> + si = READ_ONCE(ring->dev[0]);
> + goto check_device;
> + }
> +
> local_lock(&swap_queue_readers->lock);
> ri = this_cpu_ptr(&swap_queue_readers->ri[queue_idx]);
> /*
> @@ -363,6 +368,7 @@ swap_queue_get_device(long nr_alloc, struct swap_queue_cursor *cursor)
> si = READ_ONCE(ring->dev[dev_idx]);
> local_unlock(&swap_queue_readers->lock);
>
> +check_device:
> if (swap_device_masked(si))
> return ERR_PTR(-EBUSY);
>