diff options
| author | Nhat Pham <nphamcs@gmail.com> | 2026-11-10 07:14:06 -0800 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-11-22 22:24:11 -0800 |
| commit | afc0507d6e15cb21244f2b570dd57ced09375350 (patch) | |
| tree | 9034a1c570ae63856162921bcab5457baedb32f6 /tools/perf/scripts/python | |
| parent | 4436e171b0a46e06c16b8eb7dcc9e7ff5436dcee (diff) | |
mm/swap: publish cluster tables after reacquiring allocator locks
Under memory pressure, swap_cluster_populate() can publish a table
while its locks are dropped for a sleeping allocation. A cached
allocator can consume and free that table before the populating
allocator resumes, leaving the resumed scan with a NULL table.
CPU0 CPU1
alloc_swap_scan_list()
isolate_lock_cluster()
swap_cluster_populate()
drop local/global/ci locks
swap_cluster_alloc_table()
rcu_assign_pointer(ci->table, table)
folio_alloc_swap()
swap_alloc_fast()
alloc_swap_scan_cluster()
__swap_cluster_alloc_entries()
mem_cgroup_try_charge_swap()
return -ENOMEM
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()
reacquire local/global/ci locks
return ci
alloc_swap_scan_cluster()
cluster_scan_range()
__swap_table_get() /* NULL table */
Keep the count table, cgroup table and zero bitmap private until
swap_cluster_alloc_table() restores all allocator locks. Install them
under the cluster lock and retain it through the scan. Initial bad-slot
setup takes only the cluster lock because the device is unpublished.
The allocator releases its locks before the sleeping allocation. A
reclaimer that dropped ci->lock earlier can then resume and put the
cluster back on the free list. Abandon installation if the list state
changes or a table appears, freeing only private allocations. Restore
locks on allocation failure too, so the caller can return a still-isolated
cluster to its free list.
Link: https://lore.kernel.org/20261110151407.789960-3-nphamcs@gmail.com
Link: https://lore.kernel.org/all/sashiko-outbox-181086@kernel.org/
Fixes: cdd77f84d966 ("mm, swap: consolidate cluster allocation helpers")
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-181084@kernel.org/
Suggested-by: Kairui Song <ryncsn@gmail.com>
Acked-by: Kairui Song <kasong@tencent.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Barry Song <baohua@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christopher Li <chrisl@kernel.org>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Youngjun Park <youngjun.park@lge.com>
Cc: <stable@vger.kernel.org>
mm/swapfile.c | 106 +++++++++++++++++++++++++++++++++---------------
1 file changed, 74 insertions(+), 32 deletions(-)
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
