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 23412C4829A for ; Tue, 13 Feb 2024 11:14:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D9726B0092; Tue, 13 Feb 2024 06:14:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 986886B008C; Tue, 13 Feb 2024 06:14:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 800666B0092; Tue, 13 Feb 2024 06:14:11 -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 6B1F96B008A for ; Tue, 13 Feb 2024 06:14:11 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 488FEA1DD6 for ; Tue, 13 Feb 2024 11:14:11 +0000 (UTC) X-FDA: 81786521502.25.8577141 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf21.hostedemail.com (Postfix) with ESMTP id 8F0071C0011 for ; Tue, 13 Feb 2024 11:14:09 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=K6wyJoAZ; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of gang.li@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=gang.li@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707822849; 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=v+0w6vgAkx480UaKM14cyn/7okLKV9MHO3nKluWgIkY=; b=3wm0U7LH+qGM22u2k/R6mX1VXnTVhfYJ737SjYEW0xdQDqzYSXMefnSVfCmVKu1kEnnXV7 L7rulpTs1IOaV9L4FUeC5DCa8sm4y16K968cdtvkWctEHik1NUyJgmvOsTVsvz7IGIrHF6 jDjd51Td7N69wvypLchGBPCb7mZS1tQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=K6wyJoAZ; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of gang.li@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=gang.li@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707822849; a=rsa-sha256; cv=none; b=Ohf/7BE5Td0PwZlEzoyr3XVbR9iGNEilD7ArFvEdz+FFrj2I31x8hJKcCQGiHdjI7xcEgR CbqZTZ7N/j4OtnYtjzflALfkgu4TQCdoPSe854MEiAbg+oXQX0EzMJCalJIAN4Ejj8SKkr DrM4SRA2Z9qAmLeijfgz3L45aUbT1UI= 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=1707822848; 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=v+0w6vgAkx480UaKM14cyn/7okLKV9MHO3nKluWgIkY=; b=K6wyJoAZJmiAzz8+5pYM3XytCKwKH7mDSv+DR8+IWYQXu64yniCYgylUCM1PW/LdkJ+TWB NapD8/7k+iGm2K5CRO8w6/sOqUjGsvTCxz0YMU4U5TIqeUNCDkNoX510dFoS4Y+6Dmeq/e lo6UmME7aGnRqdGCGovmp/a6yGx/yD8= From: Gang Li To: Andrew Morton , Steffen Klassert , Daniel Jordan , Jane Chu , "Paul E . McKenney" , Muchun Song , Gang Li , Randy Dunlap , kernel test robot , Gang Li Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 2/2] hugetlb: process multiple lists in gather_bootmem_prealloc_parallel Date: Tue, 13 Feb 2024 19:13:47 +0800 Message-Id: <20240213111347.3189206-3-gang.li@linux.dev> In-Reply-To: <20240213111347.3189206-1-gang.li@linux.dev> References: <20240213111347.3189206-1-gang.li@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8F0071C0011 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: cihifb9zr6ds3aa1amrj3ykpobhx4ykx X-HE-Tag: 1707822849-273568 X-HE-Meta: U2FsdGVkX18K9t+7JleKLwTZQqMwYCw/jUf8A5i15mqriuTHZL7L8PlSuNIinlp+71pEtnSlErZUj1sy40gw5DIX6Yy66EX3iNNGiHQiQaVylev7tNxfDrMy9+Bf6ph5T7P+yfynYbF024wF6up38YSSt/LqdtDCm1mEr1HIKjVLHThlU+0ZX4tBEnkbig5f7R/R4bpIyfTXfas/iLl01Q9bIvkt3VdkKOVRAKlnHZyIDrji8GBp9D6Ojj8i3m1lMHUOyNTSUDSU7tkFzN2FyYBf7ARHPUEyE1rSgwbv0/k2AJGf8fCCy2zaPf3uVNAHGlgrEFUL5QvZsHTZL7VeFrXrrMfhVYWPQQ0fVLv3gZpSOUhiLQzhK7e8ayh0V0fAbuEIVjR61gXrLY3+gU+hRALAYr7hGsXKWJtFUY4T762HfyiO4cpDOZ9bNLrXvbKjZplqkbbq7gmw0uxE7rsank0uGZfQUElS+3Vsx9kEC+t+fsT+fQ8PaA6tWEs5l14LmL+oMNf6h6UO5kvSGNEU3Bnd7m9bWXyQUHgJhE5BGe8sbhRIeZ+fTcW6deF9F1PQw+0rDFM1Yfe6AIWEVouhDOIe5hba5PvJ76AMjD41kV7yv95JW3K296Z/ohWzGSjQR8UOSqmeQrldKeLkDOqDozYx7hP3YHCNyod0KYqpboaLfg/ZbOJgD+u5luzjHrmn+rsU9lRZk0ynS0Rfnyw3mCkCnSqTEptMmfrCz8hqIOBJNkIwYMJOm9m1uLI37Lq3iP6xytHbsFaqWhPOGD5JyF2NIVN1qEg8XcLUh7KmXAHba+ToraYp5ccgCcFsaaBMrX98UBcMixv9E2XsvaUX+WkLE/rw8320ruwrAaT10xEksHFIJepHf0p78b1v9eQ7TcHAU5cfm3P7yKkhohYjVdd5qXPHltYCed85zQg557ePwcHhe2rbjsMvCYEGALOHoxpfgcrGa1pnPNQngBY Ke6y67q8 E8hT+i9kRYbVSUnM1QzQQ5a4t0TFDavWECUYsVzM+6W0JCtCrahBinmos1R1bUTsxsv7TAh7LVWAX6q2nchUHmMu6eFQnxefl4JKxY6+TPyvJ5m2xUU/Cwezj7gYJFNRFCUj3sDmUGTnmStPvDA09teEjaiQHAWsS5jASNEvdCqDj4pPZWdfHbu2F3A== 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: gather_bootmem_prealloc_node currently only process one list in huge_boot_pages array. So gather_bootmem_prealloc expects padata_do_multithreaded to run num_node_state(N_MEMORY) instances of gather_bootmem_prealloc_node to process all lists in huge_boot_pages. This works well in current padata_do_multithreaded implementation. It guarantees that size/min_chunk <= thread num <= max_threads. ``` /* Ensure at least one thread when size < min_chunk. */ nworks = max(job->size / max(job->min_chunk, job->align), 1ul); nworks = min(nworks, job->max_threads); ps.nworks = padata_work_alloc_mt(nworks, &ps, &works); ``` However, the comment of padata_do_multithreaded API only promises a maximum value for the number of threads and does not specify a minimum value. Which may pass multiple nodes to gather_bootmem_prealloc_node and only one node will be processed. To avoid potential errors, introduce gather_bootmem_prealloc_parallel to handle the case where the number of threads does not meet the requirement of max_threads. Fixes: 0306f03dcbd7 ("hugetlb: parallelize 1G hugetlb initialization") Signed-off-by: Gang Li --- mm/hugetlb.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 25069ca6ec248..2799a7ea098c1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3414,10 +3414,8 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h, * 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_node(unsigned long start, unsigned long end, void *arg) - +static void __init gather_bootmem_prealloc_node(unsigned long nid) { - int nid = start; LIST_HEAD(folio_list); struct huge_bootmem_page *m; struct hstate *h = NULL, *prev_h = NULL; @@ -3455,10 +3453,19 @@ static void __init gather_bootmem_prealloc_node(unsigned long start, unsigned lo prep_and_add_bootmem_folios(h, &folio_list); } +static void __init gather_bootmem_prealloc_parallel(unsigned long start, + unsigned long end, void *arg) +{ + int nid; + + for (nid = start; nid < end; nid++) + gather_bootmem_prealloc_node(nid); +} + static void __init gather_bootmem_prealloc(void) { struct padata_mt_job job = { - .thread_fn = gather_bootmem_prealloc_node, + .thread_fn = gather_bootmem_prealloc_parallel, .fn_arg = NULL, .start = 0, .size = num_node_state(N_MEMORY), -- 2.20.1