From patchwork Thu Feb 27 22:45:05 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: 13995318 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 94564C197BF for ; Thu, 27 Feb 2025 22:45:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0FB26B0099; Thu, 27 Feb 2025 17:45:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B95BB6B009C; 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 7C6D46B009A; Thu, 27 Feb 2025 17:45:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3C8FC6B0099 for ; Thu, 27 Feb 2025 17:45:16 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8EFC21A1F52 for ; Thu, 27 Feb 2025 22:45:15 +0000 (UTC) X-FDA: 83167206990.10.986CAF3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 90F00140008 for ; Thu, 27 Feb 2025 22:45:13 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ReviaM9y; spf=pass (imf26.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; 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=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=amRfIu7egDuh2gQT2LLaey0nNPyqBorglSAqnFUklxU=; b=qQ0JrcZL57sJOEOH8jYxO+rW7wRkKPzrmdayN34okxAWbTusTaTrLyjokIztfdYI8gBu0D yg37oQOjMN+lpt4yBppaOdU9IIlYNVPMlPKtUC3mUB8S+SfiQzaE9pcuYNe1tpraKc+tNS 4XlXNKkrCJzGsBY/vwAEkuDj4rL2hm4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ReviaM9y; spf=pass (imf26.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; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740696313; a=rsa-sha256; cv=none; b=byTTA2VOBi1fY5Uh6lRoiB7MDN9rhj3B/+I0XNyeV3evo4n1RZ/iky/eA2vbM3msJ7RkrR KP6wRDePSm2gKXyCyTTfKd08kRb+zeLLcQgnOqsJd/XWCcTun82hH2HIPhf0HrTeJoj/yn T2TxHidIJcjBCCE7lFyjVUpWj4SW3c8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C25875C5A2D; Thu, 27 Feb 2025 22:42:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 47134C4CEE5; 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=oJkzUc1eO6G6pDf5SWNcF21d4R6h8JEKsl5niSERdXM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ReviaM9yL+36eqR29e6Vy+s7kRMgf6UR2DuPXer6kYpF66TbEH8IrrMV/pIKDRZgQ uxWGq/oaUO4smsW4N8sgNwJ/kzKWuFe4PgYWKM3M4ej2Sx4u8qSjwULkJ6zQSil0Su aJM49uQc/djfCltKu3NRTkStM8oA4D4PFi+OmLa4zdy2awpUtnW+9dexgdg74yqjxo J+/rKLyJQKOclSVXJY/mYx3y8Gzc0GIZrJlf7K0VD92zPA8i2Y0ztc06GfaVrAQFLE fcltTlj2HA+NqTuf5Mv7QneE6o4IcWlPDAcROIahDrHFUWQeobE2Icb9mV6YuVj9gX VdCaZ5LiAT0ag== 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 376BAC282C5; Thu, 27 Feb 2025 22:45:12 +0000 (UTC) From: Thomas Prescher via B4 Relay Date: Thu, 27 Feb 2025 23:45:05 +0100 Subject: [PATCH v2 1/3] mm: hugetlb: improve parallel huge page allocation time MIME-Version: 1.0 Message-Id: <20250227-hugepage-parameter-v2-1-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=3225; i=thomas.prescher@cyberus-technology.de; s=20250221; h=from:subject:message-id; bh=J38/TB8riQAZ4fzuSMdQ3k6+xa/EprG/GBf8GbXV050=; b=N4v8H7XB40hwjOeVzS9b78vwFut9BRoOByegtj+ANmDvtJNJUb0+/dyY3IgOtGis0NqPG1rj7 K9li2G7PWLgD7gQQ4vqzz3BzxbBK12dZtF1nd1XSS1XJkld/sxlzqqQ 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-Stat-Signature: gpgsxf6b33rejn4pzcgb3brtai4xp9eg X-Rspamd-Queue-Id: 90F00140008 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1740696313-980027 X-HE-Meta: U2FsdGVkX19E8jIsbk52Ddcnio8Qzoe4OVUcC3m1Km2OHtAD1jT8ePCN5LbqpVRtt3wE/kJKoz0OqtUK7rRj9OAoZ+hdfRZ8SEFYVrj6iq1XclRZ0OvR0Wi/gs7P9kwtXqg2A/xniskjohALqHS2yPx+OrLmmZzb4XYX0JxtmdklfTI1jpMoVClNRvcJ3XELA7Wj9sSRUL/YDJxr8x6iC2gMGaq7R5tLvj0g5beaqfF4CxQlvf7eptvcLlqdv7o9S12DVtVRv1ozQ181xzTMk9TCnxZglNTm5MXeOicWgpxANQfK4tCWtd+BWg6mWAhlmiD9slzG0yj0dYbc3DlpKGOoKmm1in1+Ysdxws1/DOAzDyvajUq7EjoKMfRt1hD7DHiN0ODvf9IIq7L/XGAA2Sa+L7Tm/tNE1yv5dMvvpJwEsiUHCqbQZaIUsIEh5to5eBQo6Vu8bEQpAK36/BbJjoopCGzxuu4OSveqbl13LBxbXN1ZVThWVcGdRWl6BE/EKnX0AIHzyam9zmtbiaKoNb28H6yXJF9ofq7x6iRHwci0yGB3Emf9bZOcIx5EwYl0II0YtE74Gftaf8/Ar9PYcz3iwoUTsF75uC0dSzmu3byv74DNTM2qyCf5jUlkd22cYEiAababWHWlcEZQ94pst2Bhj4eVqzcpKE3T456m7f6WmXMwWJMj+sRyQA4ulRAsZROi+QMSqI77xSisoDGM3jRfDoZsVlfVL6uLN8EDJfH2tEHUY7Q3aCXYUwF8ph6j4byUutq9QPepWuUIGBYcP0arOIcWPcCArWcN3lRR2pTMpcqbcvbaRaB08wzpW077FTxg1mhAhzmP1QJ4s+rzi3MOBvIYdtmEOdTnlINh3i32yiu36tWLFZ0IKWaxvRnjil3suH+uomwCVBaQ40+q5v5LjhF3ljsUPgOOudiNth5ukHKAV8A9R0mS7lvb7O3NZIMLD//TkvuDow3KJ5K 70Gj2SOa 1EtS2GMNUMas5R5aNjjz5rVW3PvPs6wKsFgEccJxVDA7+mmBUZ9mx7PQqQhqoRaDGK+0AZ0pysFmR/YlcRmKK1di/wf+lfZUQ0xnb4pp3Io3M2qCH1zPbC4PFjVGGCI1vAoiPFgZP19icn3Ta0XieiKnnc9WQQ2hB4vWtEQwGz8WiMS6Uc92hHAk25IebDkWH73y03A0sLWxu+SDGB2WUKCXo6+qnddgqYCfk0afU59rVImUPpGXF2xpNd5mV9Vb5WeJYSBc0lF41KI0njnYC/YkR7bJH2yDKkwPFix3QBd4dIBhPlHMSXCnIzsyMEpRHjy706M6TtOZ9RjqNU53G/IXrUp08L6GPKDVjjzcHiexXmtXzs4j4q9Qnp6rin/gz8V5QPfKdws11oWM= 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 Before this patch, the kernel currently used a hard coded value of 2 threads per NUMA node for these allocations. This patch changes this policy and the kernel now uses 25% of the available hardware threads for the allocations. Signed-off-by: Thomas Prescher --- mm/hugetlb.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 163190e89ea16450026496c020b544877db147d1..e9b1b3e2b9d467f067d54359e1401a03f9926108 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -14,9 +14,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -3427,31 +3429,31 @@ 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; /* - * job.max_threads is twice the num_node_state(N_MEMORY), + * job.max_threads is 25% of the available cpu threads by default. * - * Tests below indicate that a multiplier of 2 significantly improves - * performance, and although larger values also provide improvements, - * the gains are marginal. + * On large servers with terabytes of memory, huge page allocation + * can consume a considerably amount of time. * - * Therefore, choosing 2 as the multiplier strikes a good balance between - * enhancing parallel processing capabilities and maintaining efficient - * resource management. + * Tests below show how long it takes to allocate 1 TiB of memory with 2MiB huge pages. + * 2MiB huge pages. Using more threads can significantly improve allocation time. * - * +------------+-------+-------+-------+-------+-------+ - * | multiplier | 1 | 2 | 3 | 4 | 5 | - * +------------+-------+-------+-------+-------+-------+ - * | 256G 2node | 358ms | 215ms | 157ms | 134ms | 126ms | - * | 2T 4node | 979ms | 679ms | 543ms | 489ms | 481ms | - * | 50G 2node | 71ms | 44ms | 37ms | 30ms | 31ms | - * +------------+-------+-------+-------+-------+-------+ + * +-----------------------+-------+-------+-------+-------+-------+ + * | threads | 8 | 16 | 32 | 64 | 128 | + * +-----------------------+-------+-------+-------+-------+-------+ + * | skylake 144 cpus | 44s | 22s | 16s | 19s | 20s | + * | cascade lake 192 cpus | 39s | 20s | 11s | 10s | 9s | + * +-----------------------+-------+-------+-------+-------+-------+ */ - job.max_threads = num_node_state(N_MEMORY) * 2; - job.min_chunk = h->max_huge_pages / num_node_state(N_MEMORY) / 2; + + job.max_threads = num_allocation_threads; + job.min_chunk = h->max_huge_pages / num_allocation_threads; padata_do_multithreaded(&job); return h->nr_huge_pages; 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; From patchwork Thu Feb 27 22:45:07 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: 13995315 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 A2D35C197BF for ; Thu, 27 Feb 2025 22:45:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E6A16B0096; Thu, 27 Feb 2025 17:45:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 248DB6B0095; 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 0E9C26B0099; Thu, 27 Feb 2025 17:45:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E19E56B0095 for ; Thu, 27 Feb 2025 17:45:15 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 85B58161E2F for ; Thu, 27 Feb 2025 22:45:15 +0000 (UTC) X-FDA: 83167206990.08.B931924 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 9A1001C000D for ; Thu, 27 Feb 2025 22:45:13 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AIbWNI1f; spf=pass (imf18.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; 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=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=O3O7IJEBWl1XTrIboq+ErJhtutQe+8/VefZCguVdJhY=; b=SYAf1AqWcIEU3c6W91sb7UU97YRFtTQUvzA8FcjFgvMk5rjDuJJCTY1ExtnOrtpQbm9wiB oFuRHbpI30TURdffkd8F/avrKulEiiBZI2P9IwzJnD6fN24GvlcYuFeqUNw2YCEeqRyGDU HMjGHWT7r7B2egtKbtJkklCp9T1D9Ss= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AIbWNI1f; spf=pass (imf18.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; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740696313; a=rsa-sha256; cv=none; b=eDHKJTmtTF3T7dMd8sY10TAb8tulwGmToLfkDBcZM6hL4YXEemuV+ixM8rVjNqpUwCyfHh EMAoHl8GA/RmOeI/PP5eiMOaWAsvjEhCmBN9JWbCt+1cWocQ7piWc7COoqPe0eaEA/JwII aGIep8nskPsz4GWGnUszZGcJj+tsCZk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E00F25C5B10; Thu, 27 Feb 2025 22:42:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 64B26C4CEE8; 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=5VUaBxuG5jp6oEMwAW0wKmDoN3rdkjGw0TFuNrg+m+s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AIbWNI1fPa7uLDSTJHqb+aMq4O2v6EjYleUo/trN0mvO5DnibejG3dT2HjLPaepFh ZnhsEQ30ZZY3pM+5p/thRs9BPloJHBRZCkBn3MrAT3SHlGPFMgHk5Dm7yzRk0LHL0A 09R8dO5+S/4hunZS+zMlzRzgx4xeWNjnnLoIa9ZsiNBDr1zAaa3ySW6AFgtpFvNb2f uHRzYoTjAEDOJrv/dqXNVTK09k2kwBOFcrQLuZVeR3kl9RzFrpDzRocxIx0kM+P6Gm w0SP2VSrM8qfJkHEigWSVyOucD4I05vdGilmSj4S7exw+CdeWNlNC5Jjkgc72cSLp2 M19qkLV2KER4A== 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 56AA5C282C7; Thu, 27 Feb 2025 22:45:12 +0000 (UTC) From: Thomas Prescher via B4 Relay Date: Thu, 27 Feb 2025 23:45:07 +0100 Subject: [PATCH v2 3/3] mm: hugetlb: log time needed to allocate hugepages MIME-Version: 1.0 Message-Id: <20250227-hugepage-parameter-v2-3-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=1238; i=thomas.prescher@cyberus-technology.de; s=20250221; h=from:subject:message-id; bh=DnQm/ufrOp5KRhZift3qcnZk9CLmrzaedzUcrpSfRg8=; b=7/+8mcgFy1AHR3tc4v90RSb52SvqhIl5u321vKgF5hXYbL35rYRH5EJuWaxQKtZBEANJ4FLsE GApQqF2DaSKBUdDMSL2HpAgAZcgZL7SlkW9ZTzWOBBtKUR8eUEF7l+i 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-Queue-Id: 9A1001C000D X-Rspamd-Server: rspam09 X-Stat-Signature: g3amk7oyxih678bx9b94kht1zmkuc4jp X-HE-Tag: 1740696313-556032 X-HE-Meta: U2FsdGVkX1/PEmz1MtTEXgGcvfPqGlVFo0aSb1+p93CFUec1XRx9U6QJtM4C/3oSvJi8Ddnf9GTtlg6m/bhNdgGzWqoAXRGwPH0b4hAaZq8fKAOC/2/2QxOMXSSH0m/IMLVdwBYFxx8rSw3xYi1wDOqfFbl2Ah2n/ohzHzALgjbNgZT5tBQI3I4SJoikJ8pVsq9gGQML+xmNu1PYTiyeQwr/PHPEYy5d7I7jDo+LVtLvRf4clNmteQsqmPEtYeIUQC5InFLXjTYuTDxT6gG4cWBgJxrCoC9D7NOfLJ65HA94qf5b1Wqw6oEONxt73im8GtDoIZ+GUcn1gLVoVzAWF3xAacYDzoaHQZz/4/9g6uPsperL4DgMC13+ifZGqjouwfbMoipVbZ1VBASHrbx3e0DeZaDmatRJa2bZiwvDQU9wrWulzN/lNEcrjGSrQNlGgaYR/OSgTQ5ikR6ajW24+cyt+XaqOTtRiv23ifUZoW8ruBRmGmdJmm2V1C0k3Iwqt39kmNnmTkLelUyqtMD821zlFusmMGvb3V2IAyA4OlEAWmPP2uZiktZEWYZsi3WiM4+pQxR/fbg+dSGC9vqYrvyS2Zc0g9wa5lHnxneIb9IW1PV5+9glyjKrAfXniTOSPz/xOjfTVX+azfa9DwHnirSWnVGpXFr4dVhLMrw8Cr6b37km8fGngKz6W9Irb+7Bx3O3e6tqUQTeT5/pDwLAKam3YeXP+CsPatTqjSbhDwTRmeCh2FpW36BhQLjUuOsqz6PiguBMCgKSrTkJw1Xoa03XSbgTH3WBp0pFus/8Xch2TchfzCTIcWyAcIyePRWRKc3/VznSY9vUh/F2vNlfHXKZSwT3VXrzOQqhYAlgVy9BTdoPJvK0Xu6EXWlBAGoKQS3rX1vj1Mf1VqxcR42XP57VGT6WGggbqQ0+ZVB+9DSw02evmALheoy3I6nhhBScAwyoMhqhJxoCVFDlifl khRvLTyj bFiMBEtG7XLER4GhYUPQrV19MgQOZse1HmgWS7VNMdaRJmXop6xob7G1aKQIfbxuHmdm5vIud80fYUnD699+GZJqttlPV1wczzIjXzOvLYmASyFUu0uc5+VkbeGCyCCiqwL1xxDavVQvOwnZ+6qH5InFgJaz1ji+HI2mHlAWVwGHQ5qbZShd7SPN+jgQRy4Z85qYmzzzDilpo52ekbXXmWFSr4hLpEkXr21dxNb3XipZl2j7MaXQ6jL+T7fPa0tYL42J5utuzMddEnnqId+lpZse1gnG4IWFRzzG3QMKdqx0uAKy3ZHVzSxbY6gEutYpibTUzIaPV92DFGvfJ2onbVCDHr4oNQRoIulH4uZQAP5SEDdggQxXJDlrTZX4SH+bLOnMQQh1TC9H+0jQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000074, 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 Having this information allows users to easily tune the hugepages_node_threads parameter. Signed-off-by: Thomas Prescher --- mm/hugetlb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 98dbfa18bee01d01b40cc7c650cd3eca5eae2457..373b6ac4a3824555f91ad9895e66f631f6e1ba82 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3430,6 +3430,9 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) .numa_aware = true }; + unsigned long jiffies_start; + unsigned long jiffies_end; + job.thread_fn = hugetlb_pages_alloc_boot_node; job.start = 0; job.size = h->max_huge_pages; @@ -3457,7 +3460,14 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) job.max_threads = hugepage_allocation_threads; job.min_chunk = h->max_huge_pages / hugepage_allocation_threads; + + jiffies_start = jiffies; padata_do_multithreaded(&job); + jiffies_end = jiffies; + + pr_info("HugeTLB: allocation took %dms with hugepage_allocation_threads=%ld\n", + jiffies_to_msecs(jiffies_end - jiffies_start), + hugepage_allocation_threads); return h->nr_huge_pages; }