Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Baoquan He <baoquan.he@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: linux-mm@kvack.org, chrisl@kernel.org, nphamcs@gmail.com,
	kasong@tencent.com, baohua@kernel.org, youngjun.park@lge.com,
	yosry@kernel.org, david@kernel.org, shikemeng@huaweicloud.com,
	chengming.zhou@linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 01/10] mm: xswap support for zswap
Date: Fri, 7 Aug 2026 17:11:05 +0800	[thread overview]
Message-ID: <anWhKU8NPzosQR8d@MiWiFi-R3L-srv> (raw)
In-Reply-To: <anNGE_FOoupPtOhj@cmpxchg.org>

Hi Johannes,

On 08/05/26 at 10:17am, Johannes Weiner wrote:
> On Wed, Aug 05, 2026 at 03:53:24PM +0800, Baoquan He wrote:
> > From: Chris Li <chrisl@kernel.org>
> > 
> > Introduce extendable (virtual) swap device support ??? xswap.
> > 
> > The current zswap requires a backing swapfile. The swap slot used
> > by zswap is not able to be used by the swapfile, wasting swapfile
> > space.
> > 
> > An xswap device is a swapfile that only contains the swap header,
> > with the header indicating the size of the virtual swap space. There
> > is no swap data section, therefore no waste of swapfile space. Any
> > write to an xswap device will fail. To prevent accidental read or
> > write, bdev of swap_info_struct is set to NULL. Xswap devices set
> > the SSD flag because there is no rotational disk access when using
> > zswap.
> > 
> > Zswap writeback is disabled if all swapfiles in the system are
> > xswap devices (tracked via nr_real_swapfiles).
> > 
> > How to create an xswap device:
> >   touch swap.1G
> >   truncate -s 1G swap.1G
> >   mkswap swap.1G
> >   dd if=swap.1G of=xswap.1G bs=4096 count=1
> >   # xswap.1G is 4K on disk but reports 1G capacity
> >   swapon xswap.1G
> 
> Sigh.
> 
> Why does the user have to go through this dance?
> 
> Why does the user have to decide in advance what size the space needs
> to be?
> 
> You point out no inherent limit to how much can be compressed, so
> there is no reason to make userspace decide on an arbitrary one.
> 
> There is no reason to tie an address space that can be managed
> transparently inside the kernel to TWO named files on disk.

Thanks for looking into this.

The file-based creation dance is there only because this is RFC —
I wanted to reuse the existing swapon path so the core grow/shrink
machinery could be measured and tested without also designing a new
userspace interface. I agree it's not the right final interface.

The direction I'm thinking for the next revision:

- Drop the file requirement entirely.  An xswap device has no backing
  store, so there is no reason it needs a file.

- Use totalram_pages as the initial per-device size.  Chris suggested
  this, and it's a natural bound: if all anonymous memory is swapped
  out, that is the maximum number of swap entries zswap will ever need,
  assuming a reasonable compression ratio. The hard upper limit could
  be 2 times of system RAM, or the max system RAM memory hotplug can
  add to.

  Doing this because we need consider swap.tier support. A single global
  xswap device in swap.tier would mean all memcgs compress into the
  same device — there is only one swap entry namespace. With per-device
  xswap instances, swap.tier can bind different memcgs to different xswap
  devices, giving each its own swap slot namespace. Total isolation on slot
  usage, no cross-memcg interference.

   -----
   Hi Chris, Joungjun,
   Please correct me if I misunderstood the swap.tier concept and xswap
   use case in there.)
   -----

For creation, something like:

1. 
  echo $((4 * 1024 * 1024 * 1024)) > /sys/kernel/mm/xswap/create

or
2.
  even simpler, with automatic sizing:

  echo 1 > /sys/kernel/mm/xswap/enable

  (use totalram_pages as the default size.)

3. 
swapon -t xswap xswap0

(use totalram_pages as the default size.)

I'm open to other ideas.  If anyone have a preference for the interface,
I'd like to hear it.

> 
> There are plenty of past discussions on this very topic. I don't see
> the point in resubmitting the same thing under different names,
> without even a reference to previous discussions.
> 
> As a side note: if you have to add "(virtual)" after every instance of
> "extendable", then maybe "extendable" is a terrible name and you
> should just call it "virtual".

"extendable (virtual)" wasn't meant to explain one with the other.
Chris prefers "extendable", you prefer "virtual" — I put both in the
cover letter so the community could weigh in. I don't have a strong
preference to either. 

I'll address all of this in RFC v3 — drop the file requirement,
auto-size to totalram_pages (with grow/shrink for dynamic adjustment
on top), and settle the name. The goal of RFC v2 was to get the
core mechanics reviewed; I think that part is in reasonable shape,
and the interface is exactly the kind of thing I was hoping to get
feedback on.  Thanks for providing it.

Thanks
Baoquan



  reply	other threads:[~2026-08-07  9:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  7:53 [RFC PATCH v2 00/10] mm, swap: dynamic cluster management for xswap devices Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 01/10] mm: xswap support for zswap Baoquan He
2026-08-05 14:17   ` Johannes Weiner
2026-08-07  9:11     ` Baoquan He [this message]
2026-08-05  7:53 ` [RFC PATCH v2 02/10] mm, swap: add CONFIG_XSWAP and xswap fields to swap_info_struct Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 03/10] mm, swap: add xswap cluster grow via VM_SPARSE vmalloc Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 04/10] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 05/10] mm, swap: add xswap_try_shrink and shrink trigger on cluster free Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 06/10] mm, swap: free backing pages in xswap_unmap_clusters Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 07/10] mm, swap: add nr_free_tail for O(1) xswap shrink detection Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 08/10] mm, swap: add adjustable runtime ceiling (nr_clusters) for xswap Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 09/10] mm, swap: add debugfs knob for xswap per-device cluster limit Baoquan He
2026-08-05  7:53 ` [RFC PATCH v2 10/10] mm, swap: defer xswap shrink to workqueue to avoid lock recursion Baoquan He

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=anWhKU8NPzosQR8d@MiWiFi-R3L-srv \
    --to=baoquan.he@linux.dev \
    --cc=baohua@kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --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