From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net,
chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com,
hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com,
klarasmodin@gmail.com, "Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v8 09/14] mm, swap: let the command line set the xswap device size
Date: Fri, 04 Dec 2026 16:48:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-250227@kernel.org> (raw)
In-Reply-To: <20261203164336.864691-10-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mm, swap: xswap.max=max exceeds kvmalloc INT_MAX limit in
zswap_swapon()
- [Low] mm, swap: xswap_parse_size() parses percentages with base 0
instead of 10
- [Low] mm, swap: sub-PAGE_SIZE xswap.max= falls back to 200% instead of
refusing
--
commit 5bc278987251bcc1f79b53f20a43d0a5be1540cc
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 so users can
configure the size of a new xswap device as a byte size, a percentage of
RAM, or "max". The size is resolved in xswap_create(), refusing explicit
sizes that exceed the device limit or fall below one cluster.
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index ba899e349e992..6ce5dbb3b1035 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
[ ... ]
> @@ -74,6 +75,102 @@ static int xswap_destroy_by_name(const char *name);
[ ... ]
> +static int __init xswap_parse_size(const char *str, const char *what)
> +{
> + const char *pct;
> + char buf[16];
> + unsigned int pct_val;
> + unsigned long bytes;
> + char *end;
> +
> + pct = strchr(str, '%');
> + if (!strcmp(str, "max")) {
> + xswap_size_max = true;
> + xswap_size_pct = 0;
> + xswap_size_bytes = 0;
> + } else if (pct) {
> + size_t len = pct - str;
> +
> + if (pct[1] || !len || len >= sizeof(buf))
> + goto bad;
> + memcpy(buf, str, len);
> + buf[len] = '\0';
> + if (kstrtouint(buf, 0, &pct_val) || !pct_val)
> + goto bad;
[Severity: Low]
Should kstrtouint() use base 10 here instead of 0? With base 0, a
leading zero triggers octal parsing, so xswap.max=050% is silently parsed
as 40%, while xswap.max=080% fails as invalid octal and falls back to the
200% default.
> + xswap_size_pct = pct_val;
> + xswap_size_bytes = 0;
> + xswap_size_max = false;
> + } else {
> + bytes = memparse(str, &end);
> + if (*end || bytes < PAGE_SIZE)
> + goto bad;
[Severity: Low]
Does rejecting bytes < PAGE_SIZE here cause sub-page sizes to fall back to
the 200% default instead of being refused as documented?
xswap_max_setup() discards the error from xswap_parse_size(), leaving
xswap_size_pct at 200 and xswap_size_set false. A parameter such as
xswap.max=32K is refused by xswap_create() on a 4 KiB page kernel, but on
a 64 KiB page kernel it logs a parse error and silently creates a
200%-of-RAM device on swapon(2).
[ ... ]
> +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 xswap.max=max exceed kvmalloc's INT_MAX limit in zswap_swapon() and
trigger a WARN_ON_ONCE?
On 64-bit kernels with CONFIG_THP_SWAP=y (SWAPFILE_CLUSTER = 512 on 4 KiB
pages), xswap_size_limit() returns 0xffffffffUL * 512 (~8 PiB).
xswap_create() passes the full si->max to zswap_swapon():
mm/zswap.c:zswap_swapon() {
...
nr = DIV_ROUND_UP(nr_pages, ZSWAP_ADDRESS_SPACE_PAGES);
trees = kvzalloc_objs(*tree, nr);
...
}
With ZSWAP_ADDRESS_SPACE_PAGES = 16384 and sizeof(struct xarray) >= 16,
nr is 2^27, so kvzalloc_objs() requests at least INT_MAX + 1 bytes without
__GFP_NOWARN. __kvmalloc_node_noprof() hits WARN_ON_ONCE and returns
NULL, causing swapon(2) to fail with -ENOMEM (or panic if panic_on_warn).
Even for large sizes below INT_MAX, zswap_swapon() eagerly pins up to
1-2 GiB of unswappable memory and both zswap_swapon() and zswap_swapoff()
iterate over all trees without cond_resched().
In addition, setup_swap_clusters_info() reserves ~192-224+ GiB of vmalloc
space for UINT_MAX clusters, exceeding vmalloc space on 39-bit VA 64-bit
kernels (e.g., arm64 39-bit VA, riscv64 Sv39). Adding petabytes of swap
to total_swap_pages also distorts oom_badness() and vm_commit_limit().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203164336.864691-1-baoquan.he@linux.dev?part=9
next prev parent reply other threads:[~2026-12-04 16:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:43 [PATCH v8 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-12-03 16:43 ` [PATCH v8 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 02/14] mm: xswap support for zswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-12-03 16:43 ` [PATCH v8 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-12-04 16:48 ` sashiko-bot [this message]
2026-12-03 16:43 ` [PATCH v8 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-12-03 16:43 ` [PATCH v8 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 14/14] mm, swap: skip the overcommit probe when removing xswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
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-250227@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@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=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.