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 0CB70606A32D for ; Thu, 3 Dec 2026 16:44:58 +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=KLahZiu/ Received: by kanga.kvack.org (Postfix) id 17B156B05C3; Thu, 3 Dec 2026 11:44:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 152BC6B05C4; Thu, 3 Dec 2026 11:44:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 067F26B05C5; Thu, 3 Dec 2026 11:44:41 -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 59FB56B05C3 for ; Thu, 3 Dec 2026 11:44:40 -0500 (EST) Received: from smtpin22.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E63EF1A014A for ; Thu, 3 Dec 2026 16:44:38 +0000 (UTC) X-FDA: 85503245436.22.6EC9C2A Received: from mta0.migadu.com (out-92.mta0.migadu.com [91.218.175.92]) by imf16.hostedemail.com (Postfix) with ESMTP id DB87518000E for ; Thu, 3 Dec 2026 16:44:36 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="KLahZiu/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.92 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=1796316277; b=P3UwnaoId8Aab7fFj/gU/iUAsW33LbawvkNouKcV5Fb8IncH6/pb78MwK5cTgrd4l70hE1 gkWY3C4bfsRnLAmvzxs+W6+Jdc1RPtOcixjqAInNw847MVtVupVtgPMhVjqKGhmj93mHES yqsEXBjlReHcnKTl5QPL1VFRjmaFXXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796316277; 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=BsjwaAiMMr6PEePl3SuMlrdxbOgPisjXbjwmhH2rV8haJNEndq3Y1s8dBLtTCt42RZINuR KUSzzkupSt3Mn7yjsQYXCZpm1Npjdzzqf6jrPKLkpGufm5KCHySsXsU75ecvDOvxkDPpyC be04b2ym4KHY+U1+hyrr6k6l3Kd+EbE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="KLahZiu/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.92 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=1796316275; v=1; x=1796921075; b=KLahZiu/DpZIoyejpklcwxke0LL7V9IQJpQR3hhvHW8j6QtsDRopD1UJ/SaxXqOmQwRj18BI uahZ7tejEPsfDrkHLc7fp4eFWspJ2Veb0yT0UY96Pu4qI5I7zMqCGNY4FUPy3MivJG76JIWAs3Q COjT8sxYYoqrmO2rcAcBYFIw= X-Envelope-To: linux-mm@kvack.org Received: by mta12.migadu.com with ESMTPS id 117b430bb833853b; Thu, 03 Dec 2026 16:44:35 +0000 X-Mizu-Trace-ID: 117b430bb833853b X-Migadu-Flow: FLOW_OUT From: Baoquan He To: 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@linux.dev, Baoquan He Subject: [PATCH v8 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Date: Fri, 4 Dec 2026 00:43:32 +0800 Message-ID: <20261203164336.864691-11-baoquan.he@linux.dev> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261203164336.864691-1-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Stat-Signature: pwskc8yec4xrkjbx6re6zrxag7j3rm5t X-Rspamd-Queue-Id: DB87518000E X-Rspam-User: X-Rspamd-Server: rspam10 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: 1796316276-590755 X-HE-Meta: U2FsdGVkX1+JIANOXy3ej8EAn5mDA1ztIZolOcGz7XYk/NT5NdzcbKWDoKQTzR+iL227hHUTN38P1bAeXK56SpfEg2bYBlmVyTHqpYRz7tS43cIzMKUyF5iIBG8gnU7omyWKtdj5ld4ibHjOX6Nw32U5TPvhrxTEaz7ZhsxyOib+XqTPYFB+AL5rD5yjIICvhPykjLZHC6ajVeEzGyIadT8KktwB+Ieg+jm77EqdjkJx4T6Ti7AXVd81W0tz83L0uayH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hUhFJE46RI9zZ2GkLodZZv4MQAwpWLSazlJm6Rh8rqezkcaeTZeYAZUR1gsnszU5Kx6WXPmx3WAUEcX2TXhz7DW50eujTs0tgfbbgPWFrmf6L3Bs/IoVXvuF1rbyci3F/h4NWqafT44Y1wPCTWmhqI3MQsEi+olQbGxVyBZkomPBGu83tX9KiCyEm1aSf2ubEa6ofnZAsgZczbbOAzALl+wg== 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