+ mm-swap-skip-relocation-of-tableless-clusters.patch added to mm-hotfixes-unstable branch
Andrew Morton
tree noticeThe patch titled
Subject: mm/swap: skip relocation of tableless clusters
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
mm-swap-skip-relocation-of-tableless-clusters.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-swap-skip-relocation-of-tableless-clusters.patch
This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Nhat Pham <[email protected]>
Subject: mm/swap: skip relocation of tableless clusters
Date: Tue, 10 Nov 2026 07:14:07 -0800
A stale reclaimer can reach relocate_cluster() after another allocator re-isolates an emptied cluster and drops its locks to populate the table. The cluster has zero count, CLUSTER_FLAG_NONE and no table, so relocation can free it again and dereference NULL in the DEBUG_VM empty check.
CPU0 CPU1
Reclaimer Allocator
alloc_swap_scan_cluster()
cluster_reclaim_range()
spin_unlock(&ci->lock)
__try_to_reclaim_swap()
swap_cache_del_folio()
__swap_cache_del_folio()
__swap_cache_do_del_folio()
__swap_cluster_free_entries()
free_cluster()
__free_cluster()
swap_cluster_free_table()
swap_cluster_unlock(ci)
isolate_lock_cluster()
swap_cluster_populate()
drop ci and outer locks
swap_cluster_alloc_table()
spin_lock(&ci->lock)
relocate_cluster()
free_cluster()
__free_cluster()
swap_cluster_assert_empty()
__swap_table_get() /* NULL table */Leave tableless clusters to the allocator under ci->lock. This also stops a stale reclaimer from returning a cluster to the free list while table population is pending, avoiding the resulting FREE-to-NONE state cycle. The existing cluster lock serializes the table check and relocation with population.
---
mm/swapfile.c | 7 +++++++ 1 file changed, 7 insertions(+)
mm/swapfile.c renamed from mm/swapfile.c~mm-swap-skip-relocation-of-tableless-clusters +7 -0
@@ -815,6 +815,13 @@ static void relocate_cluster(struct swapif (cluster_is_discard (ci))return ; +/* +* An allocator may still be preparing the table. +* Leave the cluster to it. +*/ +if (!cluster_table_is_alloced (ci)) +return ; +if (!ci->count) {if (ci->flags !=CLUSTER_FLAG_FREE )free_cluster (si, ci);
_
Patches currently in -mm which might be from [email protected] are
mm-vmscan-allow-writeout-of-swapcache-folios-without-anon-mappings.patch mm-swap-publish-cluster-tables-after-reacquiring-allocator-locks.patch mm-swap-skip-relocation-of-tableless-clusters.patch