]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mm, swap: fix reclaim offset calculation error during allocation
authorKairui Song <kasong@tencent.com>
Thu, 30 Jan 2025 11:51:31 +0000 (19:51 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 1 Feb 2025 11:53:26 +0000 (03:53 -0800)
There is a code error that will cause the swap entry allocator to reclaim
and check the whole cluster with an unexpected tail offset instead of the
part that needs to be reclaimed.  This may cause corruption of the swap
map, so fix it.

Link: https://lkml.kernel.org/r/20250130115131.37777-1-ryncsn@gmail.com
Fixes: 3b644773eefd ("mm, swap: reduce contention on device lock")
Signed-off-by: Kairui Song <kasong@tencent.com>
Cc: Chris Li <chrisl@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c

index 6e867c16ea9347d1be266f17131a4ff96c47fe90..ba19430dd4eadb7a3f453ab94b311bcc12931390 100644 (file)
@@ -794,7 +794,7 @@ static unsigned int alloc_swap_scan_cluster(struct swap_info_struct *si,
                if (!cluster_scan_range(si, ci, offset, nr_pages, &need_reclaim))
                        continue;
                if (need_reclaim) {
-                       ret = cluster_reclaim_range(si, ci, start, end);
+                       ret = cluster_reclaim_range(si, ci, offset, offset + nr_pages);
                        /*
                         * Reclaim drops ci->lock and cluster could be used
                         * by another order. Not checking flag as off-list