From patchwork Thu Feb 27 23:02:11 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: 13995330 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 A931FC19F32 for ; Thu, 27 Feb 2025 23:02:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25273280007; Thu, 27 Feb 2025 18:02:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 201A1280008; Thu, 27 Feb 2025 18:02:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05438280007; Thu, 27 Feb 2025 18:02:14 -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 DD28F280006 for ; Thu, 27 Feb 2025 18:02:14 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 780E2161DFD for ; Thu, 27 Feb 2025 23:02:14 +0000 (UTC) X-FDA: 83167249788.25.44A4863 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf06.hostedemail.com (Postfix) with ESMTP id 90414180009 for ; Thu, 27 Feb 2025 23:02:12 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bkwUvkVW; spf=pass (imf06.hostedemail.com: domain of devnull+thomas.prescher.cyberus-technology.de@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=devnull+thomas.prescher.cyberus-technology.de@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740697332; 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=59CUWP7i+mCNxahMMBgD4RIjKFQbiKDX2aruYNDbNkC7VQtctgdqLOZ6d7eby9Q1LS0ycd kq46/18I5UJqylT/ZXtzBGG8Lmvj7xCJN6WJHbXkCpjoYJzAvLSf03zvDlC9cFNYCXZMsC AaMx4DdBXlGcTIUbJdVgXRaLLJHnVzA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bkwUvkVW; spf=pass (imf06.hostedemail.com: domain of devnull+thomas.prescher.cyberus-technology.de@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=devnull+thomas.prescher.cyberus-technology.de@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740697332; a=rsa-sha256; cv=none; b=qopeS8wD5VMS/nYi6zJPM+HiTVl4kphw/rxXU5J5Z4zV1ZzWxbtgQQhIgCP1tBMSmaHoaz qN8fGsyv8hzLICVvq8QZiRMSJyRzLNaj468SWGLjRW1g2Ror5kmmgkv7cNvh5plTI6539+ mo8lPjZAelj4H78PcLF6V1lRSR9L1p4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 7530B6121A; Thu, 27 Feb 2025 23:02:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id A9FFDC4CEE4; Thu, 27 Feb 2025 23:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740697331; bh=grcGQ/+arIlEAKZaRyhVKHEzoTjlNo07p6Orhu/Q7Hc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bkwUvkVW/TEczE4myTyrmmeFtmvcTcq0Hae2JqCI4DmQvaXRWN7jaBlvQL7Cwnuso mxhIOmt56z4hlsXQNIHyWNmgiYkn91QbThCFHZ58ePNDhydglcqq/ucuoJRmLZxzUz oCp8/13smeaAae5B/yxLV42s+egNOa34MDG1Ct6zDcw0DowRAXLNd0r7ozhZrUpz/+ hHsgzYWmd4aaA6uCTCUbDNMwMKH1U4XUYXWJyE4NQ9zkong488yKq77vxD+nt6URlu ockCxJcYp0NEIV8Dh8Unp4bYIP2PSD/OyZ/JGo1W3AvWcNUKVbBX5iYJz9BKC1cOkY bVG5U7/vDlu0g== 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 9E231C282C7; Thu, 27 Feb 2025 23:02:11 +0000 (UTC) From: Thomas Prescher via B4 Relay Date: Fri, 28 Feb 2025 00:02:11 +0100 Subject: [PATCH v3 2/3] mm: hugetlb: add hugetlb_alloc_threads cmdline option MIME-Version: 1.0 Message-Id: <20250228-hugepage-parameter-v3-2-2628e9b2b5c0@cyberus-technology.de> References: <20250228-hugepage-parameter-v3-0-2628e9b2b5c0@cyberus-technology.de> In-Reply-To: <20250228-hugepage-parameter-v3-0-2628e9b2b5c0@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=1740697330; l=4838; i=thomas.prescher@cyberus-technology.de; s=20250221; h=from:subject:message-id; bh=/OuX4vllZ9DrhNgACxdiUGULgJjK6Nnwd9N61kSfqhA=; b=plgqK9FRmX14NZYx5n6BIStbjlTw2JlRsmYOuxhiFjGV95BR4FhopQxq99CpBwNWQ+78eFYmB U7Of9U+aQ3dACUsAM7MTCS3k7oh6/dFlYcEawYMIR1uou0e+RilLHoZ 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: rspam10 X-Rspamd-Queue-Id: 90414180009 X-Stat-Signature: 7i9dmz9zgbjtfh9ku4gtqkx4sxn3yz5t X-HE-Tag: 1740697332-493162 X-HE-Meta: U2FsdGVkX182YS21fRlqxLI8iS7G9OxpLjJD7XuovSo/f13tcSJ9jfEMQTMLV4oOe5mw/Q6plSlC4Wbw72x5sHi4BVtUWVCyAKaSgSftPKbqDS9dbCzKc+yPhgYpBrFGGUhvaVvvEJ/v/E8iC5CBTbJv4j7Dy97ida7jxJjNM2u69AItZFG29uGYz2iLwqi9ysTqa4PSs97IlAm1yodFDF7baPlH/n7TV95MF8CD+FD4B8RnEAsPrrbXBkVyfXetPxGy2hHI6Zndptn6TOtQu6vtVt6lYa360JHKFaq5ia1v22UGXGqyggv+7Dnnm2B8uwsXtsKvE0wpH6IZ0/gah2AOMaiUAFNNWGTXKZMcAAR5k9yvsAPsx7YtcMU9+pzcY3mCtHr48N4eDxaV2e4NYXAVRbdYwqYKUOQCjJW0buLEa0LOnCEGCmJGwyJa2RNSp2ldFghjWm2b7d+BxsBPxc7HxEPogU0ES57QcPiGdwiLcbfU9jt/1+DOxd3kcBF2WGHMCPJbOQtq9TPKEaF5Herc3rWnjvxAZFIFNPtsfFmwqaPGvvmTDsmO0Ybbzu6h7YGEUKM5AcZOlP8Gyqxn1qst03HDEw3gUJJ1XnHU/m4q21xI/G9ubws8DOxfUGuH8bXsIzw2so+3Ob4Cp7AaLopfTxGVLraqklP+IMQMO27yyM6QGDx/K8+EMtDprv2TKxScYPeZdVI4vtv0XEpVH1cyLGPz/weOUUnk2chud1bQ7rd0V6Q6YbUCPOBHY/Q3ELGOJ+C6NWUU3dzms2d7YNZS7Gj7ygBoi5IQIIPlGPRF7wnz8RArGfoBrJnWaghr9OTzlvgySjKye2zw60eq5EwhOQYpKlPrw5eiWsgA7oPfvdXdw3u/f53ojFcZzw49inrm2+r7kuseDC6/67631tEXZEzWovrRi1xWXxKVGu7xfZXSSJVAa8UNczZEkBRZccrfXaqKEunyVOeK6An 6LXBm0s0 tH3T9n7qrVOhqQymmv+f7quS1fh3yh9sYzhz8qvGttDD3PUUmPuFpEllf8fJBGODZ8aORUHoqBz0FZEE9HVJw73/QZuBB3FgMEtDesC3fLUTqqQZKG/ZyCXJL7BQ8QiDy+qTxCPyo+IwhIORe+zAx0WsyNanMJt1WR5o6QirgtSjVvMiMPqc8CFWcS7SluQN9Pgmf2hPSu965+lUA0KLjRFZBTmpghHRgTdoytGg0DZpo2WzgkjEA/0mGXDG76l/Am1knP9Dxgibu5xq9mnBjMskvBRzGPP/Dm7BHZBWM1PGiSbGARlly3mB2rCTzX4+0FEmdGUHAqQXSV74NYljasbMB3OlrYD4K4UstXRuvlO7DOyMrSQQvDjiXQpds5OZjFzr437iA9wUhOrhW0twplPFk1lA0SG8FUbTnCAJ9iaTDY9yEXsFaX8y5bcUC4a65Da8k 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;