From: sashiko-bot@kernel.org
To: "Nhat Pham" <nphamcs@gmail.com>, linux-mm@kvack.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"Chris Li" <chrisl@kernel.org>,
"Kairui Song" <kasong@tencent.com>,
"Kemeng Shi" <shikemeng@huaweicloud.com>,
"Baoquan He" <baoquan.he@linux.dev>,
"Barry Song" <baohua@kernel.org>,
"Youngjun Park" <youngjun.park@lge.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Yosry Ahmed" <yosry@kernel.org>,
"Chengming Zhou" <chengming.zhou@linux.dev>,
"Qi Zheng" <qi.zheng@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Michal Hocko" <mhocko@kernel.org>,
"David Hildenbrand" <david@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Hugh Dickins" <hughd@google.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Arnd Bergmann" <arnd@arndb.de>,
"Karl Mehltretter" <kmehltretter@gmail.com>,
"Dapeng Mi" <dapeng1.mi@linux.intel.com>,
"Marco Elver" <elver@google.com>,
"Ethan Nelson-Moore" <enelsonmoore@gmail.com>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
"Jeff Layton" <jlayton@kernel.org>, "Tejun Heo" <tj@kernel.org>,
"Michal Koutný" <mkoutny@suse.com>
Subject: Re: [PATCH v7 19/20] mm/swap: reclaim physical backing through reverse mappings
Date: Fri, 04 Dec 2026 22:09:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-250737@kernel.org> (raw)
In-Reply-To: <20261203220010.1302207-20-nphamcs@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm: folio_realloc_swap() omits SWP_RMAP_CACHE_ONLY on
zero-count vswap slots
- [Medium] mm: try_to_reclaim_vswap_backing() returns 0 on trylock
failure causing retries
--
commit 52440fcbb69abc8d4e57c8cf9a12927331e6d4fd
Author: Nhat Pham <nphamcs@gmail.com>
mm/swap: reclaim physical backing through reverse mappings
This commit switches physical swap range and full-cluster reclaim to
identify cache-only slots via the vswap reverse mapping
(SWP_RMAP_CACHE_ONLY) and removes the unused TTRS_* flags from
__try_to_reclaim_swap().
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index d71fccce5ae31..3f6c56c51c2c0 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
[ ... ]
> @@ -1014,19 +1002,13 @@ static bool cluster_reclaim_range(struct swap_info_struct *si,
> spin_unlock(&ci->lock);
> do {
> swp_tb = swap_table_get(ci, offset % SWAPFILE_CLUSTER);
> - if (swp_tb_is_vswap(swp_tb) &&
> - (swp_tb & SWP_RMAP_CACHE_ONLY)) {
> - vswap_entry = swp_tb_vswap_to_swp_entry(swp_tb);
> - if (try_to_reclaim_vswap_backing(si, offset,
> - vswap_entry) < 0)
> - break;
> + if (swp_tb_is_null(swp_tb))
> continue;
> - }
> - if (swp_tb_get_count(swp_tb))
> + if (!swp_tb_is_vswap_cache_only(swp_tb))
> + break;
> + vswap_entry = swp_tb_vswap_to_swp_entry(swp_tb);
> + if (try_to_reclaim_vswap_backing(si, offset, vswap_entry) < 0)
> break;
> - if (swp_tb_is_folio(swp_tb))
> - if (__try_to_reclaim_swap(si, offset, TTRS_ANYWAY) < 0)
> - break;
> } while (++offset < end);
> spin_lock(&ci->lock);
[Severity: Medium]
Can a concurrently locked folio cause cluster_reclaim_range() to keep
scanning and reclaiming slots in an unallocatable range?
Unlike __try_to_reclaim_swap(), try_to_reclaim_vswap_backing() returns 0
on folio_trylock() failure:
mm/swapfile.c:try_to_reclaim_vswap_backing() {
...
if (!folio_trylock(folio)) {
/* Unvalidated: the folio may not even own @offset. */
folio_put(folio);
return 0;
}
...
}
Because the return value is not negative, cluster_reclaim_range() does
not break. It repeats swap_cache_get_folio() XArray lookups and trylock
attempts on every subpage of a locked large folio, or frees and
redirties later folios in a range whose post-loop check will fail.
swap_reclaim_full_clusters() hits the same 0 return and advances one
slot at a time with full ci->lock unlock/lock cycles instead of skipping
the folio. Returning -1 on trylock failure would at least let
cluster_reclaim_range() break immediately without relying on the
unvalidated folio size.
[ ... ]
> @@ -1070,16 +1051,12 @@ static bool cluster_scan_range(struct swap_info_struct *si,
> swp_tb = __swap_table_get(ci, ci_off);
> if (swp_tb_is_null(swp_tb))
> continue;
> - if ((swp_tb_is_folio(swp_tb) && !__swp_tb_get_count(swp_tb)) ||
> - (swp_tb_is_vswap(swp_tb) && (swp_tb & SWP_RMAP_CACHE_ONLY))) {
> - /* vswap slots are abundant; never reclaim to reuse one */
> - if (swap_is_vswap(si) || !vm_swap_full())
> - return false;
> + if (swp_tb_is_vswap_cache_only(swp_tb) && vm_swap_full()) {
> *need_reclaim = true;
> continue;
> }
> /* Slot with zero count can only be NULL or folio */
> - VM_WARN_ON(!swp_tb_get_count(swp_tb));
> + VM_WARN_ON(swp_tb_is_shadow(swp_tb) && !__swp_tb_get_count(swp_tb));
> return false;
> } while (++ci_off < ci_end);
[Severity: Medium]
Can physical swap slots backing a zero-count vswap entry end up missing
SWP_RMAP_CACHE_ONLY and become invisible to physical reclaim?
SWP_RMAP_CACHE_ONLY is only set by swap_put_entries_cluster() ->
vswap_mark_cache_only() when swap count drops from 1 to 0 while vtable
already holds VSWAP_SWAPFILE. However, folio_realloc_swap() installs
physical backing (allocated with SWP_RMAP_CACHE_ONLY clear) without
checking whether any virtual slot already has swap count 0:
mm/swapfile.c:folio_realloc_swap() {
...
for (i = 0; i < nr; i++) {
pe.val = phys_entry.val + i;
__vtable_set(ci_dyn, voff + i, vtable_mk_phys(pe));
}
spin_unlock(&ci->lock);
...
}
On the disk-only (!may_zswap) path, folio_alloc_swap() calls
folio_realloc_swap() right after vswap_alloc() while swap count is 0.
If try_to_unmap() fails in shrink_folio_list() while swap is not full,
the folio stays cached with count 0 and SWP_RMAP_CACHE_ONLY clear.
Because swap count is already 0, swap_put_entries_cluster() will not run
again to mark the rmap. Those physical slots are then skipped by
cluster_scan_range() and swap_reclaim_full_clusters(), stranding
physical swap capacity and blocking large-order reuse.
Checking !__swp_tb_get_count(__swap_table_get(ci, voff + i)) under
ci->lock in folio_realloc_swap() and calling swap_rmap_mark_cache_only()
would keep the rmap flag in sync.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203220010.1302207-1-nphamcs@gmail.com?part=19
next prev parent reply other threads:[~2026-12-04 22:10 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 21:59 [PATCH v7 00/20] mm: mandatory virtual swap Nhat Pham
2026-12-03 21:59 ` [PATCH v7 01/20] mm/swap: prepare dynamic clusters for vswap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 02/20] mm, swap: prepare the swap IO path " Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 03/20] mm/swap: prepare zswap and zero storage for virtual entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 04/20] mm/swap: allocate virtual swap slots Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 05/20] mm/swap: return physical entries from the swap allocator Nhat Pham
2026-12-03 21:59 ` [PATCH v7 06/20] mm/swap: resolve physical backing for reads and device flags Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 07/20] mm/swap: prepare physical swapoff for virtual backing Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 08/20] mm/swap: support physical swap as a vswap backend Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 09/20] mm, swap: enable THP swapin for vswap entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 10/20] mm, swap: write back vswap zswap entries to physical swap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 11/20] mm, swap: reclaim physical slots backing cache-only vswap entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 12/20] mm, swap: add debugfs counters for vswap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 13/20] mm, swap: only charge physical swap entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 14/20] mm, swap: defer memcg_table allocation for physical swap clusters Nhat Pham
2026-12-03 22:00 ` [PATCH v7 15/20] mm, swap: add vmstat and memcg counters for vswap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 16/20] mm/swap: make vswap mandatory Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 17/20] mm/swap: drop direct physical swapcache handling Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 18/20] mm/zswap: store compressed entries only in the vtable Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 19/20] mm/swap: reclaim physical backing through reverse mappings Nhat Pham
2026-12-04 22:09 ` sashiko-bot [this message]
2026-12-03 22:00 ` [PATCH v7 20/20] mm/swap: move virtual swap metadata into vswap clusters Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:14 ` [PATCH v7 00/20] mm: mandatory virtual swap Yosry Ahmed
2026-12-03 23:00 ` Nhat Pham
2026-12-03 23:05 ` Yosry Ahmed
2026-12-03 23:14 ` Nhat Pham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-250737@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=bp@alien8.de \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=dapeng1.mi@linux.intel.com \
--cc=david@kernel.org \
--cc=elver@google.com \
--cc=enelsonmoore@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=jlayton@kernel.org \
--cc=kasong@tencent.com \
--cc=kmehltretter@gmail.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=rdunlap@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=skhan@linuxfoundation.org \
--cc=tj@kernel.org \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.com \
--cc=yuanchu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.