mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Barry Song <baohua@kernel.org>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>,
	 Alexandre Ghiti <alex@ghiti.fr>,
	akpm@linux-foundation.org, willy@infradead.org, jack@suse.cz,
	 liam@infradead.org, vbabka@kernel.org, jannh@google.com,
	chrisl@kernel.org,  kasong@tencent.com,
	shikemeng@huaweicloud.com, nphamcs@gmail.com,
	 baoquan.he@linux.dev, youngjun.park@lge.com, qi.zheng@linux.dev,
	 shakeel.butt@linux.dev, axelrasmussen@google.com,
	yuanchu@google.com, weixugc@google.com,  hannes@cmpxchg.org,
	mhocko@kernel.org, yosry@kernel.org, chengming.zhou@linux.dev,
	 kunwu.chan@gmail.com, tz2294@columbia.edu, hch@lst.de,
	linux-mm@kvack.org,  linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: madvise: drop MADV_PAGEOUT folios at swap writeback completion
Date: Tue, 22 Sep 2026 11:47:03 +0100	[thread overview]
Message-ID: <arJcPIaqJOzLpkel@gremlin> (raw)
In-Reply-To: <CAGsJ_4zGmGh70QtRBpnhueev3qt_bgB4ZiE9fkW-hgNjAVhv+w@mail.gmail.com>

On Tue, Sep 22, 2026 at 06:37:38PM +0800, Barry Song wrote:
> On Tue, Sep 22, 2026 at 6:20 PM David Hildenbrand (Arm)
> <david@kernel.org> wrote:
> >
> > On 9/21/26 23:56, Barry Song wrote:
> > > On Mon, Sep 21, 2026 at 11:37 PM David Hildenbrand (Arm)
> > > <david@kernel.org> wrote:
> > >>
> > >> On 9/21/26 17:24, Alexandre Ghiti wrote:
> > >>> On an asynchronous swap device MADV_PAGEOUT only marks the folio
> > >>> PG_reclaim and rotates it to the tail of the inactive list once its
> > >>> writeback completes, so the memory is not actually freed until a later
> > >>> reclaim scan removes the by then clean swap cache folio.
> > >> But we have the same behavior when just reclaiming memory ordinarily? It's added
> > >> to the swapcache and only the next scan actually frees up the memory.
> > >>
> > >> Wouldn't we memory we reclaim ... just gone, like in the sync case?
> > >
> > > For synchronous I/O, such as zswap and zram, the memory is released
> > > immediately after sync I/O is done.
> > >
> > > For asynchronous I/O, such as NVMe, the swapcache is currently
> > > expected to be rotated back to the tail of the LRU and wait for
> > > another scan. Alexandre once mentioned that when he tried handling
> > > async I/O the same way as sync I/O—releasing the memory once the I/O
> > > completed—he saw some regression. So, delaying the release until a
> > > later scan may allow swapcache hits before the folios are eventually
> > > reclaimed.
> >
> > "may", do we have any evidence that this actually is relevant in practice?
> >
> > We asked to reclaim memory. We wrote the memory out to disk. We unmapped it from
> > the page tables. We made the workload the could, access the page immediately
> > again suffer already.
> >
> > We should just evict them as soon as possible to free up memory.
>
> I suggested this to Alexandre, and he found that it could regress some
> workloads [1]. That is why Alexandre is only making the folios
> immediately reclaimable for `MADV_PAGEOUT`.
>
> See Alexandre's description:
>
> "Future work
> -----------
> Barry suggested extending this to MADV_PAGEOUT and general reclaim. I
> prototyped dropbehind for all reclaimed swap folios and it regressed
> sysbench OLTP throughput by ~15% on NVMe swap: dropping the swap cache
> immediately turns cheap in-cache refaults into disk reads and collapses
> swap readahead clustering. Neither blk-wbt, mq-deadline nor a PG_workingset
> gate recovered it. MADV_PAGEOUT alone may still be worth it, since there
> userspace has explicitly declared the range cold, but I have not measured
> that case in isolation yet."
>
> [1] https://lore.kernel.org/linux-mm/20260921151306.625134-1-alex@ghiti.fr/
>
> Best Regards
> Barry

This patch as-is is just way way way WAY too complicated and fragile IMO.

Whatever cases you have found, they need to be fixed somewhere
fundamental. All of this feels like a hack.

If you're having to write a comment like:

/*
 * If X is Y, but not if B, and if Z is J but not if the moon's bright at
 * night, then maybe we will foo the bar, but only if the baz is blarghed,
 * ...
 */

That usually means you're doing something horribly wrong.

And this patch has multiple comments like that.

--
Cheers, Lorenzo

  reply	other threads:[~2026-09-22 10:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 15:24 Alexandre Ghiti
2026-09-21 15:37 ` David Hildenbrand (Arm)
2026-09-21 21:56   ` Barry Song
2026-09-22  8:56     ` Kairui Song
2026-09-22 10:20     ` David Hildenbrand (Arm)
2026-09-22 10:37       ` Barry Song
2026-09-22 10:47         ` Lorenzo Stoakes (ARM) [this message]
2026-09-22 11:10           ` Barry Song
2026-09-22 11:15             ` Lorenzo Stoakes (ARM)
2026-09-22 11:36               ` Barry Song
2026-09-22 11:26         ` David Hildenbrand (Arm)
2026-09-22 10:44 ` Lorenzo Stoakes (ARM)
2026-09-22 13:22   ` Alexandre Ghiti
2026-09-22 15:22   ` Gregory Price

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=arJcPIaqJOzLpkel@gremlin \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=jannh@google.com \
    --cc=kasong@tencent.com \
    --cc=kunwu.chan@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=qi.zheng@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=shikemeng@huaweicloud.com \
    --cc=tz2294@columbia.edu \
    --cc=vbabka@kernel.org \
    --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 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®