From: Kunwu Chan <kunwu.chan@gmail.com>
To: Alexandre Ghiti <alex@ghiti.fr>
Cc: Kunwu Chan <kunwu.chan@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>,
Yosry Ahmed <yosry@kernel.org>, Nhat Pham <nphamcs@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
Kairui Song <ryncsn@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Jan Kara <jack@suse.cz>, Kemeng Shi <shikemeng@huaweicloud.com>,
Baoquan He <baoquan.he@linux.dev>, Barry Song <baohua@kernel.org>,
Youngjun Park <youngjun.park@lge.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
Michal Hocko <mhocko@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Wei Xu <weixugc@google.com>, Yuanchu Xie <yuanchu@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] mm: swap: drop dropbehind swap cache folios on writeback completion
Date: Fri, 21 Aug 2026 16:34:50 +0800 [thread overview]
Message-ID: <20260821083500.856970-1-kunwu.chan@linux.dev> (raw)
In-Reply-To: <20260818163221.589352-3-alex@ghiti.fr>
Hi Alexandre,
I have a question about the reference ownership/lifetime model in the
synchronous-IO case.
Consider the synchronous writeback path in Patch 3:
zswap_writeback_entry()
folio = __swap_cache_alloc_folio(...);
...
__swap_writepage(folio, NULL);
folio_put(folio);
During writeback completion, Patch 2 does:
folio_end_writeback(folio)
folio_get(folio);
...
swap_writeback_dropbehind_folio(folio);
llist_add()
queue_work()
With synchronous I/O, is it possible for the dropbehind worker to run
before zswap_writeback_entry() drops its reference after
__swap_writepage() returns?
If so, the worker will attempt:
swap_dropbehind_drop_folio(folio)
...
remove_mapping(swap_address_space(folio->swap), folio, true, memcg)
while the caller's reference is still held. Looking at
__remove_mapping() in mm/vmscan.c, it expects a refcount of
1 + folio_nr_pages(folio), but the extra reference still held by
zswap_writeback_entry() would make the actual refcount one higher.
It therefore looks like folio_ref_freeze() will fail in this case.
Is that the intended behavior here?
If the removal can fail, the fallback is:
folio_clear_dropbehind(folio);
folio_add_lru(folio);
This appears semantically safe, but it means that the dropbehind
optimization is lost for that writeback: the cold folio goes back onto
the LRU and has to be found by reclaim later.
This seems particularly worth checking because v3 intentionally removes
the synchronous-I/O special case from v2. The cover letter describes
that special case as an optimization that was not worth the extra code,
which I agree is a reasonable direction if the generic path is
sufficiently effective.
Could you measure the corresponding fallback rate on a synchronous
backend (e.g. zram)? The 99.996% success rate in the cover letter is for
asynchronous NVMe, so it does not tell us how often this particular race
occurs with synchronous completion.
More generally, I'd like the reference ownership across
__swap_writepage(), folio_end_writeback(), and the deferred worker to be
made explicit. If the caller's reference can overlap with the worker's
reference, I'd also like to understand whether that is an intentional
and acceptable trade-off, or whether the overlap can be avoided without
reintroducing the synchronous-I/O special case that v3 is trying to
remove.
Thanks,
KunWu
next prev parent reply other threads:[~2026-08-21 8:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 16:31 [PATCH v3 0/3] mm: zswap: free cold writeback folios promptly Alexandre Ghiti
2026-08-18 16:31 ` [PATCH v3 1/3] mm: swap: move LRU insertion out of the swap cache allocator Alexandre Ghiti
2026-08-18 16:31 ` [PATCH v3 2/3] mm: swap: drop dropbehind swap cache folios on writeback completion Alexandre Ghiti
2026-08-20 11:36 ` Barry Song
2026-08-20 15:38 ` Matthew Wilcox
2026-08-21 5:00 ` Barry Song
2026-08-21 9:46 ` Alexandre Ghiti
2026-08-21 9:45 ` Alexandre Ghiti
2026-08-21 8:34 ` Kunwu Chan [this message]
2026-08-21 9:53 ` Alexandre Ghiti
2026-08-21 14:01 ` KunWu Chan
2026-08-18 16:32 ` [PATCH v3 3/3] mm: zswap: drop cold writeback folios via swap dropbehind Alexandre Ghiti
2026-08-19 13:16 ` 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=20260821083500.856970-1-kunwu.chan@linux.dev \
--to=kunwu.chan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=brauner@kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=kasong@tencent.com \
--cc=kunwu.chan@linux.dev \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=ryncsn@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=viro@zeniv.linux.org.uk \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--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.