From patchwork Thu Feb 27 22:45:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Prescher via B4 Relay X-Patchwork-Id: 13995316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00E6EC282C5 for ; Thu, 27 Feb 2025 22:45:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56FED6B0095; Thu, 27 Feb 2025 17:45:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 49A046B009B; Thu, 27 Feb 2025 17:45:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D20128000E; Thu, 27 Feb 2025 17:45:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E8D276B0096 for ; Thu, 27 Feb 2025 17:45:15 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 88DF2B72F4 for ; Thu, 27 Feb 2025 22:45:15 +0000 (UTC) X-FDA: 83167206990.07.6D3AF16 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 8359580004 for ; Thu, 27 Feb 2025 22:45:13 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Yu/GEZ61"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of devnull+thomas.prescher.cyberus-technology.de@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=devnull+thomas.prescher.cyberus-technology.de@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740696313; a=rsa-sha256; cv=none; b=wqMGWEWt+Cql2wJorOyAsr+ul4GNC4CZdXFBo4MPgfYMDlT60yoCgH4uXEaFc+tPYYXW3g EHWNsSC19mfE4U8RD0mQVWr3WjJxt+XjU0Uj7or1nYv5dtFa1EHI4St+tdOrNbHmzxC4gI fNRmK1UeAwgEKinzOC/ymaTi4XT1iDo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Yu/GEZ61"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of devnull+thomas.prescher.cyberus-technology.de@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=devnull+thomas.prescher.cyberus-technology.de@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740696313; h=from:from:sender:reply-to: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=9CRe0X6Vq4QXUfPapsT8aUbUhPYA/5EMmJG/b3f8cU4=; b=uD0q8vVfao8WH28OExVMQADOhRpR4GeJNxgu53l3yjNqVErzOa5Y/jZ4p1rxgJqgt9VXMF VZA9ZqcQ5gzuRAOqjj2zbIlHuaOmp166uPI0sfuN96T01/DTjaxfLp7J70iIIopgAIyr/b OhMoTfFjkJoVdlQV7ObD50Twl50uQmA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D188A5C5AE7; Thu, 27 Feb 2025 22:42:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 54A56C4CEE4; Thu, 27 Feb 2025 22:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740696312; bh=grcGQ/+arIlEAKZaRyhVKHEzoTjlNo07p6Orhu/Q7Hc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Yu/GEZ618qIdVI9fNOp4LWX9V7t/yjYm1X/HvO72knF+KqiNnVdNVrMtnLprDzrQb QqeFYBPHiDFFcAc24JUyd7VyEKnL+IheGZZ/Tcb3Mcic05lmFC4y/tY5bOxyvhzGy7 PSGzcDLhgNMUYtQhv9xqxOwYXBvOJ2o4yXOXL0zUlnEUJhFwM5IQD3PgsmAPc6ECfA UxkIJSfGxcrsF3JW2mRmqwlSDB3MeUXMpIaWEdSEY+IQgfwF9aE+uswx7ANJHTpSs2 odFzmHlR+YwQI/UU3cQRWzVnay86gl+aYULTzIOaWFwsZNsNhKKRzVzM094RBHEcGU rkxhxqlmKbBYg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4923CC197BF; Thu, 27 Feb 2025 22:45:12 +0000 (UTC) From: Thomas Prescher via B4 Relay Date: Thu, 27 Feb 2025 23:45:06 +0100 Subject: [PATCH v2 2/3] mm: hugetlb: add hugetlb_alloc_threads cmdline option MIME-Version: 1.0 Message-Id: <20250227-hugepage-parameter-v2-2-7db8c6dc0453@cyberus-technology.de> References: <20250227-hugepage-parameter-v2-0-7db8c6dc0453@cyberus-technology.de> In-Reply-To: <20250227-hugepage-parameter-v2-0-7db8c6dc0453@cyberus-technology.de> To: Jonathan Corbet , Muchun Song , Andrew Morton Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Thomas Prescher X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1740696310; l=4838; i=thomas.prescher@cyberus-technology.de; s=20250221; h=from:subject:message-id; bh=/OuX4vllZ9DrhNgACxdiUGULgJjK6Nnwd9N61kSfqhA=; b=phN1XnqYkdqDin5Z8AuIutKHz9rkc22/78FuumN1xbawpdcPxzrzUFrB3Ztmu9nN7DoTG9aKM lNG0g3p9CpAAFn2gED78eQwXk7spRaq5UfjPCafLAHZmvdmRglb2Clf X-Developer-Key: i=thomas.prescher@cyberus-technology.de; a=ed25519; pk=T5MVdLVCc/0UUyv5IcSqGVvGcVkgWW/KtuEo2RRJwM8= X-Endpoint-Received: by B4 Relay for thomas.prescher@cyberus-technology.de/20250221 with auth_id=345 X-Original-From: Thomas Prescher Reply-To: thomas.prescher@cyberus-technology.de X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8359580004 X-Stat-Signature: pyimdk9w4ppp3grp8jgwa6n4skyuoqmh X-HE-Tag: 1740696313-145032 X-HE-Meta: U2FsdGVkX19fsuSMnefOM6LGdqlPtskIRBV7mUhRueuoaq9egvg2490NKWbDqkHk3uNFnxe1f9jb1AIVFRVtG5jW+lJPWtwIYpCCizDvC/aDu06WRzUfSjvuSKJ8lPTZrzMHa1yVN++hSBrQj5n012RQxWwfCaxGaMcsOPs7t3zof86vTgA9x5KH8/iGuSxKEh5yy86K1FLqe7+SuXpHQCPgB1LrQvisJn+7SjY0UkIS4M8Z+5y6PWaJaVhm3lmDrurx/+w7CGn2ixp1bNytu8wn7DE6IrosE20Bsxn84sMd7kj3bCkCNXD4iCM5MJqt2rAoRSECYndEjLB81BsJIzg7ULM5T1PPNDXVZwY1ai1ZllfJ1nv80gGmqgIKfZp81CYt6E4RcVSLydPcERuDEl6jP6gx6g4l2oFZOmN0eKfp53YGuUIET4sMUw2ILfE4TFq7PKkze8/MolbavwKxlxScj6RMFhCbajMzFxPKTFaES1t2SD4AvX8ZPhb8aMoyss7smLdaLx2BuNpHWUbt+puYvbPYTnpwz3+apN7i1DeeMNgxdsExNFLT3ji1pQ0SNmiz6obn4LhxVtw3v6gA9gLExV6NhHk5jcGEQUZGuVDUDd4vY0qzATLIsQ/fLwBu96/EySnd0vI+1h8+tM/tV4btsthfL8DUS1/GjTJsP5TOwQJI95GnLYYBc8G3/xoOxCyiX/3oO9QwYhydGU9eM5ttkkYki3tifT3FOwj+yF9W3Bl3ABXUm8zvR0Tj5IsEZD3XMkX2ZV7zHnGUBw6ezgrvfL0IhtFP/meEUVPomaZXmGL9l5U0+45bY4rwnBr4EboNrTsX0Y9uMn7y+H1VmLgSqpiYa/B4rNMvcbdsHlU3SlsjmwbJP0SyAdNfewufsPhMmfmtUZjAyuFmy6S3qyDpAkr9At6rOoh1INRsCqlHbXOzirKpAnSBFBg/64/3FCdzZ69ThNJyxrEe8rY Ra8wMK3+ H4jPF5yy93Sw1KrRzEqhq7E2JrgKC7Rma8cPB6CNrqMjkqsU+rkuT+FfLJyp03lh4cZEt6WbWFLGJ0Rdm60y65bb8pRUdpPzeWYwWNUeuWlkJWgoX17fKtL5bU3lVudOk/AurecI/4SPVS/COP9xC3ePn/IqkjFfDSgtAYI7StjBsrhunl4gIzVv0Z+FOFMU9KJA8icD99XIcq5xPFNKag/UJAsWtdw1Sb/rLfGh/ICHCurBQYFeQlqylkwu3QKgo7w9+Pzf1e5A7GoSiqXsFUzBwKIflLlXiKO2DcKyPLPpmgILvd7+XVuncI7scAO9wXeRKawqeP3kF0Qoxj2nHs3bQYyBkc8yGcyyjR7pMi1p47vx/PiVw9WjTd9pPvTVJ+4xBdGNb/Db78btwzij6FMpYEPwrEkzRWE7YKYObKe7QO9/iwjy3S4rfl2F/HQ70HHhh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Thomas Prescher Add a command line option that enables control of how many threads should be used to allocate huge pages. Signed-off-by: Thomas Prescher --- Documentation/admin-guide/kernel-parameters.txt | 9 +++++++ Documentation/admin-guide/mm/hugetlbpage.rst | 10 ++++++++ mm/hugetlb.c | 31 +++++++++++++++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index fb8752b42ec8582b8750d7e014c4d76166fa2fc1..1937ee02c1f883ecd910bab33cdb9194bddbd9b1 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1882,6 +1882,15 @@ Documentation/admin-guide/mm/hugetlbpage.rst. Format: size[KMG] + hugepage_alloc_threads= + [HW] The number of threads that should be used to + allocate hugepages during boot. This option can be + used to improve system bootup time when allocating + a large amount of huge pages. + The default value is 25% of the available hardware threads. + + Note that this parameter only applies to non-gigantic huge pages. + hugetlb_cma= [HW,CMA,EARLY] The size of a CMA area used for allocation of gigantic hugepages. Or using node format, the size of a CMA area per node can be specified. diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst index f34a0d798d5b533f30add99a34f66ba4e1c496a3..67a941903fd2231e6c082cffb4c9179ee094b208 100644 --- a/Documentation/admin-guide/mm/hugetlbpage.rst +++ b/Documentation/admin-guide/mm/hugetlbpage.rst @@ -145,7 +145,17 @@ hugepages It will allocate 1 2M hugepage on node0 and 2 2M hugepages on node1. If the node number is invalid, the parameter will be ignored. +hugepage_alloc_threads + Specify the number of threads that should be used to allocate hugepages + during boot. This parameter can be used to improve system bootup time + when allocating a large amount of huge pages. + The default value is 25% of the available hardware threads. + Example to use 8 allocation threads:: + + hugepage_alloc_threads=8 + + Note that this parameter only applies to non-gigantic huge pages. default_hugepagesz Specify the default huge page size. This parameter can only be specified once on the command line. default_hugepagesz can diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e9b1b3e2b9d467f067d54359e1401a03f9926108..98dbfa18bee01d01b40cc7c650cd3eca5eae2457 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -70,6 +70,7 @@ static unsigned long __initdata default_hstate_max_huge_pages; static bool __initdata parsed_valid_hugepagesz = true; static bool __initdata parsed_default_hugepagesz; static unsigned int default_hugepages_in_node[MAX_NUMNODES] __initdata; +static unsigned long hugepage_allocation_threads __initdata; /* * Protects updates to hugepage_freelists, hugepage_activelist, nr_huge_pages, @@ -3429,8 +3430,6 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) .numa_aware = true }; - unsigned int num_allocation_threads = max(num_online_cpus() / 4, 1); - job.thread_fn = hugetlb_pages_alloc_boot_node; job.start = 0; job.size = h->max_huge_pages; @@ -3451,9 +3450,13 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) * | cascade lake 192 cpus | 39s | 20s | 11s | 10s | 9s | * +-----------------------+-------+-------+-------+-------+-------+ */ + if (hugepage_allocation_threads == 0) { + hugepage_allocation_threads = num_online_cpus() / 4; + hugepage_allocation_threads = max(hugepage_allocation_threads, 1); + } - job.max_threads = num_allocation_threads; - job.min_chunk = h->max_huge_pages / num_allocation_threads; + job.max_threads = hugepage_allocation_threads; + job.min_chunk = h->max_huge_pages / hugepage_allocation_threads; padata_do_multithreaded(&job); return h->nr_huge_pages; @@ -4766,6 +4769,26 @@ static int __init default_hugepagesz_setup(char *s) } __setup("default_hugepagesz=", default_hugepagesz_setup); +/* hugepage_alloc_threads command line parsing + * When set, use this specific number of threads for the boot + * allocation of hugepages. + */ +static int __init hugepage_alloc_threads_setup(char *s) +{ + unsigned long allocation_threads; + + if (kstrtoul(s, 0, &allocation_threads) != 0) + return 1; + + if (allocation_threads == 0) + return 1; + + hugepage_allocation_threads = allocation_threads; + + return 1; +} +__setup("hugepage_alloc_threads=", hugepage_alloc_threads_setup); + static unsigned int allowed_mems_nr(struct hstate *h) { int node;