From: Johannes Weiner <hannes@cmpxchg.org>
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>,
"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>,
"Gregory Price" <gourry@gourry.net>,
"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 11:41:31 -0400 [thread overview]
Message-ID: <araWKyJ5MENBwXCL@cmpxchg.org> (raw)
In-Reply-To: <arUcil9kxUPiymXI@KASONG-MC4>
On Fri, Sep 25, 2026 at 09:15:17PM +0800, Kairui Song wrote:
> On Tue, Sep 22, 2026 at 09:44:37PM +0100, Chris Li wrote:
> > It seems you are talking about a different topic: the vswap charging issue.
> > There is a golden rule that we should follow: don't break existing
> > users. At least with the same persistence, this rule should apply
> > universally.
> > In the swap tiers discussion, the UAPI was such a big deal that we
> > couldn't implement new UAPI. On the other hand here we argue for
> > liberally changing user-space visible behavior.
> >
> > BTW, I already shared that changing swap counter charging will break
> > our and others' existing deployments.
>
> Hi all
>
> As I read the threads and try to clean up the requirement, just
> realized that I forgot and ignored something previously. I think I can
> share a few things here.
>
> I also see that Rik mentioning that:
>
> > It adds up anonymous, file, accounted slab, and
> > (after compression) zswap memory use for a cgroup,
> > and can be limited with all the usual cgroup
> > limits.
>
> That's very true, and that's also the one reason we can't
> migrate some workload to zswap easily (at least yet) :D
> See below.
>
> The discussion on this can be saw two years before (I know
> things are different for V2, so see below):
> https://lore.kernel.org/linux-mm/CAMgjq7AYA91f4g-bknUZOMg6hApTD-X5LqjcTBN2u-Lu8pjs+w@mail.gmail.com/
>
> An minor update for that, memsw in V1 serves pretty well (we also
> modded that part and would try push to upstream if doable), and as
> memsw is missing in V2, we can still workaround that using
> memory.current and memory.swap.current. BUt missing the offloaded
> part in memory.swap seems a problem.
>
> First a little bit off topic, I'll be really happy if we can make
> both compressed memory and swap as separate counters (I even once
> tried to implement a zpool accounting to account compressed memory
> in some unified way, but, well, zpool got killed before I post
> that :P), or at least a way to do that, e.g. something like nokmem.
Thanks for your thoughtful email, Kairui.
> Due to our real usage:
>
> With compressed memory staying in a separate counter (which
> we manged to do that with ZRAM) the memory.current + memory.swap
> (or, memsw for cgv1) could be the exactly planned or sold size of a
> container, the scheduler (e.g. from k8s level) is fully aware of
> the packing rate of a host based on this reading. and can make
> scheduling decisions based on that. And can control it by
> adjusting the limit two combined.
>
> But with compression as a fixed part in memory.current, first the
> compression rate is totally uncontrollable, both the user and us
> will be fully *unaware* of how much memory they can *actually* use,
> that makes the planning really awkward. memory.max stops being the
> bound of what we planned or sold, anything compressed lets the raw
> footprint go past it by however much the compression ratio happens
> to give, so what we oversold is bounded by the workload's data and
> not by anything we configure. We can substract the zswap reading
> though with adaption, however it's hard to change the performance,
> OOM behavior or reclaim behavior:
>
> As you may considering compression is trading CPU time with memory,
> then two things here: the user could use more memory than we expected
> by burning the CPU. And, some users has a leaking application, the
> application could goes super slow or experiencing high CPU usage due
> to memory being compressed. They really just want to get OOM killed
> in time when ever the application leaks beyound a threshold (and
> yes that is a real and actually practical model for many applications).
> And, we can't simply disable memory compression for them.
>
> In many cases we just want a best effort compression to make space
> for low priority tasks, and do not want ordinary containers to use
> compression at the cost of lose of performance. While still has
> a fixed limit as usual. So simply disable memory compression is also
> not the plan, we do need compression to make place for other
> applications, we just don't want their real raw usage to exceed
> memory.max, and we can dynamically adjust memory.swap.max to
> control the oversold part, compression or physical.
>
> And this is not about residency, so memory.min/low don't help here:
> it's about overselling, and about not leaving a container thrashing in
> compress/decompress loops instead of being killed.
>
> And if the memory compression is really fully transparent (not
> doable by software), yeah, that's great as there is nothing to do
> with reclaim. But, for now, we have to go through page fault / folio
> allocation / map it again. So For example, if we already have
> memory.max == memory.current or under high pressure, then now
> doing any read from the compressed part would need to some
> require further eviction first to make place for the decompressed
> new data, this is not like any kind of "real" memory, something
> feels not right here.
>
> Another thing is that I think we has been assuming that physical
> swap is slower than compressed memory, which is not always true either.
> They all need to be read through page fault, the page fault could
> be the real blocker here rather than IO or de-compression.
>
> I also want to separate two things that I think got bundled together
> here: not requiring a physical slot behind a compressed entry, and not
> charging the raw size to the swap counter. The first one is great, yeah,
> and it's exactly the part we want, it's what makes compression usable
> without provisioning disk. The second one is a policy change, maybe it's
> not needed for the first stage, charging a cgroup for the
> memories it has offloaded doesn't require any slot to exist behind them.
> If someone wants to run memory compression with no disk at all,
> memory.swap.max defaults to max, so that still works fine, right?
I think what we found out over the course of this discussion is that
people have been using memory.swap.max in two ways. Regardless of what
we do, we will "break" one side.
(1) The usecase you're describing. Use memory.swap.max, combined with
memory.max, to set a "total", predictable footprint of in-use
application address space. You can mmap whatever you want, but the
number of unique pages you can touch is limited to this sum. And you
can control residency vs non-residency through the invididual values
of those settings. If compressed entries are not included, this
usecase will break.
(2) The use case we have. Use memory.swap.max to divide a finite space
in storage. We only have so much space on disk, and we need to manage
fair access. Note that this isn't about speed. We have a mix of
containers where some use writeback and others do not. The ones who
write back to the swapfile need to be able to get their fair share -
not more, not less. Including something that doesn't actually consume
this separate finite resource is also a behavioral change that would
break that usecase. And arguably it's a deviation from how the control
was intended and from the broader cgroup design philosophy.
I think we need to build tools to support both cases. But somebody
will have to change how they're doing things... :/
next prev parent reply other threads:[~2026-09-25 15:41 UTC|newest]
Thread overview: 121+ 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-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 [this message]
2026-09-25 16:11 ` Gregory Price
2026-09-25 16:54 ` Nhat Pham
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=araWKyJ5MENBwXCL@cmpxchg.org \
--to=hannes@cmpxchg.org \
--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=gourry@gourry.net \
--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®