From nobody Fri Oct 3 13:32:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B4F672FB609; Mon, 1 Sep 2025 08:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756715678; cv=none; b=M3MkDJhvsrwQN70NWPmZKJJLFQBXEE6gWQr1M/d+lCYEdmbxRslbd0NJmQUysm7AEcQFxHGprMpilROJqiN3tJWL2fhDDSGTVNIGE5JFFfCbO/GNXC6WtiYazsRDdCtpFXm6EOc9YakBR0Ll/gc+OwBphsAZlVdOHl1niIkiKkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756715678; c=relaxed/simple; bh=s7gDD17wyPWHQKbzFBz1JNHLt2wfCsHSqppGZ+0gGnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZWcya7oHhOsm7mk6vAIZjkkwg9QssZMaGBI9WIDnj78Ewna66eoSOuGhVl4Xv9qQWRFU3pv/8Tr995RTsO3Zz84hjyTftt44tjxAcje1AV2kBKSJezVzxS5KIKWjB5jYX2ZDGGOLSPpS/Q+CSsKsLQrZTMn4RFvQAziOMps2nPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D5iytukq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D5iytukq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8653C4CEF8; Mon, 1 Sep 2025 08:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756715678; bh=s7gDD17wyPWHQKbzFBz1JNHLt2wfCsHSqppGZ+0gGnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D5iytukqVhx8KXkeeNxWYS3iT9qtiWj5ahsGclE358EQFNX0SghXLbqK9QR5HgNMh SPbUz3nsEgsm8W939duAv+3aIjoKZ0q7Hx9RVKbIkvE0nmFUxH7b8ZPqCkfwlfG4z8 GGDMg37upT/s2kA4ON8tWNt5cRBdJdlWqGssqcKYQeCdRJ+vl2Ca4RBQOJLue0zbeQ lqWYLLnOZvQE+mphW+5qaXI5a9CTRsPwvp9FsGsKtlF/dYwQpL7eT13qE3NP2+QaAv 5yd2KJoSjoUdNAq3dONOix1WwKl6cVgywQaXjRKLBIfIrRCKzgsojIl5Eh03oe6xao Tvz//iPPdH0Xw== From: Mike Rapoport To: linux-mm@kvack.org Cc: Andrew Morton , Bill Wendling , Daniel Jordan , David Hildenbrand , Justin Stitt , Michael Ellerman , Miguel Ojeda , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Wei Yang , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 2/4] mm/mm_init: deferred_init_memmap: use a job per zone Date: Mon, 1 Sep 2025 11:34:21 +0300 Message-ID: <20250901083423.3061349-3-rppt@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250901083423.3061349-1-rppt@kernel.org> References: <20250901083423.3061349-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" deferred_init_memmap() loops over free memory ranges and creates a padata_mt_job for every free range that intersects with the zone being initialized. padata_do_multithreaded() then splits every such range to several chunks and runs a thread that initializes struct pages in that chunk using deferred_init_memmap_chunk(). The number of threads is limited by amount of the CPUs on the node (or 1 for memoryless nodes). Looping through free memory ranges is then repeated in deferred_init_memmap_chunk() first to find the first range that should be initialized and then to traverse the ranges until the end of the chunk is reached. Remove the loop over free memory regions in deferred_init_memmap() and pass the entire zone to padata_do_multithreaded() so that it will be divided to several chunks by the parallelization code. Reviewed-by: David Hildenbrand Reviewed-by: Wei Yang Link: https://lore.kernel.org/r/20250818064615.505641-3-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) --- mm/mm_init.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index e73f313dc375..57b256ea9e6c 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2179,12 +2179,10 @@ static int __init deferred_init_memmap(void *data) { pg_data_t *pgdat =3D data; const struct cpumask *cpumask =3D cpumask_of_node(pgdat->node_id); - unsigned long spfn =3D 0, epfn =3D 0; - unsigned long first_init_pfn, flags; + int max_threads =3D deferred_page_init_max_threads(cpumask); + unsigned long first_init_pfn, last_pfn, flags; unsigned long start =3D jiffies; struct zone *zone; - int max_threads; - u64 i =3D 0; =20 /* Bind memory initialisation thread to a local node if possible */ if (!cpumask_empty(cpumask)) @@ -2212,24 +2210,20 @@ static int __init deferred_init_memmap(void *data) =20 /* Only the highest zone is deferred */ zone =3D pgdat->node_zones + pgdat->nr_zones - 1; - - max_threads =3D deferred_page_init_max_threads(cpumask); - - while (deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, first_= init_pfn)) { - first_init_pfn =3D ALIGN(epfn, PAGES_PER_SECTION); - struct padata_mt_job job =3D { - .thread_fn =3D deferred_init_memmap_job, - .fn_arg =3D zone, - .start =3D spfn, - .size =3D first_init_pfn - spfn, - .align =3D PAGES_PER_SECTION, - .min_chunk =3D PAGES_PER_SECTION, - .max_threads =3D max_threads, - .numa_aware =3D false, - }; - - padata_do_multithreaded(&job); - } + last_pfn =3D SECTION_ALIGN_UP(zone_end_pfn(zone)); + + struct padata_mt_job job =3D { + .thread_fn =3D deferred_init_memmap_job, + .fn_arg =3D zone, + .start =3D first_init_pfn, + .size =3D last_pfn - first_init_pfn, + .align =3D PAGES_PER_SECTION, + .min_chunk =3D PAGES_PER_SECTION, + .max_threads =3D max_threads, + .numa_aware =3D false, + }; + + padata_do_multithreaded(&job); =20 /* Sanity check that the next zone really is unpopulated */ WARN_ON(pgdat->nr_zones < MAX_NR_ZONES && populated_zone(++zone)); --=20 2.50.1