From mboxrd@z Thu Jan 1 00:00:00 1970 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 39D88C47DDF for ; Fri, 26 Jan 2024 15:25:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C506E6B009A; Fri, 26 Jan 2024 10:25:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BFFB16B009B; Fri, 26 Jan 2024 10:25:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1776B009C; Fri, 26 Jan 2024 10:25:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9709C6B009A for ; Fri, 26 Jan 2024 10:25:41 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6DD0BA08CC for ; Fri, 26 Jan 2024 15:25:41 +0000 (UTC) X-FDA: 81721836882.28.36F0557 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by imf02.hostedemail.com (Postfix) with ESMTP id C7F5E80018 for ; Fri, 26 Jan 2024 15:25:39 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qwIcy4O8; spf=pass (imf02.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=gang.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706282740; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jedycsf2hoazZl2VD5dKzn3Ogz/yNT2KcxNdOLYavB4=; b=j8MbZRWsymfKxc6fFceY0Auk8+zr9TjNXMBqJ4Gzpert2dQKj7p1028B5b9DhKXtaS+Gyt dZBYIve0WMw98ehMzDiUKkL4w2TVocFgVFcxz6blLEhNgBwxc2I6S4/Bt7BNAf9iRGGDKA pR6KJcgaQ3uYNYjj3vLKWu161WJZoZY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qwIcy4O8; spf=pass (imf02.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=gang.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706282740; a=rsa-sha256; cv=none; b=G8z/EnpUUIS5ngZ35iViDr5rW8/Zv7vWEVfDvkABmyWrDgnyG+aDlDNt46mvjftSH5Gsv6 Oppf39dAEHcYrBsCoszt6c0+Xl3NMp9p2s0mTXi2T4GqPsSunkdsywjx35TzvanLMq2sCn 5A+VchaYNRioVcC5WnVEULYdPcn8nh8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706282738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jedycsf2hoazZl2VD5dKzn3Ogz/yNT2KcxNdOLYavB4=; b=qwIcy4O8oYc6ieAe8OwvpEKH4wyBee3Jlif+nxuPJKFmuXp+E3oYFgTjBUsVhVcTbe3PJO LbG1Yp4MWWpIydaJlX5rrJfhgvOcuD2EKuJO/Yme8P9fG6DM1ACjVdMyPO1FZ4Ag0JyV0D a0k79BNlAPNr4wc8ZdQcdQUIK48SoXc= From: Gang Li To: David Hildenbrand , David Rientjes , Mike Kravetz , Muchun Song , Andrew Morton , Tim Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [PATCH v5 6/7] hugetlb: parallelize 2M hugetlb allocation and initialization Date: Fri, 26 Jan 2024 23:24:10 +0800 Message-Id: <20240126152411.1238072-7-gang.li@linux.dev> In-Reply-To: <20240126152411.1238072-1-gang.li@linux.dev> References: <20240126152411.1238072-1-gang.li@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: C7F5E80018 X-Rspam-User: X-Stat-Signature: y3j3w1s1m9qgq1m6x57u6iyqgqysbwk4 X-Rspamd-Server: rspam01 X-HE-Tag: 1706282739-832883 X-HE-Meta: U2FsdGVkX1/57Amtu9DdR+il36ZgXybuX3qLtMOpnQBIdQ+kltLrvOQJERzJlzanpTzw0CpkrQChA7jhtxBhMFHduuZLyjlLH8M/HglAE3nTjdx1KsIs0jzBK+fok87ZeNS11k3wEUQYfurN3FPSr2Byfwg1i2CZrn7IDfadvkkoNItHxtrax6Et2ld4VMyniI/bRKrLeG4th4Yw2tkjGCzXDpCsNMbRYlZCJcHVkhOLlMiDpESuUuUvqf24N/VS7m4UHxVU6b9f23V/csL7nj3n8AaiN1xeXLoe4VqFQ2sinXlDsW5i02hQ7n45/xXCDsDw6kOPhLiys2BWw2RS2rETDZ8Nn+ePw8+TZEsDw58F54Qg8Um6hl7H64IoaLsmTuevNZI/OqYfM2CF4xqwRSKpUIrmf11ox3agzbuXBHVt3e5IirNgAaPT695K2ZR649mrORHqM5YbtLQlw5oVFQp2vbJti9ectYQGNm7H6TXL3w4IKw6NC+jmUu/I6ZJd7Xb55rK5W6Ah+5rQzrLDFJzq4aSIcVPjnbRO13kYl2/Ixf1cUGshJM6ojMzgDldxIk1XWGT1P+OIPN/7kx6qrZiaughH2qBcZ3uL2ofRL5m3eviKX+sXBHHqiNP3kO8UqL8zGIDsnFsEuytitxYpHycvrm+5qXGCwVQjjqriOlkm0F9gXU5T608EhqU1tO5Jm1RItueLs/SiJZkzO/6IfkL18uRcOgRis9nxoFR9KTK2RAzoY59jeBGFaXf9cR55Qi50cQZ0nU7HsXcvTJN7bYK0fe99rEZV1dTaoAAqJHHl26JsPLI/p0iph2TqUbYGq/pT9k2f4Gg4dmaIsUNBUQ== 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: By distributing both the allocation and the initialization tasks across multiple threads, the initialization of 2M hugetlb will be faster, thereby improving the boot speed. Here are some test results: test case no patch(ms) patched(ms) saved ------------------- -------------- ------------- -------- 256c2T(4 node) 2M 3336 1051 68.52% 128c1T(2 node) 2M 1943 716 63.15% Signed-off-by: Gang Li Tested-by: David Rientjes --- mm/hugetlb.c | 73 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e4e8ffa1c145a..385840397bce5 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -3510,6 +3511,30 @@ static void __init hugetlb_hstate_alloc_pages_errcheck(unsigned long allocated, } } +static void __init hugetlb_pages_alloc_boot_node(unsigned long start, unsigned long end, void *arg) +{ + struct hstate *h = (struct hstate *)arg; + int i, num = end - start; + nodemask_t node_alloc_noretry; + LIST_HEAD(folio_list); + int next_node = first_online_node; + + /* Bit mask controlling how hard we retry per-node allocations.*/ + nodes_clear(node_alloc_noretry); + + for (i = 0; i < num; ++i) { + struct folio *folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], + &node_alloc_noretry, &next_node); + if (!folio) + break; + + list_move(&folio->lru, &folio_list); + cond_resched(); + } + + prep_and_add_allocated_folios(h, &folio_list); +} + static unsigned long __init hugetlb_gigantic_pages_alloc_boot(struct hstate *h) { unsigned long i; @@ -3525,26 +3550,40 @@ static unsigned long __init hugetlb_gigantic_pages_alloc_boot(struct hstate *h) static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) { - unsigned long i; - struct folio *folio; - LIST_HEAD(folio_list); - nodemask_t node_alloc_noretry; - - /* Bit mask controlling how hard we retry per-node allocations.*/ - nodes_clear(node_alloc_noretry); + struct padata_mt_job job = { + .fn_arg = h, + .align = 1, + .numa_aware = true + }; - for (i = 0; i < h->max_huge_pages; ++i) { - folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], - &node_alloc_noretry); - if (!folio) - break; - list_add(&folio->lru, &folio_list); - cond_resched(); - } + job.thread_fn = hugetlb_pages_alloc_boot_node; + job.start = 0; + job.size = h->max_huge_pages; - prep_and_add_allocated_folios(h, &folio_list); + /* + * job.max_threads is twice the num_node_state(N_MEMORY), + * + * Tests below indicate that a multiplier of 2 significantly improves + * performance, and although larger values also provide improvements, + * the gains are marginal. + * + * Therefore, choosing 2 as the multiplier strikes a good balance between + * enhancing parallel processing capabilities and maintaining efficient + * resource management. + * + * +------------+-------+-------+-------+-------+-------+ + * | 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 | + * +------------+-------+-------+-------+-------+-------+ + */ + job.max_threads = num_node_state(N_MEMORY) * 2; + job.min_chunk = h->max_huge_pages / num_node_state(N_MEMORY) / 2; + padata_do_multithreaded(&job); - return i; + return h->nr_huge_pages; } /* -- 2.20.1