From: Johannes Weiner <hannes@cmpxchg.org>
To: Kairui Song <ryncsn@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>,
Kairui Song via B4 Relay <devnull+kasong.tencent.com@kernel.org>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Chris Li <chrisl@kernel.org>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
Barry Song <baohua@kernel.org>,
Youngjun Park <youngjun.park@lge.com>,
Yosry Ahmed <yosry@kernel.org>,
Chengming Zhou <chengming.zhou@linux.dev>,
Usama Arif <usamaarif642@gmail.com>,
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>,
Chuanhua Han <hanchuanhua@oppo.com>,
Mani Tofigh <mt4022@columbia.edu>,
linux-kernel@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>
Subject: Re: [PATCH 2/3] mm/swap: account synchronous swap reads as memory stall
Date: Mon, 2 Nov 2026 14:10:03 -0500 [thread overview]
Message-ID: <aujgC6qPrTqewPPP@cmpxchg.org> (raw)
In-Reply-To: <CAMgjq7DZYKXGw1McsDT345HS4BNqa46xte_dTJia6EMv2Dy6jg@mail.gmail.com>
On Tue, Nov 03, 2026 at 01:26:35AM +0800, Kairui Song wrote:
> On Tue, Nov 3, 2026 at 12:57 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
> >
> > On Sat, Oct 31, 2026 at 04:00:22AM +0800, Kairui Song wrote:
> > > On Fri, Oct 30, 2026 at 9:08 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
> > > >
> > > > Hm, I think the only option to avoid this would be to split the batch
> > > > and flush more frequently, which I'm not sure is worth it. The batch
> > > > size is only 32 folios...
> > > >
> > > > diff --git a/mm/page_io.c b/mm/page_io.c
> > > > index 22e5ac1d298f..806cfe633a95 100644
> > > > --- a/mm/page_io.c
> > > > +++ b/mm/page_io.c
> > > > @@ -207,6 +207,8 @@ static bool swap_can_merge(struct swap_io_ctx *ctx, struct folio *folio,
> > > >
> > > > if (ctx->sis != sis)
> > > > return false;
> > > > + if (rw == READ && ctx->workingset != folio_test_workingset(folio))
> > > > + return false;
> > > > return sis->ops->can_merge(folio, prev_folio, prev_folio_size, rw);
> > > > }
> > >
> > > We are in a dilemma with this change: if it fires frequently it breaks
> > > batching but improves PSI accuracy. If it doesn't fire frequently, it
> > > has no negative effect on batching and performance, and it isn't helping
> > > with PSI accuracy either :/
> > >
> > > But after a second thought, maybe we can live with it by having both this
> > > posted patch merged as it is and appending your suggested fix: the two
> > > kinds of devices end up differently.
> > >
> > > For sync devices the batch is now always one folio, so there is nothing
> > > fancy, everything is accurate. Readahead batching for them only happens
> > > on the MADV and swapoff walks, so the cost is limited.
> > >
> > > For async, the window covers submission. That cost grows only mildly
> > > with the folios in the bio, block layer and dispatch work, unlike a
> > > synchronous read. And the previous per folio accounting was not
> > > exact either: in a single threaded task, the throttle or cost of
> > > a non-workingset readahead folio pays is also holding up the workingset
> > > folio's refault, since the task cannot start the next submission until
> > > that one returns. Same story for delayacct.
> >
> > That sounds reasonable to me. Zero benefit to batching on these
> > devices, so no point in taking the fuzz factor that comes with it.
> >
> > > And we are missing the completion wait either way: if a fault finds the
> > > folio in the swap cache with its read still in flight, it blocks in
> > > folio_lock_or_retry() in do_swap_page(), which no window covers.
> >
> > It's there, if you drill down to folio_wait_bit_common():
> >
> > if (bit_nr == PG_locked &&
> > !folio_test_uptodate(folio) && folio_test_workingset(folio)) {
> > delayacct_thrashing_start(&in_thrashing);
> > psi_memstall_enter(&pflags);
> > thrashing = true;
> > }
>
> Thanks for the info! Good to know.
>
> > > So perhaps we can live with it for now by having your suggested fix
> > > on top of this posted patch? Some comments could be helpful here and
> > > maybe some further improvement is needed.
> >
> > Yes, I think that plan works.
> >
> > Want me to send a proper patch with changelog on top of Josef's?
>
> I've tested the following code on top of V1, and it worked well; it
> seems there is no need to move some functions or am I missing anything?
I did that to keep the write side in the same sequence, and remove the
then fully redundant submission in swap_add_folio(). Seems a bit
easier on readers that way.
> How about I keep your authorship and just send V2 including this ? :)
> Any other suggestions are welcomed!
Works for me, thanks!
next prev parent reply other threads:[~2026-11-02 19:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 18:31 [PATCH 0/3] mm/swap, zswap: fix stale zswap data and swap-in bugs Kairui Song via B4 Relay
2026-10-29 18:31 ` [PATCH 1/3] mm/zswap: drop the stale zswap entry of a zero folio Kairui Song via B4 Relay
2026-10-29 19:17 ` Johannes Weiner
2026-10-29 21:06 ` Nhat Pham
2026-10-29 21:15 ` Yosry Ahmed
2026-10-29 18:31 ` [PATCH 2/3] mm/swap: account synchronous swap reads as memory stall Kairui Song via B4 Relay
2026-10-29 21:00 ` Johannes Weiner
2026-10-30 11:16 ` Kairui Song
2026-10-30 13:08 ` Johannes Weiner
2026-10-30 20:00 ` Kairui Song
2026-11-02 16:57 ` Johannes Weiner
2026-11-02 17:26 ` Kairui Song
2026-11-02 19:10 ` Johannes Weiner [this message]
2026-10-29 18:31 ` [PATCH 3/3] mm, swap: fix large swap-in across swap file extents Kairui Song via B4 Relay
2026-10-29 21:21 ` Nhat Pham
2026-10-30 7:30 ` Kairui Song
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=aujgC6qPrTqewPPP@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=devnull+kasong.tencent.com@kernel.org \
--cc=hanchuanhua@oppo.com \
--cc=hch@lst.de \
--cc=josef@toxicpanda.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=mt4022@columbia.edu \
--cc=nphamcs@gmail.com \
--cc=rppt@kernel.org \
--cc=ryncsn@gmail.com \
--cc=shikemeng@huaweicloud.com \
--cc=surenb@google.com \
--cc=usamaarif642@gmail.com \
--cc=vbabka@kernel.org \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.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
all inboxes | Powered by JetHome®