From: "David Hildenbrand (Arm)" <david@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>,
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, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] mm/zswap: preserve the workingset shadow across writeback
Date: Fri, 21 Aug 2026 11:58:43 +0200 [thread overview]
Message-ID: <c6e1ffd9-def5-448b-ad2d-52dfca9685ef@kernel.org> (raw)
In-Reply-To: <20260821093606.2231216-4-alex@ghiti.fr>
On 8/21/26 11:35, Alexandre Ghiti wrote:
> When zswap writes an entry back, allocating the buffer folio in the swap
> cache overwrites the swap slot's workingset shadow. It is lost and later
> re-minted inaccurately, which corrupts anon refault/workingset accounting
> for the written-back data.
>
> Preserve it within zswap itself: at writeback, park the shadow in the
> zswap tree in place of the freed entry, so it outlives the writeback
> buffer folio. The buffer then meets one of three fates, and the parked
> shadow is handled at whichever happens first:
>
> - swap-in: do_swap_page()/shmem_swapin_folio() find the buffer in the swap
> cache, take the shadow and feed it to workingset_refault() to account
> the refault of the now-resident folio, then drop it.
> - reclaim: __remove_mapping() skips minting a fresh shadow for the buffer
> (minting would double-count the eviction) and
> __swap_cache_do_del_folio() restores the parked shadow into the slot, so
> a later disk swap-in still refaults against the original eviction.
> - slot free (e.g. process exit): the shadow is not needed and is cleared.
>
> The last two both go through __swap_cache_do_del_folio(), the single point
> every swap-cache removal passes through, which is why the shadow is read
> and cleared there.
>
> Fixes: aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU")
> Signed-off-by: Nhat Pham <nphamcs@gmail.com>
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
> ---
> include/linux/swap.h | 2 +-
> include/linux/zswap.h | 12 ++++++
> mm/filemap.c | 2 +-
> mm/memory.c | 5 +++
> mm/shmem.c | 5 +++
> mm/swap_state.c | 14 ++++++-
> mm/vmscan.c | 4 +-
> mm/workingset.c | 16 ++++++--
> mm/zswap.c | 91 ++++++++++++++++++++++++++++++++++++++++++-
> 9 files changed, 142 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index 6d72778e6cc3..ef9b1612ac12 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -298,7 +298,7 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset,
> bool flush);
> void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages);
> void *workingset_eviction(struct folio *folio, struct mem_cgroup *target_memcg);
> -void workingset_refault(struct folio *folio, void *shadow);
> +void workingset_refault(struct folio *folio, void *shadow, bool lru_managed);
Passing booleans makes calling code hard to read. It's preferable to either use
(a) Dedicated flags; only makes sense if there are really more flags expected
(b) Having helpfer functions that spell it out for calling code
workingset_refault_lru_managed
workingset_refault
workingset_refault_lru
workingset_refault_nonlru
Or something like that, which makes calling code easier to get.
--
Cheers,
David
next prev parent reply other threads:[~2026-08-21 9:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 9:35 [PATCH v2 0/3] mm: fix workingset refaults in the zswap writeback path Alexandre Ghiti
2026-08-21 9:35 ` [PATCH v2 1/3] mm/swap: move LRU insertion out of the swap cache allocator Alexandre Ghiti
2026-08-23 8:38 ` Barry Song
2026-08-23 12:16 ` Alexandre Ghiti
2026-08-25 13:55 ` Alexandre Ghiti
2026-08-21 9:35 ` [PATCH v2 2/3] mm/swap: refault on swap-in, not in " Alexandre Ghiti
2026-08-21 9:35 ` [PATCH v2 3/3] mm/zswap: preserve the workingset shadow across writeback Alexandre Ghiti
2026-08-21 9:58 ` David Hildenbrand (Arm) [this message]
2026-08-21 10:19 ` 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=c6e1ffd9-def5-448b-ad2d-52dfca9685ef@kernel.org \
--to=david@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=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox