Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2977086rdb; Tue, 13 Feb 2024 03:14:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+CpJJQvFjwAgrHphRRQaERFrITVL1ZL7Nks3NRAKKclTNhxRB9tMjDQwBVGcgxXDFP219NurVO+heI7dj3/jxQtl9QlPA7RTKV7BVWg== X-Google-Smtp-Source: AGHT+IHmM5KWIDsyA8+DHVfh++vpUPL9Yd4ZxRI53nSrPKEU1cclOBT/POumlcStSWhUZBtY1ruu X-Received: by 2002:ac2:42cb:0:b0:511:429e:43d4 with SMTP id n11-20020ac242cb000000b00511429e43d4mr5889699lfl.11.1707822887301; Tue, 13 Feb 2024 03:14:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707822887; cv=pass; d=google.com; s=arc-20160816; b=VVjcLLkdu3fTVtAtt01+mfxZoIm3cqHkEQuNhFV2zCWZ1cdvhtQtpw53rmqblEenEa rzbEm+X4s+TyFjqjre5DMk3ynaneIobRUftnCZBQtzRfu2P2df1huvG22Rd+gRWWDM9N S8Jt2XW4QjNO7v8ZqtorlmDtVo7jdCAJMuiuEYo4G0v0EFXi/M5jKJq875NwVcsn1XeC 9yVx6gpQ6zgJ/QM0sB7lLIiCLqoa3BYloDXfsUluxP6AYAxuBaXZMGKkW8YRdgQ5JZS2 lErW1rDWDWRpl76WXwOWJWUiJdBV8jmrotw39KpcEWPJqX8yXC70Qu7vHcmY5yHr0gD3 OY4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=v+0w6vgAkx480UaKM14cyn/7okLKV9MHO3nKluWgIkY=; fh=YEEewgUiT9c0WwHe99WUuUNYhtsAGm4J8/4R813YXkI=; b=w/y5MNteTAkUrxVGQJ1DI96YwseKvOHcHIuROiyvgm4w5XsQhZqhHlMXl6FZ+IbssD 7DPvHk/lHtfqhixzDesBGnys/watNu3QumCVyvTRRUmF5ztC+irz5luVAh1SAQr92cSK yF3Aq3b6y2B1cecEvO3cs7Kp1UyfduvjWQIZut3XboPEo6FCM+ds8tSPxZGia7YQsTr4 denbxgPqcHWmRvm42a/H2oBGjVd5Nep1wz94EhBxDPo130TGXAPGE+iQ5uznpbGZHoj6 9CWKwdbFVxCFUaId/wgWBGaNZqnMzgI3ZDvjJQtY48aXbRje0DUY74Y8QlwEBOUAUMlA ix4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K6wyJoAZ; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-63405-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63405-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCWYdv0oagQKOp3bYbKEFlTLh2sBtIvj+EJQIBBmZMt5F6KPsV+NejMyz0MNtC1MHlK40oxfAWt7rWijpCjt/IRqvoi6CXpMskNIQOieLA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ox7-20020a170907100700b00a3842effe3fsi1154064ejb.345.2024.02.13.03.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 03:14:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63405-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K6wyJoAZ; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-63405-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63405-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0E6AA1F26F89 for ; Tue, 13 Feb 2024 11:14:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9104B383B6; Tue, 13 Feb 2024 11:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="K6wyJoAZ" Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13D9F37711 for ; Tue, 13 Feb 2024 11:14:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707822851; cv=none; b=FY4naBZA3YPUFqRXxRcJgVUlnuPtzSXE6e/MHQRTU9h+EMxiRMkdFx1RF/pF7IaPvxywNwsNritJEyMjdQw7L8jEe+mZL8aep8vJZh7fl/8z3FsKF7IDSuaWDXpmWP9TNVb8w3i0ITxHcZ4zz8hE6n8AxQhXktotOabRKZbgyJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707822851; c=relaxed/simple; bh=d6/hUbDiaSKbaKZPPqsgtYI6MyO67KcFseD9Tax9SNk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e9VM0N4qQvPEi1G9c9zmIYx0DlSFON9f/CbAw5KjESS64KEtmvPpx6XOtMTZxqTsOyyxda8Q3/g6qFWEbH/5UFTkXk10v8pf1cR3AlJGkkKj60QO0CaoM4DfRJbFw5Awypi1gNEJjJFYdpSaEDmFOXqU+0tJypUa48M3dwZhZG8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=K6wyJoAZ; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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