From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0B13606A32A for ; Sun, 29 Nov 2026 15:09:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=T9NPQmo9 Received: by kanga.kvack.org (Postfix) id 81FB16B05C0; Sun, 29 Nov 2026 10:09:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7CD6B05C1; Sun, 29 Nov 2026 10:09:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70DB16B05C2; Sun, 29 Nov 2026 10:09:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 394846B05C0 for ; Sun, 29 Nov 2026 10:09:11 -0500 (EST) Received: from smtpin05.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BBA2A406C7 for ; Sun, 29 Nov 2026 15:09:10 +0000 (UTC) X-FDA: 85488489660.05.1684156 Received: from mta0.migadu.com (out-152.mta0.migadu.com [91.218.175.152]) by imf29.hostedemail.com (Postfix) with ESMTP id B87ED12000C for ; Sun, 29 Nov 2026 15:09:08 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=T9NPQmo9; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.152 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795964949; b=8coRXv5QBPOk+JZLB9KezZ9WSkHRDuxylUJXU0yjukYQn7i335WEkDw+964H6wDgLCjBnR YoNu5jaJPug7k9eHMsfpR0Jfn9SrXpBPFf7CWMTu9ZIq/n+VpX7tiJQ29mfHfBYoIXaIGn zFB3UiY/b4YAb5UJI3e+MMRdv/DUEhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795964949; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aG77Tt0+HfKSaS8cceIBpOVkgp9+NtupJFY/VfZdPcA=; b=39twFgAclA+U/L5+JoZI8qUfV0WHr2yLgOnwVnB3nqGvmnubp2eyLyuM8ohulR4QojBVV4 d4nn6vKbHA+kG4qNCs5Mo1WKPhzR9G/ZzMsslI4YMreiBX1Rw03E1yIAXyh0fiuPKqcuA1 JpLf8bzlHIl4SDUCkZzWn9xch6+oP+M= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=T9NPQmo9; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.152 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=bnqwKFpeU5/2y2rW/HXN7qmHVkG3yeEx8fWuFw3RSKU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795964947; v=1; x=1796569747; b=T9NPQmo97vGOuoiN3+OzhIqJ0MscD7/0v6BSYhwSDocWBiDu8lOI945xVID9cny3VrUh519A qKtxMUQCi4hv2wIYTsQO/ii98uKk5EOuDsOMdAMCyYC6ezgmS9IS9u5NJUu/ZXtQqMH/LHqOHuS od3XN5kjhPi47DN6lsvXSOd0= X-Envelope-To: linux-mm@kvack.org Received: by mta10.migadu.com with ESMTPS id dac2cd4c71c69d74; Sun, 29 Nov 2026 15:09:07 +0000 X-Mizu-Trace-ID: dac2cd4c71c69d74 X-Migadu-Flow: FLOW_OUT From: Baoquan He To: 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, linux-kernel@vger.kernel.org, baoquan.he@linux.dev, Baoquan He Subject: [PATCH v7 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Date: Sun, 29 Nov 2026 23:07:51 +0800 Message-ID: <20261129150755.191662-11-baoquan.he@linux.dev> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261129150755.191662-1-baoquan.he@linux.dev> References: <20261129150755.191662-1-baoquan.he@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Stat-Signature: 69bk6mekf4ancaksybx1kuoot5p3ppja X-Rspamd-Queue-Id: B87ED12000C X-Rspam-User: X-Rspamd-Server: rspam03 X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1795964948-188717 X-HE-Meta: U2FsdGVkX18ZMxE7gyIcvU9Ur8IOAbhW6wARkukFkk8jM4a/95kJ1hRuiWcXQluIpDEb+ZN1SZ7VJgDBXgQ3Cd33Val1tPEM7+D9o0h++gTKTUa8jBANZ1IStDjx/rD4nLMxMGn9GHOihWv5VyikrMU2UVYIJkt71xSPIW1pMvap8gmRYfRXCJ6SyRB7YR1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aQcviLEdJuZObfePrGOHl/vAGvV8GTxJyiGtgjWzf4P8WL+hsOvXu5wWfcQZh1JtqPJIRU2jBv2NYPWDXJqvaU1l6yx1RZvHPA1KyaGaLAqOtT5bUqjn1foF36j5odufv78N/TGIBELbexAefm+ob5G/58q8ZWaXsa2suATmflcgz6tbv2qy1hoZYPNhIMV62dsRtvHoyLh+95yTMBrw9S5jQdLK9nWCNzvHDddNLkOFbBDlJpKvdzQHc5H6aCA+bMnDaVNadIJftx6+ch93KZjh4fFH5nJXg== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Baoquan He Add a build-time default for the size of a new xswap device. The value can be a percentage of RAM, a size in bytes, or "max". "max" means the largest size the device can address. xswap.max= on the command line overrides this default. The build-time default is clamped to the device limit. An explicit xswap.max= that is too large is refused. If the build-time default cannot be parsed, or is a byte size below one cluster, use 200% instead. A percentage default can still be below one cluster after RAM is known. In that case, device creation fails. Signed-off-by: Baoquan He --- .../admin-guide/kernel-parameters.txt | 6 ++-- mm/Kconfig | 11 ++++++ mm/swapfile.c | 34 ++++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2b0fc585e0c7..2a28aaa3cb32 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -8736,8 +8736,10 @@ Kernel parameters off xmon is disabled. xswap.max= [KNL,SWAP] - Maximum size of a new xswap device. The value is a + Maximum size of a new xswap device, which is created + with swapon(2) and the spec "xswap". The value is a size in bytes with an optional KMGTPE suffix, a percentage of RAM, or "max" for the largest size - the device can address. + the device can address. The default is set by + CONFIG_XSWAP_DEFAULT_MAX. Format: [KMGTPE] | % | max diff --git a/mm/Kconfig b/mm/Kconfig index d238a4971b1e..16958240a066 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -131,6 +131,17 @@ config XSWAP array is backed by a sparse vmalloc area that is mapped lazily in chunks, avoiding static pre-allocation overhead. +config XSWAP_DEFAULT_MAX + string "Default maximum size of a new xswap device" + depends on XSWAP + default "200%" + help + The maximum size of a newly created xswap device. It accepts a + percentage of RAM (for example "200%"), a size (for example "2T"), + or "max" for the largest size the device can address. + + xswap.max= on the kernel command line overrides this value. + config ZSMALLOC tristate diff --git a/mm/swapfile.c b/mm/swapfile.c index 6ce5dbb3b103..074c5114d129 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -77,9 +77,9 @@ static int xswap_destroy_by_name(const char *name); static DEFINE_MUTEX(xswap_ctl_lock); /* - * Size of a new device: xswap.max= if given, otherwise the built-in - * default. A percentage unless bytes is set; "max" asks for the largest - * size the device can address. + * Size of a new device: xswap.max= if given, otherwise + * CONFIG_XSWAP_DEFAULT_MAX. A percentage unless bytes is set; "max" asks + * for the largest size the device can address. */ static unsigned int xswap_size_pct = 200; static unsigned long xswap_size_bytes; @@ -87,9 +87,12 @@ static bool xswap_size_max; static bool xswap_size_set; /* xswap.max= was given */ /* - * Parse "200%", "2T" or "max". @str is not modified. + * Parse "200%", "2T" or "max". @str is not modified. @cmdline tells an + * explicit xswap.max= from the build-time default, which is clamped + * instead of refused when it is too large. */ -static int __init xswap_parse_size(const char *str, const char *what) +static int __init xswap_parse_size(const char *str, const char *what, + bool cmdline) { const char *pct; char buf[16]; @@ -118,12 +121,16 @@ static int __init xswap_parse_size(const char *str, const char *what) bytes = memparse(str, &end); if (*end || bytes < PAGE_SIZE) goto bad; + /* A default below one cluster would fail every create. */ + if (!cmdline && bytes < (unsigned long)SWAPFILE_CLUSTER * PAGE_SIZE) + goto bad; xswap_size_bytes = bytes; xswap_size_pct = 0; xswap_size_max = false; } - xswap_size_set = true; + if (cmdline) + xswap_size_set = true; return 0; bad: pr_err("xswap: bad %s=%s\n", what, str); @@ -132,7 +139,7 @@ static int __init xswap_parse_size(const char *str, const char *what) static int __init xswap_max_setup(char *str) { - xswap_parse_size(str, "xswap.max"); + xswap_parse_size(str, "xswap.max", true); return 1; } __setup("xswap.max=", xswap_max_setup); @@ -4175,11 +4182,7 @@ static int setup_swap_clusters_info(struct swap_info_struct *si, } #ifdef CONFIG_XSWAP -/* - * Create the file-less xswap device, sized by xswap.max= or the built-in - * default. Called from swapon(2) with SWAP_FLAG_XSWAP; there is at most - * one device per system. - */ +/* Create the file-less xswap device from swapon(2). */ static int xswap_create(int prio) { struct swap_info_struct *si; @@ -4694,6 +4697,13 @@ static int __init swapfile_init(void) { swapfile_maximum_size = arch_max_swapfile_size(); +#ifdef CONFIG_XSWAP + /* xswap.max= on the command line overrides the build-time default. */ + if (!xswap_size_set) + xswap_parse_size(CONFIG_XSWAP_DEFAULT_MAX, + "CONFIG_XSWAP_DEFAULT_MAX", false); +#endif + /* * Once a cluster is freed, it's swap table content is read * only, and all swap cache readers (swap_cache_*) verifies -- 2.54.0