From: Gregory Price <gourry@gourry.net>
To: Kairui Song <ryncsn@gmail.com>
Cc: "Chris Li" <chrisl@kernel.org>, "Nhat Pham" <nphamcs@gmail.com>,
"Rik van Riel" <riel@surriel.com>,
"Baoquan He" <baoquan.he@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Kairui Song" <kasong@tencent.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Yosry Ahmed" <yosry@kernel.org>,
"David Hildenbrand" <david@kernel.org>,
"Muchun Song" <muchun.song@linux.dev>,
"Kemeng Shi" <shikemeng@huaweicloud.com>,
"Barry Song" <baohua@kernel.org>,
"YoungJun Park" <youngjun.park@lge.com>,
"Chengming Zhou" <chengming.zhou@linux.dev>,
"Lorenzo Stoakes (Oracle)" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Qi Zheng" <qi.zheng@linux.dev>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
"Wenchao Hao" <haowenchao22@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Hugh Dickins" <hughd@google.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Tejun Heo" <tj@kernel.org>, "Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Kunwu Chan" <kunwu.chan@linux.dev>,
"Meta kernel team" <kernel-team@meta.com>,
"Linux Memory Management List" <linux-mm@kvack.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
linux-doc@vger.kernel.org,
"open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)"
<cgroups@vger.kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Joshua Hahn" <joshua.hahnjy@gmail.com>
Subject: Re: Path forward for Virtualized Swap?
Date: Fri, 25 Sep 2026 17:30:03 -0400 [thread overview]
Message-ID: <arbgZ1OGndQAsXJc@gourry-fedora-PF4VCD3F> (raw)
In-Reply-To: <arbJ1LTzc7H4GL27@KASONG-MC4>
On Sat, Sep 26, 2026 at 04:44:07AM +0800, Kairui Song wrote:
> On Fri, Sep 25, 2026 at 12:11:55PM +0800, Gregory Price wrote:
> > 2) something has to pay the price of virtualization - period.
> >
> > No matter how we cut this issue, something in the stack is going
> > to implement a method of virtualizing a swap entry. Whether that's
> > a virtualization layer that virtualizes every backend, or some kind
> > of franken-swap device that lets a non-physical swap backend look
> > like a physical swap back end without charging physical swap.
> >
> > If the history of virtualization has taught us anything it's that
> > the overhead of a virtualization layer is *almost* never so extreme
> > that it isn't worth the utility of the layer
> > ( unless you virtualize the wrong things :] )
>
> Hmmm... I mean there are tons and tons of projects trying to get
> rid of the overhead of virtualization, if you are referring to
> virtialization as a broad topic..
>
> With careful design we can miminize the overhead for sure, and
> that's exactly why we need to do the design carefully :D
>
Oh absolutely, overhead is enemy number #1 - but we still deploy page
tables and virtual machines because the utility is just that high.
I suspect the level of virtualization we're talking about here, which
amounts to a single token representing many possible backends, is an
incredibly small overhead if designed correctly.
> >
> > I struggle to think of a scenario that cannot be described
> > compositionally this way - and that is without adding any kind of
> > "tier" logic.
>
> That sounds interesting, but I think this is already a mini
> version of swap tiering :D
>
Sort of. The key difference is that the actual resource being consumed
has vastly differently levels of availability and at least an order of
magnitude (if not 2-3) difference in latency. So while the tails can be
very bad, the P50s are generally not that severe.
We do this same thing in memory tiering - we treat socket-hosted memory
as the same tier, simply because it's not worth differentiating.
But we still prefer locality within that tier. So i could imagine
memory-backed swap tiers having locality that is separately grouped
from storage-backed swap tiers.
zsmalloc actually encodes a mild version of this - preferring to
compress onto the node the folio is being swapped out from
https://lore.kernel.org/linux-mm/20250402204416.3435994-1-nphamcs@gmail.com/
So in fact zsmalloc already has a tiering concept built-in.
> And not sure if the implementation will looks odd, e.g. like if you
> adjust that midway, you get different slot of different compression
> rates.?
>
It is not an intuitive set of knobs, but then i also don't think it's
particularly complicated math. But yes, there are some odd looking
configs.
> That data is very helpful info! But it could be very hardware dependent,
> especially with certain mitigations and hardwares, the faulting
> process may slowdown by a lot. This is the right picture for most
> cases, and for another example on one of our certain instance of VM, I
> observed this (high pressure, batch fault):
>
> component µs/page
> page fault handling (directly calibrated) ~1.92
> swap machinery (slot, swap cache, rmap, zram, etc) ~1.04
> lzo decompression ~0.32
>
> Kind of crazy that decompression only take a very minor part
> of it. While storage based SWAP goes through SPDK so it changes
> dramatically according to the host, setup or spec.
>
> BTW CRAM looks really nice from the data of yours :) !
>
Funny enough this is exactly the data needed to argue that CRAM should
not be a swap backend - you're offloading the cheapest part of the
process.
The actual win comes from allowing the compressed memory to stay mapped
while Read-only, which means you don't have faults. I'll call this
"ghost-pressure" - the data is in-memory, but you have to take a fault
because it's software-compressed. Letting it remain mapped R/O solves
the entire fault/swap machinery piece.
We cannot safely map R/W however, as you could have catestrophic loss of
compression ratio. (I digress, but hopefully we can chat more at LPC)
> > That shows up as stalls and PSI pretty quickly and can be dealt with
> > by monitoring - but I can see the desire to just have them OOM.
>
> Right, monitoring is less effective from somehting that is directly
> in the kernel.
>
Well.... I think this is probably an organizational philosophy.
We are pretty solidly effective with PSI + proactive reclaim keeping
our machines chugging along nicely. I think this is where a lot of
confusion is coming from - because the PSI data is very effective.
> > > The second one is a policy change,
> >
> > Disagree.
> >
> > If zswap does not charge a physical slot, then it is correct to stop
> > charging the counter based on the historic definition - it just was
>
> Hmm, but the historical defination is the logical entry, no?
>
I think this is the entire debate, right?
Historically I think it's clear that it is a physical slot, from the
time it was proposed it was talked about in terms of consumption, and
Johannes' original definition even said "physical" (for some reason
this did not make it into the docs).
The zswap-charging-swap was a function of zswap reserving a writeback
slot - which means it *was* consuming a physical slot and it was being
accounted accordingly.
If zswap no longer reserves a writeback slot by default, it's not being
consumed, and so not charging it is correct.
But if you read the docs as swap being a logical counter as opposed to a
physical counter, without the context of zswap reserving writeback, then
I can understand how we got here.
The question is how do we move foward. Continuing to charge swap breaks
us, but not charging swap breaks you. At the end of the day, someone is
changing the counter they're using (or methodology).
> > I would push back on tiering - this seems like more complexity than the
> > requirement warrants. We may find memory-backed and storage-backed swap
> > want different solutions in the "tiering" worlds.
>
> Hmm, I mean in general swap are page fault (swap entry) based, that makes
> them similiar and that's the common point?
>
As above, I think even in memory-tiering we have this separation of
reasoning about different logical tiers of memory (VRAM, DRAM, CXL) but
among those tiers we do not differentiation except maybe based on
locality of accessor (socket0 prefers cxl on its own CXL complex over
cxl on socket1's complex to avoid the extra NUMA hop).
I can see there being a differentiation here as well (memory backed vs
storage backed).
> >
> > e.g. it may never make sense to give zswap/zram/xswap a lower priority
> > than a physical swap layer, and you may never really want to compose
> > them with one another, so why does it need to be considered?
>
> Making ZRAM have a lower priority could make sense... Well I haven't
> actually see it being used that way, but first there are users of
> multiple ZRAMs indeed, and e.g. if you put offline batch tasks on the
> same machine with high priority tasks, and the offline batch task only
> want to finish their work, however slow is fine, and the user want to
> have lower impact on CPU usage from them, with a limited storage space.
> Well I have to say this looks odd and just a theory, but we have see
> too many bizzard usage of the Linux kernel, there are even people
> using deprecated GPU's VRAM as SWAP for CPU's RAM, and hey they
> still make sense, you can easily found popular community projects
> based on that.
This is what I mean by I would push back on a tiering solution. We
haven't even figured this out for memory alone - let alone a component
that composes both memory and storage.
What's the chance we get it right? I think unlikely.
~Gregory
next prev parent reply other threads:[~2026-09-25 21:30 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 21:14 Nhat Pham
2026-09-07 5:51 ` Kairui Song
2026-09-08 16:36 ` Nhat Pham
2026-09-11 16:09 ` Kairui Song
2026-09-11 16:57 ` Nhat Pham
2026-09-11 18:14 ` Kairui Song
2026-09-11 19:03 ` Nhat Pham
2026-09-12 8:47 ` Kairui Song
2026-09-14 16:49 ` Nhat Pham
2026-09-08 18:30 ` Johannes Weiner
2026-09-09 16:41 ` Nhat Pham
2026-09-09 17:47 ` Nhat Pham
2026-09-12 9:00 ` Kairui Song
2026-09-12 11:51 ` Johannes Weiner
2026-09-19 7:23 ` Chris Li
2026-09-20 1:06 ` Rik van Riel
2026-09-21 0:18 ` Chris Li
2026-09-21 0:35 ` Rik van Riel
2026-09-21 0:53 ` Chris Li
2026-09-14 16:10 ` Nhat Pham
2026-09-10 23:27 ` Nhat Pham
2026-09-07 11:30 ` David Hildenbrand (Arm)
2026-09-08 16:45 ` Nhat Pham
2026-09-10 10:56 ` David Hildenbrand (Arm)
2026-09-10 16:22 ` Nhat Pham
2026-09-10 17:57 ` David Hildenbrand (Arm)
2026-09-11 16:20 ` Kairui Song
2026-09-11 16:56 ` David Hildenbrand (Arm)
2026-09-14 15:00 ` Baoquan He
2026-09-19 6:50 ` Chris Li
2026-09-21 18:55 ` Nhat Pham
2026-09-22 13:38 ` Chris Li
2026-09-22 14:43 ` Shakeel Butt
2026-09-22 14:56 ` Chris Li
2026-09-22 15:07 ` Johannes Weiner
2026-09-22 15:30 ` Chris Li
2026-09-22 15:45 ` Shakeel Butt
2026-09-23 6:44 ` Chris Li
2026-09-22 15:46 ` Johannes Weiner
2026-09-22 15:28 ` Baoquan He
2026-09-25 18:47 ` Shakeel Butt
2026-09-10 7:09 ` Baoquan He
2026-09-10 16:39 ` Shakeel Butt
2026-09-11 13:06 ` Baoquan He
2026-09-11 16:45 ` Shakeel Butt
2026-09-15 5:48 ` Baoquan He
2026-09-15 6:44 ` Baoquan He
2026-09-19 6:55 ` Chris Li
2026-09-19 16:15 ` Rik van Riel
2026-09-19 21:21 ` Chris Li
2026-09-19 22:50 ` Rik van Riel
2026-09-21 0:13 ` Chris Li
2026-09-22 17:54 ` Nhat Pham
2026-09-23 7:44 ` Chris Li
2026-09-23 16:30 ` Shakeel Butt
2026-09-24 11:27 ` Chris Li
2026-09-24 13:15 ` Shakeel Butt
2026-09-25 13:15 ` Kairui Song
2026-09-25 15:41 ` Johannes Weiner
2026-09-25 19:21 ` Kairui Song
2026-09-25 20:20 ` Johannes Weiner
2026-09-25 16:11 ` Gregory Price
2026-09-25 20:44 ` Kairui Song
2026-09-25 21:30 ` Gregory Price [this message]
2026-09-25 21:53 ` Johannes Weiner
2026-09-25 16:54 ` Nhat Pham
2026-09-25 20:26 ` Kairui Song
2026-09-25 19:36 ` Shakeel Butt
2026-09-25 20:20 ` Kairui Song
2026-09-19 7:07 ` Chris Li
2026-09-10 17:03 ` Johannes Weiner
2026-09-11 12:27 ` Baoquan He
2026-09-11 16:21 ` Johannes Weiner
2026-09-19 8:45 ` Chris Li
2026-09-19 16:08 ` Gregory Price
2026-09-19 19:02 ` Chris Li
2026-09-20 1:14 ` Rik van Riel
2026-09-20 1:53 ` Gregory Price
2026-09-21 9:43 ` Chris Li
2026-09-21 12:53 ` Gregory Price
2026-09-21 16:11 ` Chris Li
2026-09-22 17:14 ` Rik van Riel
2026-09-22 17:21 ` Nhat Pham
2026-09-23 7:20 ` Chris Li
2026-09-22 17:31 ` Johannes Weiner
2026-09-23 7:32 ` Chris Li
2026-09-23 13:55 ` Johannes Weiner
2026-09-21 14:06 ` Rik van Riel
2026-09-21 16:15 ` Chris Li
2026-09-21 15:16 ` Rik van Riel
2026-09-21 16:31 ` Chris Li
2026-09-21 16:36 ` Rik van Riel
2026-09-21 18:10 ` Chris Li
2026-09-21 18:52 ` Rik van Riel
2026-09-22 13:32 ` Chris Li
2026-09-22 14:59 ` Rik van Riel
2026-09-22 15:23 ` Chris Li
2026-09-22 15:43 ` Johannes Weiner
2026-09-23 6:10 ` Chris Li
2026-09-22 15:48 ` Rik van Riel
2026-09-23 7:00 ` Chris Li
2026-09-23 14:21 ` Rik van Riel
2026-09-22 17:32 ` Nhat Pham
2026-09-23 7:37 ` Chris Li
2026-09-23 14:11 ` Johannes Weiner
2026-09-23 15:39 ` Nhat Pham
2026-09-22 15:20 ` Gregory Price
2026-09-22 15:43 ` Chris Li
2026-09-22 15:52 ` Rik van Riel
2026-09-23 7:10 ` Chris Li
2026-09-23 12:52 ` Klara Modin
2026-09-23 15:43 ` Nhat Pham
2026-09-23 17:26 ` Klara Modin
2026-09-24 5:51 ` Baoquan He
2026-09-24 7:20 ` Klara Modin
2026-09-24 7:53 ` Baoquan He
2026-09-21 10:01 ` Kairui Song
2026-09-21 13:27 ` Gregory Price
2026-09-21 15:27 ` Rik van Riel
2026-09-21 15:48 ` Gregory Price
2026-09-21 16:32 ` Chris Li
2026-09-21 17:02 ` Gregory Price
2026-09-23 9:39 ` Baoquan He
2026-09-23 12:11 ` Gregory Price
2026-09-24 11:02 ` Chris Li
2026-09-24 14:18 ` Gregory Price
2026-09-23 14:34 ` Kairui Song
2026-09-21 18:11 ` Nhat Pham
2026-09-22 17:16 ` Johannes Weiner
2026-09-10 17:16 ` Nhat Pham
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=arbgZ1OGndQAsXJc@gourry-fedora-PF4VCD3F \
--to=gourry@gourry.net \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=cgroups@vger.kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=haowenchao22@gmail.com \
--cc=hughd@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kasong@tencent.com \
--cc=kernel-team@meta.com \
--cc=kunwu.chan@linux.dev \
--cc=liam@infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=riel@surriel.com \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=ryncsn@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--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
all inboxes | Powered by JetHome®