[RFC PATCH v3 17/18] mm/swap: skip reader rotation for single-device priority rings

From: Lian Wang

Date: Tue Oct 27 2026 - 12:18:15 EST


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 bbd114f043ab..9e90f815f99c 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -333,6 +333,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]);
/*
@@ -362,6 +367,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);