From: sashiko-bot@kernel.org
To: "Alexandre Ghiti" <alex@ghiti.fr>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Yosry Ahmed" <yosry@kernel.org>, "Nhat Pham" <nphamcs@gmail.com>,
"Chengming Zhou" <chengming.zhou@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Hugh Dickins" <hughd@google.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"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>,
"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>,
"Joonsoo Kim" <iamjoonsoo.kim@lge.com>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH v5 3/3] mm: zswap: preserve the workingset shadow across writeback
Date: Wed, 02 Dec 2026 18:01:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-246400@kernel.org> (raw)
In-Reply-To: <20261201175729.790028-4-alex@ghiti.fr>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm: missing zswap_swapin_writeback_folio() call in
unuse_pte_range()
- [Medium] mm: zswap: unnecessary O(nr_pages) xa_load() loop under
ci->lock
--
commit 7f5e8c1d5ef64588519452bf15c64dc4a8d5a95f
Author: Alexandre Ghiti <alex@ghiti.fr>
mm: zswap: preserve the workingset shadow across writeback
This commit preserves a swap slot's workingset shadow across zswap
writeback by parking it in the zswap tree in place of the freed entry and
consuming or restoring it when the writeback buffer folio is swapped in or
removed from the swap cache.
> diff --git a/mm/memory.c b/mm/memory.c
> index d477a4f986bc8..6fe6ab2ad315e 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -5104,6 +5104,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> goto out_page;
> }
>
> + zswap_swapin_writeback_folio(folio);
> +
> /*
> * KSM sometimes has to copy on read faults, for example, if
> * folio->index of non-ksm folios would be nonlinear inside the
[Severity: Medium]
Should unuse_pte_range() also call zswap_swapin_writeback_folio(folio)
before unuse_pte()?
When swapoff finds a zswap writeback buffer via swap_cache_get_folio(),
unuse_pte_range() locks the folio, waits for writeback, maps it with
unuse_pte(), and calls folio_free_swap() without consuming the parked
shadow. If folio_free_swap() removes the folio from the swap cache,
__swap_cache_do_del_folio() discards the shadow without evaluating
workingset_refault(). If the folio stays in the swap cache (for example,
the swap entry is shared across fork() and try_to_unuse() is interrupted
by a signal before the other process exits), the parked shadow remains in
the zswap tree on the now-resident folio, so later reclaim treats it as a
writeback buffer in zswap_is_writeback_folio(), skipping zswap_store() and
workingset_eviction().
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 4f0a0afe534d3..4096abafaf2ac 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -1062,6 +1062,122 @@ struct zswap_shrink_ctl {
[ ... ]
> +void *zswap_get_and_clear_writeback_shadow(struct folio *folio)
> +{
> + swp_entry_t swp = folio->swap;
> + unsigned long nr_pages = folio_nr_pages(folio);
> + pgoff_t offset = swp_offset(swp);
> + void *shadow = NULL;
> + unsigned long i;
> +
> + if (zswap_never_enabled())
> + return NULL;
> +
> + for (i = 0; i < nr_pages; i++) {
> + swp_entry_t e = swp_entry(swp_type(swp), offset + i);
> + struct xarray *tree = swap_zswap_tree(e);
> + void *parked = xa_load(tree, offset + i);
> +
> + if (!xa_is_value(parked))
> + continue;
> + xa_erase(tree, offset + i);
> + if (parked != ZSWAP_WRITEBACK_NO_SHADOW)
> + shadow = parked;
> + }
> +
> + return shadow;
> +}
[Severity: Medium]
Can this break (or walk with an XA_STATE) when !xa_is_value(parked), as
zswap_is_writeback_folio() does?
__swap_cache_do_del_folio() calls zswap_get_and_clear_writeback_shadow()
on every swap-cache deletion while holding ci->lock (with IRQs disabled
from __remove_mapping()). For a normal large folio whose zswap slots hold
zswap_entry pointers or NULL, using continue instead of break performs up
to 512 separate xa_load() walks under ci->lock.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201175729.790028-1-alex@ghiti.fr?part=3
next prev parent reply other threads:[~2026-12-02 18:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:57 [PATCH v5 0/3] mm: fix workingset refaults in the zswap writeback path Alexandre Ghiti
2026-12-01 17:57 ` [PATCH v5 1/3] mm: swap: refault on swap-in, not in the swap cache allocator Alexandre Ghiti
2026-12-01 17:57 ` [PATCH v5 2/3] mm: workingset: add workingset_refault_lru_managed() Alexandre Ghiti
2026-12-01 17:57 ` [PATCH v5 3/3] mm: zswap: preserve the workingset shadow across writeback Alexandre Ghiti
2026-12-02 18:01 ` sashiko-bot [this message]
2026-12-01 18:17 ` [PATCH v5 0/3] mm: fix workingset refaults in the zswap writeback path Yosry Ahmed
2026-12-02 3:33 ` Nhat Pham
2026-12-02 4:33 ` Yosry Ahmed
2026-12-02 4:40 ` Nhat Pham
2026-12-02 4:59 ` Yosry Ahmed
2026-12-02 9:25 ` Alexandre Ghiti
2026-12-02 7:29 ` Chris Li
2026-12-02 9:49 ` Alexandre Ghiti
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-246400@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=surenb@google.com \
--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.