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 8202FC48291 for ; Mon, 5 Feb 2024 07:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAB668D0001; Mon, 5 Feb 2024 02:28:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C5B966B0075; Mon, 5 Feb 2024 02:28:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4A9B8D0001; Mon, 5 Feb 2024 02:28:33 -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 A4C7B6B0074 for ; Mon, 5 Feb 2024 02:28:33 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D65D1A07F8 for ; Mon, 5 Feb 2024 07:28:33 +0000 (UTC) X-FDA: 81756922506.08.8487004 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 6141E100006 for ; Mon, 5 Feb 2024 07:28:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u9PdkuQA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.172 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707118111; 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=i/ZGvwbHuNVW/dSM5Fqd2S27/qH5458seah4OOuVqJ8=; b=QDwB5yS5ud/McrkVptAEyFRpL42Y1V9/2r5RMHbNntVX6n50LWdBZl7Z0Qi/JCb0fAuG6Y v0z3Kfhp1/zE1D4hqO2jmwnjrLP+dDGCM7933eeXFzwXIB1RCdA7rG6OaDR9WGgBNgBwof 0BbB/ya8eqrPtfHv/tM6xHpsTACkk1o= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u9PdkuQA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.172 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707118111; a=rsa-sha256; cv=none; b=S7qU1uBa2WieKMKEZTqemzxQ9Pmbvq6K4KjPZ+dcGELRkKwfkxnlJ6m3pd+guzA9897RjX ERa1TUyWehbNVDTF5oqeuXgbhnbbBYlI6+SWijdCWbXvpcCL0bgqlHIlqwdNio/R9Wfffg uXLRe6uH2YzZvXINsJum6yGDRIpb+8M= Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707118109; h=from:from: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; bh=i/ZGvwbHuNVW/dSM5Fqd2S27/qH5458seah4OOuVqJ8=; b=u9PdkuQAntTMBsLnsf0HJ5vK5V694BEyp2ZqC/vCUjF6FHjJqFGVbq+QC5yzo360UC/WDc dNnQm32pZRwHl8boutvnNYb7hlF/1OQfSTNIM5MEIec+k9LlhBNhKcGGTEftvE8DWs2jQk Xsxt3FXtzx89+W3xkLMEUOSCnFOvQOE= Date: Mon, 5 Feb 2024 15:28:16 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v5 7/7] hugetlb: parallelize 1G hugetlb initialization To: Gang Li , David Hildenbrand , David Rientjes , Mike Kravetz , Andrew Morton , Tim Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com References: <20240126152411.1238072-1-gang.li@linux.dev> <20240126152411.1238072-8-gang.li@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20240126152411.1238072-8-gang.li@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 6141E100006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: icq9rhbax83zpthfg13txphoidkhgcds X-HE-Tag: 1707118111-535084 X-HE-Meta: U2FsdGVkX1/E665gViqpkW33yDC5NnPDkgpwi7rVrLyULSjk5dfB2UMFng6BymYZ18d/A2Bq7brq3KNHpif1EPZogdoS5j8pKdI+BEnQ+pYFewNQLS+vO9ClvOsvGCsy6WfM7JWEAmreKujUoGcQdWC9391nds6ZuRFQlD3betRwrWCSvN+rJQGL2N7+6BDp5LG7pR1OrDe2QhArXLiQKkZ4DlUM68Z/sWQBG0tJA7DsY0M2/iIb+BNsMaB1j3bH3+wnhrgY4ocw380G3dGaV9TSLW20UBZBtI23qVATn+ccfWUT3iqn8X7VVEqlWQ2SZdAA+aZIaILneupw2IgIq1B3/DpSKAQBXeubfC1Qm6S6sTgU4e/kMF3JcyUdAmS5eSChShoHjttj8Eht2a0v8FH3NdRBkO+rNbYrmMrklyyUttpoodiXDjpoRuLzC4un/u9IvqJYw0i6LiiwPjUMBnufiqP01GeuwILXoACaRPil3t0pN9gSqcYGtQd9t+IVrFePImewpgtlj6+gmML92kSCPhjDC7QflBtr1d1YPrPkP8RbivFT1+WUFSndZzCGumuBr7VVxFKC31EN99KtREbmY3oCyo7wiu04Oj+3Fv+8yhBR9ourfeCGVcIKqQ2eEI8Ej32YX+RqssQWouc5JAPGi3plHSwffhxJ3Q0zaptByxl/9JP15BZT8+4vUenrVnNW1yKef2/C3YJq9h1ibN59acPGxfd3XeM4qjN/0OtvhrrzPK+i41y2RiO3/1mkDOyeF2EHsk1XQC26JMVs23AcpYk5ApLINnjJRgIOxrgQS30kjuCVVVFfmRDLtkzOv1qEB6fvJWoXPPL9Ig9SSkYJH7/k5RXa0d9yI1f2Yy57oHv4gF4VDGly4ue+j0JLS1k1bo63fgN1n20t39UpS7feB32ulBe62OBX5tDIlWSiNaX625iYB48nL9Uuft0TU1KWnC5qLgCybQwALf3 nI046Ud8 oVqSpDMaqeyxVQwP+v2ttPQLd7iRymvP/MINwWWIfnCONCDB3nWw6y6RbmXKV8JmgZu1JvwnD8q9uBJl/Im1dTABviIXfaoOtNjJu62UPsFj9vVlCwc9ASnBUbL3uXjZj255ouTMZ2Olda+rf7+auDe0cWQVMABSOrWB7 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: On 2024/1/26 23:24, Gang Li wrote: > Optimizing the initialization speed of 1G huge pages through > parallelization. > > 1G hugetlbs are allocated from bootmem, a process that is already > very fast and does not currently require optimization. Therefore, > we focus on parallelizing only the initialization phase in > `gather_bootmem_prealloc`. > > Here are some test results: > test case no patch(ms) patched(ms) saved > ------------------- -------------- ------------- -------- > 256c2T(4 node) 1G 4745 2024 57.34% > 128c1T(2 node) 1G 3358 1712 49.02% > 12T 1G 77000 18300 76.23% > > Signed-off-by: Gang Li > Tested-by: David Rientjes > --- > arch/powerpc/mm/hugetlbpage.c | 2 +- > include/linux/hugetlb.h | 2 +- > mm/hugetlb.c | 44 ++++++++++++++++++++++++++++------- > 3 files changed, 38 insertions(+), 10 deletions(-) > > diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c > index 0a540b37aab62..a1651d5471862 100644 > --- a/arch/powerpc/mm/hugetlbpage.c > +++ b/arch/powerpc/mm/hugetlbpage.c > @@ -226,7 +226,7 @@ static int __init pseries_alloc_bootmem_huge_page(struct hstate *hstate) > return 0; > m = phys_to_virt(gpage_freearray[--nr_gpages]); > gpage_freearray[nr_gpages] = 0; > - list_add(&m->list, &huge_boot_pages); > + list_add(&m->list, &huge_boot_pages[0]); > m->hstate = hstate; > return 1; > } > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index c1ee640d87b11..77b30a8c6076b 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -178,7 +178,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma, > struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage); > > extern int sysctl_hugetlb_shm_group; > -extern struct list_head huge_boot_pages; > +extern struct list_head huge_boot_pages[MAX_NUMNODES]; > > /* arch callbacks */ > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 385840397bce5..eee0c456f6571 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -69,7 +69,7 @@ static bool hugetlb_cma_folio(struct folio *folio, unsigned int order) > #endif > static unsigned long hugetlb_cma_size __initdata; > > -__initdata LIST_HEAD(huge_boot_pages); > +__initdata struct list_head huge_boot_pages[MAX_NUMNODES]; > > /* for command line parsing */ > static struct hstate * __initdata parsed_hstate; > @@ -3301,7 +3301,7 @@ int alloc_bootmem_huge_page(struct hstate *h, int nid) > int __alloc_bootmem_huge_page(struct hstate *h, int nid) > { > struct huge_bootmem_page *m = NULL; /* initialize for clang */ > - int nr_nodes, node; > + int nr_nodes, node = nid; > > /* do node specific alloc */ > if (nid != NUMA_NO_NODE) { > @@ -3339,7 +3339,7 @@ int __alloc_bootmem_huge_page(struct hstate *h, int nid) > huge_page_size(h) - PAGE_SIZE); > /* Put them into a private list first because mem_map is not up yet */ > INIT_LIST_HEAD(&m->list); > - list_add(&m->list, &huge_boot_pages); > + list_add(&m->list, &huge_boot_pages[node]); > m->hstate = h; > return 1; > } > @@ -3390,8 +3390,6 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h, > /* Send list for bulk vmemmap optimization processing */ > hugetlb_vmemmap_optimize_folios(h, folio_list); > > - /* Add all new pool pages to free lists in one lock cycle */ > - spin_lock_irqsave(&hugetlb_lock, flags); > list_for_each_entry_safe(folio, tmp_f, folio_list, lru) { > if (!folio_test_hugetlb_vmemmap_optimized(folio)) { > /* > @@ -3404,23 +3402,27 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h, > HUGETLB_VMEMMAP_RESERVE_PAGES, > pages_per_huge_page(h)); > } > + /* Subdivide locks to achieve better parallel performance */ > + spin_lock_irqsave(&hugetlb_lock, flags); > __prep_account_new_huge_page(h, folio_nid(folio)); > enqueue_hugetlb_folio(h, folio); > + spin_unlock_irqrestore(&hugetlb_lock, flags); > } > - spin_unlock_irqrestore(&hugetlb_lock, flags); > } > > /* > * Put bootmem huge pages into the standard lists after mem_map is up. > * Note: This only applies to gigantic (order > MAX_PAGE_ORDER) pages. > */ > -static void __init gather_bootmem_prealloc(void) > +static void __init gather_bootmem_prealloc_node(unsigned long start, unsigned long end, void *arg) > + > { > + int nid = start; Sorry for so late to notice an issue here. I have seen a comment from PADATA, whcih says:     @max_threads: Max threads to use for the job, actual number may be less                   depending on task size and minimum chunk size. PADATA will not guarantee gather_bootmem_prealloc_node() will be called ->max_threads times (You have initialized it to the number of NUMA nodes in gather_bootmem_prealloc). Therefore, we should add a loop here to initialize multiple nodes, namely (@end - @start) here. Otherwise, we will miss initializing some nodes. Thanks. > LIST_HEAD(folio_list); > struct huge_bootmem_page *m; > struct hstate *h = NULL, *prev_h = NULL; > > - list_for_each_entry(m, &huge_boot_pages, list) { > + list_for_each_entry(m, &huge_boot_pages[nid], list) { > struct page *page = virt_to_page(m); > struct folio *folio = (void *)page; > > @@ -3453,6 +3455,22 @@ static void __init gather_bootmem_prealloc(void) > prep_and_add_bootmem_folios(h, &folio_list); > } > > +static void __init gather_bootmem_prealloc(void) > +{ > + struct padata_mt_job job = { > + .thread_fn = gather_bootmem_prealloc_node, > + .fn_arg = NULL, > + .start = 0, > + .size = num_node_state(N_MEMORY), > + .align = 1, > + .min_chunk = 1, > + .max_threads = num_node_state(N_MEMORY), > + .numa_aware = true, > + }; > + > + padata_do_multithreaded(&job); > +} > + > static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) > { > unsigned long i; > @@ -3600,6 +3618,7 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) > static void __init hugetlb_hstate_alloc_pages(struct hstate *h) > { > unsigned long allocated; > + static bool initialied __initdata; > > /* skip gigantic hugepages allocation if hugetlb_cma enabled */ > if (hstate_is_gigantic(h) && hugetlb_cma_size) { > @@ -3607,6 +3626,15 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) > return; > } > > + /* hugetlb_hstate_alloc_pages will be called many times, initialize huge_boot_pages once */ > + if (!initialied) { > + int i = 0; > + > + for (i = 0; i < MAX_NUMNODES; i++) > + INIT_LIST_HEAD(&huge_boot_pages[i]); > + initialied = true; > + } > + > /* do node specific alloc */ > if (hugetlb_hstate_alloc_pages_specific_nodes(h)) > return;