Re: [PATCH RFC 01/13] mm/swap: fix off-by-one in swap cache replace sanity check

From: Zi Yan

Date: Sat Aug 08 2026 - 13:08:05 EST


On Fri Aug 7, 2026 at 5:17 PM EDT, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> The DEBUG_VM sanity check in __swap_cache_replace_folio() iterates
> the old folio's range with "while (ci_off++ < ci_end)", so the loop
> body runs on the already-incremented offset: the first entry is
> skipped and one entry past the range is read. For a folio split
> that entry belongs to the first after-split folio and was just
> repointed by the replacement loop above, so the check would warn
> spuriously whenever sub-folio orders differ from the head folio's,
> as non-uniform swapcache splits now do.
>
> Use the same do-while pattern as the replacement loop.
>
> Fixes: 8578e0c00dcf ("mm, swap: use the swap table for the swap cache and switch API")
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> ---
> mm/swap_state.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

LGTM.

Acked-by: Zi Yan <ziy@xxxxxxxxxx>

--
Best Regards,
Yan, Zi