All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org,
	kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org,
	corbet@lwn.net, nphamcs@gmail.com, baohua@kernel.org,
	youngjun.park@lge.com, shikemeng@huaweicloud.com,
	yosry@kernel.org, chengming.zhou@linux.dev, kunwu.chan@gmail.com,
	klarasmodin@gmail.com, "Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v7 09/14] mm, swap: let the command line set the xswap device size
Date: Mon, 30 Nov 2026 15:09:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-241468@kernel.org> (raw)
In-Reply-To: <20261129150755.191662-10-baoquan.he@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm, swap: multi-GiB eager zswap allocation in xswap_create()
  on xswap.max=max
--

commit 907eeff02d0e504aa197c941cec5a5a165686a5e
Author: Baoquan He <hebaoquan@kylinos.cn>

mm, swap: let the command line set the xswap device size

This commit adds the xswap.max= kernel command-line parameter to configure
the size of new xswap devices as a percentage of RAM, a byte size, or
"max".

> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index ba899e349e992..6ce5dbb3b1035 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
[ ... ]
> +/*
> + * The most a device can address, whatever xswap.max= asked for.  An xswap
> + * slot is still a swap entry, so the swap offset limit applies even though
> + * the data never goes through a physical address.
> + */
> +static unsigned long xswap_size_limit(void)
> +{
> +	unsigned long limit = swapfile_maximum_size;
> +
> +	/* A cluster index is an unsigned int. */
> +	if (limit / SWAPFILE_CLUSTER > UINT_MAX)
> +		limit = (unsigned long)UINT_MAX * SWAPFILE_CLUSTER;
> +
> +	return limit;
> +}
> +
> +static unsigned long xswap_size_pages(void)
> +{
> +	unsigned long long pages;
> +
> +	if (xswap_size_max)
> +		return xswap_size_limit();

[Severity: Medium]
Can setting xswap.max=max cause xswap_create() to allocate multiple
gigabytes of physical memory upfront in zswap_swapon() or exhaust vmalloc
address space in setup_swap_clusters_info()?

On 64-bit systems, xswap_size_limit() caps si->max at UINT_MAX *
SWAPFILE_CLUSTER (~2.2 trillion pages with 4K pages and CONFIG_THP_SWAP=y,
or ~35.2 trillion pages with 64K pages).  xswap_create() then passes
si->max to zswap_swapon(), which eagerly allocates and initializes one
struct xarray per ZSWAP_ADDRESS_SPACE_PAGES (16,384) pages:

mm/zswap.c:zswap_swapon() {
    ...
	nr = DIV_ROUND_UP(nr_pages, ZSWAP_ADDRESS_SPACE_PAGES);
	trees = kvzalloc_objs(*tree, nr);
	if (!trees) {
		pr_err("alloc failed, zswap disabled for swap type %d\n", type);
		return -ENOMEM;
	}

	for (i = 0; i < nr; i++)
		xa_init(trees + i);
    ...
}

At that limit, trees requires 134,217,728 xarrays (2 GiB of physical RAM
on 4K-page systems, or 32 GiB on 64K-page systems) initialized in an
unscheduled loop before any page is swapped, failing with -ENOMEM on
smaller machines.  In addition, setup_swap_clusters_info() reserves
UINT_MAX * sizeof(struct swap_cluster_info) (~192 GiB) of vmalloc virtual
address space via get_vm_area(), which exceeds the entire vmalloc space on
39-bit VA configurations.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129150755.191662-1-baoquan.he@linux.dev?part=9


  reply	other threads:[~2026-11-30 15:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 15:07 [PATCH v7 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-11-29 15:07 ` [PATCH v7 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-11-30 15:09   ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 02/14] mm: xswap support for zswap Baoquan He
2026-11-29 15:07 ` [PATCH v7 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-11-29 15:07 ` [PATCH v7 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-11-29 15:07 ` [PATCH v7 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-11-29 15:07 ` [PATCH v7 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-11-30 15:09   ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-11-29 15:07 ` [PATCH v7 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-11-29 15:07 ` [PATCH v7 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-11-30 15:09   ` sashiko-bot [this message]
2026-11-29 15:07 ` [PATCH v7 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-11-29 15:07 ` [PATCH v7 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-11-30 15:09   ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-11-29 15:07 ` [PATCH v7 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-11-30 15:09   ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 14/14] mm, swap: skip the overcommit probe when removing xswap 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=sashiko-outbox-241468@kernel.org \
    --to=sashiko-bot@kernel.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=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hebaoquan@kylinos.cn \
    --cc=kasong@tencent.com \
    --cc=klarasmodin@gmail.com \
    --cc=kunwu.chan@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shikemeng@huaweicloud.com \
    --cc=urezki@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.