From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 98B11545284; Wed, 9 Sep 2026 13:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960844; cv=none; b=W3jSV/nBqXRPgJF0+aag/MZJzpMiqpTWo9eCMPVhZ0SgKWLxGYx2DE0IuLgEBHhXJQjY4DFMyNiKJaEQ9+xaPB7cNkrMhBhaSgRzUzj//KKOpO1AlWrLnnBRczBAWl7I9gclMb6nWaqfA3NtRHhTBCY8V+Y0rlSDvCPvC0lDUF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960844; c=relaxed/simple; bh=tuizVE3zPZHpcM2HGG+m6b3SuJ7LR3VtKbc7zGfeEhc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q+7bIvxKgXSdOGqRePn2SQsTkHHzcBATnhnuA4N6sCJr47dJw0stIHO8eTFyAJGk3w4Gq7KBV7/hl/r2SQgW0YyB4qO1PoUJi8zrYWisQiIwHwtpQhKCQlmjPweaINAz+3sMfCMxGZaktvPvLjLaLBvHTP5ijTBeLKtPatnxYV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kxAJ8TkH; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kxAJ8TkH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A319F1F00A3D; Wed, 9 Sep 2026 13:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960843; bh=ke7wbwtpCjUAwuxuLGTSFpELTF8GAXgQgWxJpOfKOlk=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=kxAJ8TkHym33fm/nM2JegElwmiyVwFZ0YNsgval5iLx/fAaFlApVsOrk21RqvhOTw bdhecW15KUMV8YzLqiIH9eH0nvy37ki3NSxffsRITrTO2nvb4Pw9r+uTw0uLYi2lQ7 JEBxI1bdBIc9ph6Vw/Q+9p/SAbxsj56xU9uloikO5hpn+uFjATCy8MwIALXktyfQbh W5WZd1dLWstQKdJ/jti2Ep5zLEed9g5EExRVy6+g7zvzTrS0AIAUm/UJRTGFtCV7Ka eY+vCZsu9eFAyTywAl+ehZ3vRHLoi8Wm+gXFid62KNoMwvpJ7I4t9YT9ozLsk3Ok5h 2B5UB6El4/WMw== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:32:54 +0200 Subject: [PATCH 01/12] mm/sparse: move mem_section init to sparse_extreme_init() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-1-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1918; i=david@kernel.org; h=from:subject:message-id; bh=tuizVE3zPZHpcM2HGG+m6b3SuJ7LR3VtKbc7zGfeEhc=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJqhf+8M6eYfkbV/5ZQszo18qzdtQdUrG9MjBH/tyl 68/zXM4p6OUhUGMg0FWTJElKPi+wcuX62qr3fiYYeawMoEMYeDiFICJXPZlZNhr2Gf7Y/aN9uOy Ru2WM1VWpqrOtt1qHfHiRc6HOeov9mkzMjzbsHlZRXPhkflTWh+3JPtvW87zXvjPD8mr2Ve0bPT 4f7AAAA== X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Let's just avoid another pair of ifdef inside a function. While at it, switch to INTERNODE_CACHE_BYTES by just defining a fallback in cache.h as well, given that the x86 variant already provides one. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- include/linux/cache.h | 1 + mm/sparse.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/linux/cache.h b/include/linux/cache.h index e69768f50d532..b6e857b985bca 100644 --- a/include/linux/cache.h +++ b/include/linux/cache.h @@ -89,6 +89,7 @@ */ #ifndef INTERNODE_CACHE_SHIFT #define INTERNODE_CACHE_SHIFT L1_CACHE_SHIFT +#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT) #endif =20 #if !defined(____cacheline_internodealigned_in_smp) diff --git a/mm/sparse.c b/mm/sparse.c index 9349ed6326c01..6a6d258862904 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -103,11 +103,22 @@ int __meminit sparse_index_init(unsigned long section= _nr, int nid) =20 return 0; } + +static void __init sparse_extreme_init(void) +{ + const unsigned long size =3D sizeof(struct mem_section *) * NR_SECTION_RO= OTS; + + mem_section =3D memblock_alloc_or_panic(size, INTERNODE_CACHE_BYTES); +} #else /* !SPARSEMEM_EXTREME */ int __meminit sparse_index_init(unsigned long section_nr, int nid) { return 0; } + +static void __init sparse_extreme_init(void) +{ +} #endif =20 /* @@ -197,13 +208,7 @@ void __init sparse_sections_init(void) unsigned long start, end; int i, nid; =20 -#ifdef CONFIG_SPARSEMEM_EXTREME - unsigned long size, align; - - size =3D sizeof(struct mem_section *) * NR_SECTION_ROOTS; - align =3D 1 << (INTERNODE_CACHE_SHIFT); - mem_section =3D memblock_alloc_or_panic(size, align); -#endif + sparse_extreme_init(); =20 for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid) memory_present(nid, start, end); --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E1BEE566C5C; Wed, 9 Sep 2026 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960854; cv=none; b=PDxhLdSP9pqkeqE/+cT5ej8VB7/nykrTQxXIXQQKNyaZqnYhmLfaOkWHVuGvZ+xK4SlC+wlwHgMgT/EkSQXal7Q37QhrAXv9z9Z1kBejDN9wNnXH+D29Dmc5izAcDRhCRcbTqTmSowDcRjPkEs/9o3W6XcUvzjHHccpNmeNO0Zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960854; c=relaxed/simple; bh=vj5TwCzhlLxvUe7A+Bx3R9PGajolUon6lM6RJzWmxHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YLZOWFqeG1xa3swSyD0db8My0AI62kWsFxsSaSJpJGL04GRtYR1CK+UY01LyyGx9pWLyCFvJL4qSR1un54TXODYOT5JOiUHGnBRXUaa8CvlcmpZvQNSGsSLU5z0Ymq4FzCWqIVYdZJx0FRj8FvL+dAC3vxCLHS24K8X4wPnQwEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VKETAwhb; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VKETAwhb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D97AA1F00A3A; Wed, 9 Sep 2026 13:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960852; bh=Vwf3XHFmLke+N9soz5HJtjy5W6jvA8C1cmDilLBFR0E=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=VKETAwhbvv+EK0Gm31QFMYaYfrQJ2PkX9WiTurdg0GqN2atlcsKeEnI2LT69seS1g ckmzVzkRoynOrvTlgBNzG1vsWAhQRsMuS1a7vuZYSDXafGxdgK9TNpx4ebCVmVAjM1 xDU1YFvqp0/x0rO09WvuApW6ngX9ZKM5Vkq7BQ8v35OA/CBlRB5ViylH9nulLN/f29 5dnXJYPV5oRwG4/vm/WSmAWMIcDVIe38hgrg+TvfeE1NJrKE8c5xy9uZKJTJnaRbyS OkQib97F1RX0R0/WJwLRKYGE5XY9OxKPJH/UsYWzVYILEjG7UPdcd15Pipp0iFaPrd GcwqJZUYV2Rxw== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:32:55 +0200 Subject: [PATCH 02/12] mm/sparse: refactor sparse_sections_init() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-2-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2859; i=david@kernel.org; h=from:subject:message-id; bh=vj5TwCzhlLxvUe7A+Bx3R9PGajolUon6lM6RJzWmxHU=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJmg1TG/wTlyzoPKR2TK/dRFzncSdjcw5bZd5zM1// dqqsVqxo5SFQYyDQVZMkSUo+L7By5fraqvd+Jhh5rAygQxh4OIUgInwTWD4ny5++k5Jx/wO5uki oZopr+4wct0S4XQ8sunwR2f+wENn5RgZrr9oaQteGlzRdT11x6xTOw1nq7yNDpm/IaqT039Ki3U fNwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A memory_present() really identifies+prepares all early sections so the initialization in sparse_init() can properly iterating them to initialize metadata. Let's just inline memory_present() into sparse_sections_init() and cleaning up the code a bit while at it: make it clear that we are operating on pfns. Note that we call set_section_nid() now only if the section was not already created earlier. Now, there is no more inconsistency between what we (temporarily) store in ms->section_mem_map and what we store in our section->nid array. Signed-off-by: David Hildenbrand (Arm) Acked-by: Lorenzo Stoakes (ARM) Acked-by: Oscar Salvador Reviewed-by: Mike Rapoport (Microsoft) --- mm/sparse.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 6a6d258862904..36e3d854febc5 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -179,22 +179,27 @@ static inline unsigned long first_present_section_nr(= void) return next_present_section_nr(-1); } =20 -/* Record a memory area against a node. */ -static void __init memory_present(int nid, unsigned long start, unsigned l= ong end) +void __init sparse_sections_init(void) { - unsigned long pfn; + unsigned long pfn, start_pfn, end_pfn; + int i, nid; + + sparse_extreme_init(); =20 - start &=3D PAGE_SECTION_MASK; - mminit_validate_memmodel_limits(&start, &end); - for (pfn =3D start; pfn < end; pfn +=3D PAGES_PER_SECTION) { - unsigned long section_nr =3D pfn_to_section_nr(pfn); - struct mem_section *ms; + for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { + start_pfn &=3D PAGE_SECTION_MASK; + mminit_validate_memmodel_limits(&start_pfn, &end_pfn); =20 - sparse_index_init(section_nr, nid); - set_section_nid(section_nr, nid); + for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D PAGES_PER_SECTION) { + unsigned long section_nr =3D pfn_to_section_nr(pfn); + struct mem_section *ms; =20 - ms =3D __nr_to_section(section_nr); - if (!ms->section_mem_map) { + sparse_index_init(section_nr, nid); + ms =3D __nr_to_section(section_nr); + if (ms->section_mem_map) + continue; + + set_section_nid(section_nr, nid); ms->section_mem_map =3D sparse_encode_early_nid(nid) | SECTION_IS_ONLINE; __section_mark_present(ms, section_nr); @@ -202,18 +207,6 @@ static void __init memory_present(int nid, unsigned lo= ng start, unsigned long en } } =20 -/* Initialize memory section metadata for all system memory. */ -void __init sparse_sections_init(void) -{ - unsigned long start, end; - int i, nid; - - sparse_extreme_init(); - - for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid) - memory_present(nid, start, end); -} - #ifndef CONFIG_SPARSEMEM_VMEMMAP struct page __init *__populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap, --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A7B83566C5C; Wed, 9 Sep 2026 13:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960864; cv=none; b=qUjgY2hDBSStJY+2bK5wZlFQVwyMdGnV5Rtx35nnuClYcHJk7YWMLc370mvuK4bJPADah1Ac/OeWid+9fN939jWWo61VpKlR8cxkxcYTOQyHCfksucZ+K3un/58Qalr0RVP5Rs3DoKoCytbOaOJBV4Y6/ZWESxou8KJ7itYHOPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960864; c=relaxed/simple; bh=f5vfO3saF7PVVCMfIchqE3Iy0rnVBSpES3AbK2/MfAc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=paYdgqg0jDqUfcVwwxa4PflALHcYH3cQ+zkGQdhr3EYIV4L7iPymSyzSPU85+nYLCHgYqMXSlznQVQRpk6ZWFBRnIlzcY7Zw9Cr/EaaOWjBrpn3rwzGFoVCstKbV/MSj7/D/Ag6nNeirzvIYpv0hdBACkNRHLaRuN1U8cT33vPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PwklD36q; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PwklD36q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75A141F00A3D; Wed, 9 Sep 2026 13:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960862; bh=wfXJR6x8v03fXUe0TqSKHDJiGieSJgGhDryfxeyRA9M=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=PwklD36qGjyYvFWApNCpE42qV3e3BOR2Kgo+jF5pn5Hgu//Dcgoq7Wm0kns9g21k8 ysL1SVlmIVtAuPqPttzOcHyVslyAAR/JaCZy6cXEpREMiKofKDuzHdP65D77cMfZcT YixC8alIt/gUhMNsV8Kf563LegysoB1pqb1TEirBAYYW2igJPFScR4u61DqjA0zaVk 1ZutKHppQr1pIfljD22DLrSam3J9cYQ7Cu7mGLjZe6J4ByirBjg4gf1QOvSbzeUXXe ydABST5FK+9hcfE1KgrhbZUqVmqaZQadLoEakZY8OCFoJBQZhq2FJUv+MH16EUVCEF tYK2C8MitVVfA== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:32:56 +0200 Subject: [PATCH 03/12] mm/sparse: move initialization of section metadata to sparse_metadata_init() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-3-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2420; i=david@kernel.org; h=from:subject:message-id; bh=f5vfO3saF7PVVCMfIchqE3Iy0rnVBSpES3AbK2/MfAc=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJmjH7Uza+6Et22NRz/V4J2bhbw/eh/3xsNlWveUgt 0nCVqaHHaUsDGIcDLJiiixBwfcNXr5cV1vtxscMM4eVCWQIAxenAExEwYThN9ssvqU62d2f3le9 nfYr/OaM3bfvWay+ternsu2mjSrVCWUM/6wvHXtrcutno3dRlaqEZ5u6U0riDf6AOd+iFh+Okpi 3iwsA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Let's move the code responsible for initializing sparse metadata (usemap, memmap) into a helper. Cleanup the variable while at it (e.g., "map_count"). Drop the rather obvious code comments. No functional change intended. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- mm/sparse.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 36e3d854febc5..a85a9c3840f6c 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -257,38 +257,39 @@ static void __init sparse_init_nid(int nid, unsigned = long pnum_begin, } } =20 +static void __init sparse_metadata_init(void) +{ + unsigned long start_section_nr =3D first_present_section_nr(); + int nid_begin =3D sparse_early_nid(__nr_to_section(start_section_nr)); + unsigned long section_nr, nr_sections =3D 1; + + for_each_present_section_nr(start_section_nr + 1, section_nr) { + const int nid =3D sparse_early_nid(__nr_to_section(section_nr)); + + if (nid =3D=3D nid_begin) { + nr_sections++; + continue; + } + sparse_init_nid(nid_begin, start_section_nr, section_nr, nr_sections); + nid_begin =3D nid; + start_section_nr =3D section_nr; + nr_sections =3D 1; + } + sparse_init_nid(nid_begin, start_section_nr, section_nr, nr_sections); +} + /* * Allocate the accumulated non-linear sections, allocate a mem_map * for each and record the physical to section mapping. */ void __init sparse_init(void) { - unsigned long pnum_end, pnum_begin, map_count =3D 1; - int nid_begin; - if (compound_info_has_mask()) { VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN)); } =20 - pnum_begin =3D first_present_section_nr(); - nid_begin =3D sparse_early_nid(__nr_to_section(pnum_begin)); - - for_each_present_section_nr(pnum_begin + 1, pnum_end) { - int nid =3D sparse_early_nid(__nr_to_section(pnum_end)); - - if (nid =3D=3D nid_begin) { - map_count++; - continue; - } - /* Init node with sections in range [pnum_begin, pnum_end) */ - sparse_init_nid(nid_begin, pnum_begin, pnum_end, map_count); - nid_begin =3D nid; - pnum_begin =3D pnum_end; - map_count =3D 1; - } - /* cover the last node */ - sparse_init_nid(nid_begin, pnum_begin, pnum_end, map_count); + sparse_metadata_init(); sparse_init_subsection_map(); vmemmap_populate_print_last(); } --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E72FD534454; Wed, 9 Sep 2026 13:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960872; cv=none; b=su6VH0Qi/8OcxIsiXawK6rQD1wMX4PFlR86LNYJavrg+OOP2oirZv/l1bm46pKb78qsrm4+/PDPv+4q2o3Uy3qq7p/TnUHACn9vFPCFU7FcDOFOboegweYJZHUnG2MlQOMGBGfIsFvJoSmfj+rliPR+Ct6JG2bHf+ywjQ0YcQ3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960872; c=relaxed/simple; bh=22aLutJEtYm1F1P07TqVwcTSIGuZ5EPTXkGcwZd1Z9w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RC/AMl1CDZpYtjze0T+yI/I4a0dtH8/tU5+mwLNt8lQ6z/7gnPrlt6VskhUfnEapww9GqPDdLLJD05YjWePprDaxvJGHTkIVRYklWihpLl3Cw2QbQ6UxpEgjF/ZSUQf2vJcqfSfx7mhSQ+zh11CimJqgGwQdQxc+YD0mgQ3JVTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZelQ852V; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZelQ852V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB38E1F00A3E; Wed, 9 Sep 2026 13:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960870; bh=EfFkM8TVdbGE2NG2Pg9PpUCdJifdmydrKyHEc/A5FNg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ZelQ852VoOuFMeQYlpa1x3hPLSEBcmbHr/anV1cxsUAXZbU4Q5UyYHEPxH4ih1+0P izH9qgUZlMVymte2q3uRmLw9/JQiFCsNpX7U/MlzLkYBWu9shEbx5HPSH+KmfDlrTd arhjR1E7ccoi14BBCfMhxmd2F85EApCvid29inQNclly453UllgucI5jYUcge9USbI 6dMDsN01ZpUKXTL3XtyFl6qdXKtzDo11qWD9yjrkuWpfLZPXCCD8pAZAMlzeqNbrph uGe4wsD1cPESHaN+3KOwYl45kJESPBhLIlf7dOzS4dMad9l5EP9icvfoPSmt+uLbOP Nf1AMeDO01jZA== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:32:57 +0200 Subject: [PATCH 04/12] mm/sparse: rename and cleanup sparse_init_nid() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-4-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3010; i=david@kernel.org; h=from:subject:message-id; bh=22aLutJEtYm1F1P07TqVwcTSIGuZ5EPTXkGcwZd1Z9w=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJug/EP2qvX5Rr/5ab7Y3etta32/kz7uebGjWHKIga 7G7ofx3RykLgxgHg6yYIktQ8H2Dly/X1Va78THDzGFlAhnCwMUpABPh2cTIsPXCsU3TilYZ6avM f60osnipg1zpgRX+Pk9+n9hy7YrV04sM/12tUwMX/JfRUjlQwL7L68iE28+eWOyt/MxZH1qbwGz jww8A X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Let's rename it to "sparse_metadata_init_nid", avoid the "pnum" terminology and drop the function comment. Further, rename the "map" variable to "mem_map" for consistency with other functions. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- mm/sparse.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index a85a9c3840f6c..f84bfceb53060 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -222,37 +222,34 @@ void __weak __meminit vmemmap_populate_print_last(voi= d) { } =20 -/* - * Initialize sparse on a specific node. The node spans [pnum_begin, pnum_= end) - * And number of present sections in this node is map_count. - */ -static void __init sparse_init_nid(int nid, unsigned long pnum_begin, - unsigned long pnum_end, - unsigned long map_count) +static void __init sparse_metadata_init_nid(int nid, + unsigned long start_section_nr, unsigned long end_section_nr, + unsigned long nr_sections) { - unsigned long pnum; struct mem_section_usage *usage; + unsigned long section_nr; =20 - usage =3D memblock_alloc_node(map_count * mem_section_usage_size(), + usage =3D memblock_alloc_node(nr_sections * mem_section_usage_size(), SMP_CACHE_BYTES, nid); if (!usage) panic("Failed to allocate usemap for node %d\n", nid); =20 - for_each_present_section_nr(pnum_begin, pnum) { - unsigned long pfn =3D section_nr_to_pfn(pnum); - struct page *map; + for_each_present_section_nr(start_section_nr, section_nr) { + unsigned long pfn =3D section_nr_to_pfn(section_nr); + struct page *mem_map; =20 - if (pnum >=3D pnum_end) + if (section_nr >=3D end_section_nr) break; =20 - map =3D __populate_section_memmap(pfn, PAGES_PER_SECTION, - nid, NULL, NULL); - if (!map) - panic("Failed to allocate memmap for section %lu\n", pnum); + mem_map =3D __populate_section_memmap(pfn, PAGES_PER_SECTION, nid, + NULL, NULL); + if (!mem_map) + panic("Failed to allocate memmap for section %lu\n", + section_nr); memmap_boot_pages_add(section_nr_vmemmap_pages(pfn, PAGES_PER_SECTION, NULL, NULL)); - sparse_init_one_section(__nr_to_section(pnum), pnum, map, usage, - SECTION_IS_EARLY); + sparse_init_one_section(__nr_to_section(section_nr), section_nr, + mem_map, usage, SECTION_IS_EARLY); usage =3D (void *)usage + mem_section_usage_size(); } } @@ -270,12 +267,14 @@ static void __init sparse_metadata_init(void) nr_sections++; continue; } - sparse_init_nid(nid_begin, start_section_nr, section_nr, nr_sections); + sparse_metadata_init_nid(nid_begin, start_section_nr, + section_nr, nr_sections); nid_begin =3D nid; start_section_nr =3D section_nr; nr_sections =3D 1; } - sparse_init_nid(nid_begin, start_section_nr, section_nr, nr_sections); + sparse_metadata_init_nid(nid_begin, start_section_nr, section_nr, + nr_sections); } =20 /* --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 DE6C15427E6; Wed, 9 Sep 2026 13:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960881; cv=none; b=fTpnC1T1glnMcmEGQq+8WrfQ0iI3DvlQXdotP/iH2m/FmTVzLO3hKiPf78azSgbR2OfPq8t1bdq1NO9cZUe02E6+CiX8u/NEJagxRTFQIa2OYqXvNbeq7Z33cHBKXhCHdIlGN6CVl6fgJOPnn3KotWviOLwY37D7KPuE7nrejj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960881; c=relaxed/simple; bh=Z7WiH4a0eM1yPjwlViyGW7AlVy9OebQyIjLQp6z8KDo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fr9Gkw6KOjDeWY/sItHx0HDIoLfOLOGRltbJQNpq++PM/RW2TJrzMSpEEJ0obBVV097lyXTPzc89UHdZw3Ty/gS/TTeVzxTbMRAp3Dfhawvxe3hIYudx1OzApamm7jfSHH4yN3UeX+imoveBc2ScKlqrGxS7LTyJs4RlvSlfLj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D/t+Mmy8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D/t+Mmy8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 195531F00A3F; Wed, 9 Sep 2026 13:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960879; bh=2s0CTmVngAhgAN93TX2cVOhQyycESM96yPxbLZkJZRo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=D/t+Mmy8CiNwGSg0cWFN3moAPhAPZ9DE8Ga8Htq8mAEHixxrpYy6ZOeKpVtXYEOax e9wfbI97DnTzPswN6LtpD2OvZ8VxEny1EOowANRDN5AMSj6mC3N41CTGuuBv1DZXJ1 JVZc0UTkSwh+tW379Q+rDff8oeohBos5A2I1nVxy6ij+mKswZVHoCx781LFZXjgL+a UHxG3MCcZ2Z8UFWRl1xiTSiX+Vp085FS0BihF48mdBS97GEHOBaXk/u/QF3yylZRw9 g3gzJF+e65Q4kTli/43aExcpWz+ZFC8ug6DvycHV4ScHn8b1Rw2a585t676cE3EEFA VfnKlPO7nTJtw== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:32:58 +0200 Subject: [PATCH 05/12] mm/sparse: cleanup sparse_init_one_section() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-5-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1155; i=david@kernel.org; h=from:subject:message-id; bh=Z7WiH4a0eM1yPjwlViyGW7AlVy9OebQyIjLQp6z8KDo=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJhjsOtzKtPNH/67rxXoq8S2fL/FvXG3l3rXhBKN6m Ldyy9RzHaUsDGIcDLJiiixBwfcNXr5cV1vtxscMM4eVCWQIAxenAExESYfhr3h+9fyk4vchfZeC L+cHLDA1V7zKqjU799hSl9Cy00FOygz/43kCvjQdN7VIkCjau+5EcV2Nec/396s3NsR6u9t+bjL jAwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Let's avoid the "pnum" terminology. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- mm/sparse.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/sparse.h b/mm/sparse.h index 049272aba84e5..744ae29002f5e 100644 --- a/mm/sparse.h +++ b/mm/sparse.h @@ -90,7 +90,7 @@ void sparse_sections_init(void); int sparse_index_init(unsigned long section_nr, int nid); =20 static inline void sparse_init_one_section(struct mem_section *ms, - unsigned long pnum, struct page *mem_map, + unsigned long section_nr, struct page *mem_map, struct mem_section_usage *usage, unsigned long flags) { unsigned long coded_mem_map; @@ -102,7 +102,7 @@ static inline void sparse_init_one_section(struct mem_s= ection *ms, * page_to_pfn() on !CONFIG_SPARSEMEM_VMEMMAP can simply subtract it * from the page pointer to obtain the PFN. */ - coded_mem_map =3D (unsigned long)(mem_map - section_nr_to_pfn(pnum)); + coded_mem_map =3D (unsigned long)(mem_map - section_nr_to_pfn(section_nr)= ); VM_WARN_ON_ONCE(coded_mem_map & ~SECTION_MAP_MASK); =20 ms->section_mem_map &=3D ~SECTION_MAP_MASK; --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 06854492E23; Wed, 9 Sep 2026 13:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960891; cv=none; b=eKBKrywwaSxuyLm06E2g3K4dDpobR5OyAB6dP+OUZTooJSoY+VLhKlUfr1DbFRGyai0bI7CIPc7qhe3HlF6Fj2IubfJn5uO8ZeNpO215LZ6NBbNON2WfvtGO9xz5IugVDcs2bM2sNr7FWQ4qQOfrh0jpO41FFNM6kO5z4mTks/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960891; c=relaxed/simple; bh=mW1IouhiQ9wKrEiRlJmNZfNFYgNpZy9MK7BrqFqJBso=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AB18w4KOA+Ha8mkAa+SeZIqHadsGLJgBdo2VrS9nbEHxYHv/QqN+dJ/m+wZi89DoSZmJSGUqnaILBNvZc1VpNf1OEIFPUnOVzGFhDRdMsx9/4MiYMlRyKUR4xfsRj8KXDZNYnwQ0BaymXH3GsWTaAQcX2iZRJBo7IancnkMM/8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kIoHTTPA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kIoHTTPA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45EDE1F00A3D; Wed, 9 Sep 2026 13:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960889; bh=7PN1IUhSiINmj8se4l4JjZpqC9NFR6pyb0CVD1i9OUw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=kIoHTTPAUt43eRitH91WceQSKtW/bnO0DsunOWkKihNYd/TT4n16yoEXPoL7Ttm9v E7gprzEbl0f7YRxISlwllUWnaB0OKQSmS0xcjOC1zAFl5XJ1rCnR2aGCbSo+Lb4osQ 0yMDnt+yLEJeJkDCoBsEAk22lqqKD00F2VpX20tr6exOlYobDWufPg8N0bHsAZHnNW mGvhmaliePQkYXReT6AVNhIznC18ECGJ8kOaV/3HkVgcDIYTsuIcn06yOVzUJP1Or9 sfcTGZOONZU6H6SnH1ms+/x3/csSerKpLL5WpiNLSFH65Js/Sj3S/a4irbU70T20Ef aOOZo8EgoypAA== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:32:59 +0200 Subject: [PATCH 06/12] mm/sparse: rename __highest_present_section_nr to __highest_used_section_nr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-6-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3550; i=david@kernel.org; h=from:subject:message-id; bh=mW1IouhiQ9wKrEiRlJmNZfNFYgNpZy9MK7BrqFqJBso=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJhjt+K15+5FExW+Nhc9aPAxOq727k9J291GdSHh5F INK0Au+jlIWBjEOBlkxRZag4PsGL1+uq61242OGmcPKBDKEgYtTACaiUcPI8Ndc3j9wvsG86jv3 PwS2ifdN+B1TWf8jNPVm87eqn/UbuxgZtuXck7xmXMy6aIrQXJ9/JdnXLvhcnHklOPNWIqveQhd ZbgA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A In preparation for getting rid of SECTION_MARKED_PRESENT, rename __highest_present_section_nr and clarify the comment. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- include/linux/mmzone.h | 6 +++--- mm/compaction.c | 2 +- mm/sparse.c | 12 ++++-------- mm/sparse.h | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index c9ae7991a8b20..19296e8ef44f8 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2170,7 +2170,7 @@ static inline struct mem_section *__pfn_to_section(un= signed long pfn) return __nr_to_section(pfn_to_section_nr(pfn)); } =20 -extern unsigned long __highest_present_section_nr; +extern unsigned long __highest_used_section_nr; =20 static inline int subsection_map_index(unsigned long pfn) { @@ -2269,7 +2269,7 @@ static inline unsigned long first_valid_pfn(unsigned = long pfn, unsigned long end =20 rcu_read_lock_sched(); =20 - while (nr <=3D __highest_present_section_nr && pfn < end_pfn) { + while (nr <=3D __highest_used_section_nr && pfn < end_pfn) { struct mem_section *ms =3D __pfn_to_section(pfn); =20 if (valid_section(ms) && @@ -2324,7 +2324,7 @@ static inline int pfn_in_present_section(unsigned lon= g pfn) =20 static inline unsigned long next_present_section_nr(unsigned long section_= nr) { - while (++section_nr <=3D __highest_present_section_nr) { + while (++section_nr <=3D __highest_used_section_nr) { if (present_section_nr(section_nr)) return section_nr; } diff --git a/mm/compaction.c b/mm/compaction.c index 4994e200bbecd..f1b2060eb2016 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -216,7 +216,7 @@ static unsigned long skip_offline_sections(unsigned lon= g start_pfn) if (online_section_nr(start_nr)) return 0; =20 - while (++start_nr <=3D __highest_present_section_nr) { + while (++start_nr <=3D __highest_used_section_nr) { if (online_section_nr(start_nr)) return section_nr_to_pfn(start_nr); } diff --git a/mm/sparse.c b/mm/sparse.c index f84bfceb53060..2b41ae36f20b8 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -164,15 +164,11 @@ static void __init mminit_validate_memmodel_limits(un= signed long *start_pfn, } =20 /* - * There are a number of times that we loop over NR_MEM_SECTIONS, - * looking for section_present() on each. But, when we have very - * large physical address spaces, NR_MEM_SECTIONS can also be - * very large which makes the loops quite long. - * - * Keeping track of this gives us an easy way to break out of - * those loops early. + * Looping over all memory sections is expensive, especially if NR_MEM_SEC= TIONS + * is large but only a fraction is actually used. Keep track of the highest + * section number we ever used. */ -unsigned long __highest_present_section_nr; +unsigned long __highest_used_section_nr; =20 static inline unsigned long first_present_section_nr(void) { diff --git a/mm/sparse.h b/mm/sparse.h index 744ae29002f5e..7c5d82ceb7142 100644 --- a/mm/sparse.h +++ b/mm/sparse.h @@ -114,8 +114,8 @@ static inline void sparse_init_one_section(struct mem_s= ection *ms, static inline void __section_mark_present(struct mem_section *ms, unsigned long section_nr) { - if (section_nr > __highest_present_section_nr) - __highest_present_section_nr =3D section_nr; + if (section_nr > __highest_used_section_nr) + __highest_used_section_nr =3D section_nr; =20 ms->section_mem_map |=3D SECTION_MARKED_PRESENT; } --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 0105255C1D2; Wed, 9 Sep 2026 13:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960900; cv=none; b=Lz8+0YHAISsEibBj26Eo6hhXPkeQOgGp5zTU7/2Cv5jcycWiM2Raw9tgGr7shB2lSAA5p/MArlKWeRDxkRWLJ9AaH3iu1rrJxLuE9BwR4HSDHFj0caBzaWxp95bgHpEnHSh0A3XPalgzK+45PGE0ezawbwbC40u0UYdg1C9NrPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960900; c=relaxed/simple; bh=DA7ADutddsFmCEjmK+yDurz/oaDpzdkWvjLNiIYgvvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UNTlV0HlhWLggA0417arS4lYG1prRjoeyPGxcM/dWCTTew/Kf0nddxH0rfbiDUjkfrk7MqOEZRnxrKXE6K1Gr5JpRu/n6qiAxtakPJ3sAR5yaBVWCo4hJ3AZQBKvjHOEzmu4CQAuwfQEuo2shivC3Jr4MrgOwmAZghdXDw/lf4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BRsmgCIw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BRsmgCIw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A9AF1F00A3A; Wed, 9 Sep 2026 13:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960898; bh=RbrTaD0MOwCU/dADLtwS3cqKnDKmO0natjZctaLbG/M=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=BRsmgCIwY0Z931Vf0ZjC6k0U+yWVRAZCHkkhlcXWETlu88ySO3sCpKrVMlBV0iwfx uhI+WzvqD/3YQ8SMBuVeKSS3n9hx1GEVvZRBQVN+UZ6ykgBxwlGQRStGr9ZtQLU75j 5aH0gGEiUG3K64WjEPowzkxXP0T0DJT7FbdoM/VRe8+Cqvr0qaOBmdfjtxHK8E99jh mCxckMTz3aD1mk4SOj53r+ZG94HF+mDeSiNjqjkOPLTKlbPE9tnTT1lHzT53+jY59q em4ZD3q2xBchOgXc3/a8fw6iE6JpLL9tOd3EhDpAZ+Z9UGFQ1cTGuOHPZ35dJw+hKz ndwC/p+XCnE6A== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:33:00 +0200 Subject: [PATCH 07/12] mm/sparse: remove pfn_in_present_section() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-7-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1038; i=david@kernel.org; h=from:subject:message-id; bh=DA7ADutddsFmCEjmK+yDurz/oaDpzdkWvjLNiIYgvvA=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJhj9LT/1YHOplEHQxz9GrwpNzSyZjmz2tmhef2zS3 OZzJVmKHaUsDGIcDLJiiixBwfcNXr5cV1vtxscMM4eVCWQIAxenAEzk5BqGf8bHdbuE5Vl+1wfJ rk3bxv5+Da8L//f8XY1WufOf/10fz83wV1ZXYe3Dd1PSZ0bz3Ofq3hL065LbnIjrSodf/jx98dm sNawA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Unused, let's remove it. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- include/linux/mmzone.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 19296e8ef44f8..e0fac344f6ac2 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2315,13 +2315,6 @@ static inline unsigned long next_valid_pfn(unsigned = long pfn, unsigned long end_ =20 #endif =20 -static inline int pfn_in_present_section(unsigned long pfn) -{ - if (pfn_to_section_nr(pfn) >=3D NR_MEM_SECTIONS) - return 0; - return present_section(__pfn_to_section(pfn)); -} - static inline unsigned long next_present_section_nr(unsigned long section_= nr) { while (++section_nr <=3D __highest_used_section_nr) { @@ -2351,9 +2344,6 @@ static inline unsigned long next_present_section_nr(u= nsigned long section_nr) #else #define pfn_to_nid(pfn) (0) #endif - -#else -#define pfn_in_present_section pfn_valid #endif /* CONFIG_SPARSEMEM */ =20 /* --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 848745678D9; Wed, 9 Sep 2026 13:35:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960909; cv=none; b=YBq8qjm9p/wncqh7Tv+V7j2fYBjr4Y98JSmg8ltT+szUpUcvOL/CBtPMfZoj7T/u29UIqkDkFZSKwOvayOVwWK6DhKaT8TRkKWrpvcOuEaveuErpZ/YkAOIjczdGJIG8+6v1/L5qA4ujRbTT76Xs4DfJby+hBf9OK/xnGbSQc2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960909; c=relaxed/simple; bh=ifd00cyRI1HuxOcc2xxWxJxbUrmoY4ieu/5tTBcNKZc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XRBk3AFBF35H6NhZKVPrWmx/BNBB1afizFFT37xqGvQALLZVSg3DuO7lmtO9PtNWIhhLkXllLR41oZnLqPn1BVg2dz6/muly6L2bvAzEJdfxaro3qNzvFjZuXMPtAQdcS1fws/JzYHZ8Eus/6jFoVyX4vU95I59IAhU+gKDAaB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JUrQET7B; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JUrQET7B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87FCA1F00A3D; Wed, 9 Sep 2026 13:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960908; bh=L2v3o67HNQ9aSFqTXVM1jpMn5NU+1i04xE3R5tvtAw4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=JUrQET7Bpep1u4rw0MKmhd9cfkeICsEyAERFh9SEB3R3M+csy30qdNXfG/4GEdFoe ylt75rtuHgs5B902EEQK9MUSQwl8Jvgpfu87L8ifQaEXVvj2lWEQ2sNq5st4BeYXO6 7AFVLyGoIDL0OR6RE1ecN3f0N7liMpHacZoQ20+8IP0J88ZyM2xcWbh3R8Ek+fVCrQ /IOC4FEn+4dlR9VjLohiYugge0+bl+TbMqGUOgEt+goOdwybo2LG51/wecTCLBMqbX UKc1z3AWRQcg9gA+oBnjs1wQEvXxuzHAsQJ5bIom6NyHIAfadkKPvZyItRyn/yduu5 x32FaRXVOo9OQ== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:33:01 +0200 Subject: [PATCH 08/12] mm/sparse: move __highest_used_section_nr handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-8-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2321; i=david@kernel.org; h=from:subject:message-id; bh=ifd00cyRI1HuxOcc2xxWxJxbUrmoY4ieu/5tTBcNKZc=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJhj/9Ny1KDloarDGVa1TGt0r2+dIpR+efCbvRNIKL bfLL/nlOkpZGMQ4GGTFFFmCgu8bvHy5rrbajY8ZZg4rE8gQBi5OAZhI7jxGhvXvpFgXTC59Y6Tj FHXihcBi00OJWlFqnZdOrNI6IaKxpoSR4c/7iSYTvC+Glr0wsct6bm6/8hnnuY4O6bVr31hNFeG fygkA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Let's move it to sparse_init_one_section(). However, to keep early boot processing working, we also have to initialize it in sparse_sections_init(). Should we use READ_ONCE/WRITE_ONCE with __highest_used_section_nr? Probably, something for another day. Signed-off-by: David Hildenbrand (Arm) Reviewed-by: Mike Rapoport (Microsoft) --- mm/sparse.c | 5 +++-- mm/sparse.h | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 2b41ae36f20b8..2d0f2db34f4cf 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -177,7 +177,7 @@ static inline unsigned long first_present_section_nr(vo= id) =20 void __init sparse_sections_init(void) { - unsigned long pfn, start_pfn, end_pfn; + unsigned long pfn, start_pfn, end_pfn, section_nr; int i, nid; =20 sparse_extreme_init(); @@ -187,9 +187,9 @@ void __init sparse_sections_init(void) mminit_validate_memmodel_limits(&start_pfn, &end_pfn); =20 for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D PAGES_PER_SECTION) { - unsigned long section_nr =3D pfn_to_section_nr(pfn); struct mem_section *ms; =20 + section_nr =3D pfn_to_section_nr(pfn); sparse_index_init(section_nr, nid); ms =3D __nr_to_section(section_nr); if (ms->section_mem_map) @@ -201,6 +201,7 @@ void __init sparse_sections_init(void) __section_mark_present(ms, section_nr); } } + __highest_used_section_nr =3D section_nr; } =20 #ifndef CONFIG_SPARSEMEM_VMEMMAP diff --git a/mm/sparse.h b/mm/sparse.h index 7c5d82ceb7142..a3af4967fd5c5 100644 --- a/mm/sparse.h +++ b/mm/sparse.h @@ -97,6 +97,9 @@ static inline void sparse_init_one_section(struct mem_sec= tion *ms, =20 BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT); =20 + if (section_nr > __highest_used_section_nr) + __highest_used_section_nr =3D section_nr; + /* * We encode the start PFN of the section into the mem_map such that * page_to_pfn() on !CONFIG_SPARSEMEM_VMEMMAP can simply subtract it @@ -114,9 +117,6 @@ static inline void sparse_init_one_section(struct mem_s= ection *ms, static inline void __section_mark_present(struct mem_section *ms, unsigned long section_nr) { - if (section_nr > __highest_used_section_nr) - __highest_used_section_nr =3D section_nr; - ms->section_mem_map |=3D SECTION_MARKED_PRESENT; } =20 --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 273CF5678F9; Wed, 9 Sep 2026 13:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960919; cv=none; b=VDFb0fjJcLFqDtuY3LhSg5PZNoOEsiwg5LYc+HJgdlOKJmBxmeO0vdDKIGAyL5Ilbel8//Qh9L0+exlEVBpVompxnW+3LJh65qTdr0rlK34x5AyR0g97vSw47O9VXFKu/kNpMI5L5Ti01jZJKKuUDiI5tr+zU/NlreP4f4MUjyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960919; c=relaxed/simple; bh=pAqijJ/xtGVhn3ym5mqreVDB8QMgyWcSahLMC88vLlA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PEos3Mt/C+1IqQd10QQhjXGUshnIcWlZaGHaNW4xEpNzQFnF1krkxP4sH0dZ6wqxP7LNjXw76bBnU0b0DL/qQVlLqUPfbi44whO8Ny3H86WB76wTETsMWvz9tV/HBRMhKpvPtyyHjF7M6jIaISq4Iv1zzCsRIwYSuM2UrvAeTwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UZLwWhoX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UZLwWhoX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 138B71F00A3A; Wed, 9 Sep 2026 13:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960917; bh=fBGQrCMxkvE0QOzXeJ7kYvO7SCxKh2lg8AgTwyZfi+M=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=UZLwWhoX3lWXrf9WsF1UKXoWEIfmH/rvUBRquWmhTYW9CJp/XO7wzmfIN/Zqm651z x9tPEWZZsqskkE9Pya7FExW89tjSqX5Jz8JUew/6l9EnDQkxNnxCLPJffLyQfRM3e0 nm7XhHmm0h6G0L4UTrJiLLKWRIRKfs5gSv34GfMtTly1fb360I15kX4fY5Br424rm1 sHh+rG7H3Nh7lpShT9PSjfplcTeAAaC2wxJGq1V4nYMSdueS1D0rVtMrLmvpM58odx bAuBZys9lGRDF4X3jTIq85yBIFNN0BFk35Kk6HsgAW3+uShbg5BFBIztNtPC1ioSJE p7THdbyIJIL8A== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:33:02 +0200 Subject: [PATCH 09/12] mm/sparse: remove SECTION_MARKED_PRESENT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-9-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7818; i=david@kernel.org; h=from:subject:message-id; bh=pAqijJ/xtGVhn3ym5mqreVDB8QMgyWcSahLMC88vLlA=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJpis8LDdZLhL67vVoh9SsSqed1RveiSuZVebFLcog fn9b+M9HaUsDGIcDLJiiixBwfcNXr5cV1vtxscMM4eVCWQIAxenAEzELoGRYaaaEkPmwSkW+g9O ahZu/nh96Q62ILObQrXLO60S5q5/G8Dwmz3O6dIh2Vv7JJb/ab9yxlp/66dv3ZwNf/zXnwzP+/R 0AxMA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A All present section iterators run before memory hotplug added any further memory sections, Therefore, we can simply use the SECTION_IS_EARLY flag by setting that flag earlier in sparse_prepare_early_sections(). Get rid of SECTION_MARKED_PRESENT entirely and rename for_each_present_section_nr() to for_each_early_section_nr(). Also update the gdb script to use the updated value for SECTION_IS_EARLY. No functional change intended. Signed-off-by: David Hildenbrand (Arm) Acked-by: Lorenzo Stoakes (ARM) Acked-by: Oscar Salvador Reviewed-by: Mike Rapoport (Microsoft) --- drivers/base/memory.c | 2 +- include/linux/mmzone.h | 27 ++++++++++----------------- mm/sparse-vmemmap.c | 1 - mm/sparse.c | 17 ++++++++--------- mm/sparse.h | 6 ------ scripts/gdb/linux/mm.py | 2 +- 6 files changed, 20 insertions(+), 35 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 5eead3346f1e3..b0338de2f1d82 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -972,7 +972,7 @@ void __init memory_dev_init(void) * block so that it can be covered. */ block_id =3D ULONG_MAX; - for_each_present_section_nr(0, nr) { + for_each_early_section_nr(0, nr) { if (block_id !=3D ULONG_MAX && memory_block_id(nr) =3D=3D block_id) continue; =20 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index e0fac344f6ac2..62cff59dd80c4 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2084,7 +2084,6 @@ static inline struct mem_section *__nr_to_section(uns= igned long nr) * accommodate SECTION_MAP_LAST_BIT. We use BUILD_BUG_ON() to ensure this. */ enum { - SECTION_MARKED_PRESENT_BIT, SECTION_HAS_MEM_MAP_BIT, SECTION_IS_ONLINE_BIT, SECTION_IS_EARLY_BIT, @@ -2094,7 +2093,6 @@ enum { SECTION_MAP_LAST_BIT, }; =20 -#define SECTION_MARKED_PRESENT BIT(SECTION_MARKED_PRESENT_BIT) #define SECTION_HAS_MEM_MAP BIT(SECTION_HAS_MEM_MAP_BIT) #define SECTION_IS_ONLINE BIT(SECTION_IS_ONLINE_BIT) #define SECTION_IS_EARLY BIT(SECTION_IS_EARLY_BIT) @@ -2111,16 +2109,6 @@ static inline struct page *__section_mem_map_addr(st= ruct mem_section *section) return (struct page *)map; } =20 -static inline int present_section(const struct mem_section *section) -{ - return (section && (section->section_mem_map & SECTION_MARKED_PRESENT)); -} - -static inline int present_section_nr(unsigned long nr) -{ - return present_section(__nr_to_section(nr)); -} - static inline int valid_section(const struct mem_section *section) { return (section && (section->section_mem_map & SECTION_HAS_MEM_MAP)); @@ -2136,6 +2124,11 @@ static inline int valid_section_nr(unsigned long nr) return valid_section(__nr_to_section(nr)); } =20 +static inline int early_section_nr(unsigned long nr) +{ + return early_section(__nr_to_section(nr)); +} + static inline int online_section(const struct mem_section *section) { return (section && (section->section_mem_map & SECTION_IS_ONLINE)); @@ -2315,20 +2308,20 @@ static inline unsigned long next_valid_pfn(unsigned= long pfn, unsigned long end_ =20 #endif =20 -static inline unsigned long next_present_section_nr(unsigned long section_= nr) +static inline unsigned long next_early_section_nr(unsigned long section_nr) { while (++section_nr <=3D __highest_used_section_nr) { - if (present_section_nr(section_nr)) + if (early_section_nr(section_nr)) return section_nr; } =20 return -1; } =20 -#define for_each_present_section_nr(start, section_nr) \ - for (section_nr =3D next_present_section_nr(start - 1); \ +#define for_each_early_section_nr(start, section_nr) \ + for (section_nr =3D next_early_section_nr(start - 1); \ section_nr !=3D -1; \ - section_nr =3D next_present_section_nr(section_nr)) + section_nr =3D next_early_section_nr(section_nr)) =20 /* * These are _only_ used during initialisation, therefore they diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index e62e6aa07f126..5aba058df6b67 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -890,7 +890,6 @@ int __meminit sparse_add_section(int nid, unsigned long= start_pfn, page_init_poison(memmap, sizeof(struct page) * nr_pages); =20 ms =3D __nr_to_section(section_nr); - __section_mark_present(ms, section_nr); =20 /* Align memmap to section boundary in the subsection case */ if (section_nr_to_pfn(section_nr) !=3D start_pfn) diff --git a/mm/sparse.c b/mm/sparse.c index 2d0f2db34f4cf..344acaaed94db 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -170,13 +170,14 @@ static void __init mminit_validate_memmodel_limits(un= signed long *start_pfn, */ unsigned long __highest_used_section_nr; =20 -static inline unsigned long first_present_section_nr(void) +static inline unsigned long first_early_section_nr(void) { - return next_present_section_nr(-1); + return next_early_section_nr(-1); } =20 void __init sparse_sections_init(void) { + const unsigned long flags =3D SECTION_IS_EARLY | SECTION_IS_ONLINE; unsigned long pfn, start_pfn, end_pfn, section_nr; int i, nid; =20 @@ -196,9 +197,7 @@ void __init sparse_sections_init(void) continue; =20 set_section_nid(section_nr, nid); - ms->section_mem_map =3D sparse_encode_early_nid(nid) | - SECTION_IS_ONLINE; - __section_mark_present(ms, section_nr); + ms->section_mem_map =3D sparse_encode_early_nid(nid) | flags; } } __highest_used_section_nr =3D section_nr; @@ -231,7 +230,7 @@ static void __init sparse_metadata_init_nid(int nid, if (!usage) panic("Failed to allocate usemap for node %d\n", nid); =20 - for_each_present_section_nr(start_section_nr, section_nr) { + for_each_early_section_nr(start_section_nr, section_nr) { unsigned long pfn =3D section_nr_to_pfn(section_nr); struct page *mem_map; =20 @@ -246,18 +245,18 @@ static void __init sparse_metadata_init_nid(int nid, memmap_boot_pages_add(section_nr_vmemmap_pages(pfn, PAGES_PER_SECTION, NULL, NULL)); sparse_init_one_section(__nr_to_section(section_nr), section_nr, - mem_map, usage, SECTION_IS_EARLY); + mem_map, usage, 0); usage =3D (void *)usage + mem_section_usage_size(); } } =20 static void __init sparse_metadata_init(void) { - unsigned long start_section_nr =3D first_present_section_nr(); + unsigned long start_section_nr =3D first_early_section_nr(); int nid_begin =3D sparse_early_nid(__nr_to_section(start_section_nr)); unsigned long section_nr, nr_sections =3D 1; =20 - for_each_present_section_nr(start_section_nr + 1, section_nr) { + for_each_early_section_nr(start_section_nr + 1, section_nr) { const int nid =3D sparse_early_nid(__nr_to_section(section_nr)); =20 if (nid =3D=3D nid_begin) { diff --git a/mm/sparse.h b/mm/sparse.h index a3af4967fd5c5..03351f2467e34 100644 --- a/mm/sparse.h +++ b/mm/sparse.h @@ -114,12 +114,6 @@ static inline void sparse_init_one_section(struct mem_= section *ms, ms->usage =3D usage; } =20 -static inline void __section_mark_present(struct mem_section *ms, - unsigned long section_nr) -{ - ms->section_mem_map |=3D SECTION_MARKED_PRESENT; -} - static inline size_t mem_section_usage_size(void) { return struct_size_t(struct mem_section_usage, pageblock_flags, diff --git a/scripts/gdb/linux/mm.py b/scripts/gdb/linux/mm.py index 193a88d763abf..73d637d28c8e6 100644 --- a/scripts/gdb/linux/mm.py +++ b/scripts/gdb/linux/mm.py @@ -76,7 +76,7 @@ class x86_page_ops(): self.SECTION_IS_EARLY =3D 1 << int(gdb.parse_and_eval('SECTION= _IS_EARLY_BIT')) except: self.SECTION_HAS_MEM_MAP =3D 1 << 0 - self.SECTION_IS_EARLY =3D 1 << 3 + self.SECTION_IS_EARLY =3D 1 << 2 =20 self.SUBSECTION_SHIFT =3D 21 self.PAGES_PER_SUBSECTION =3D 1 << (self.SUBSECTION_SHIFT - self.P= AGE_SHIFT) --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 30D87568FA1; Wed, 9 Sep 2026 13:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960929; cv=none; b=QSGx6FO2qbysUMHVaYGwGe2i7lTx1w/kllA/9ribJ/nJDAtFLheH6Ne2VHxLxexD2NTrQ6sHe01+3ok3zcpAwXPTOntudAb++RJ80f2r0XBiJObBGpMqdJvH+DuJ7Z7sYethnUPlVz1VXyCqkqPcOMPBCK8VLRX9bKMBoWe7tqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960929; c=relaxed/simple; bh=DckWm817GDohe+Jpj0X2/MGpAnLdf0iSl2oq+0nv+DY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qFM86YA5j0ss+o/qj8fCefrRBPZpcLklLMQ+m19GbuAQ9G60Q7089Y53kHk6xIBJLl+t8guQmtuYg9okLjo/7G3dsG5Fiys0eKDpV8HffHYwA/ESLfFOkagd+G3KaVXdmknZzZ9ezJ8LgjCpIZX65J1GKClcsdpU6kQom68zHK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FwyGU5F9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FwyGU5F9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 887071F00A3D; Wed, 9 Sep 2026 13:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960928; bh=yZNdkM0u6O9tZXo2WJInVc9+4wXdTph9vPW/LWef/ec=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=FwyGU5F93doyR2e+TPh/mdOmwUgenFtb2TP+XJNz3h+GAaop9V50jXt3fURujWDff 844XCCU9pS4FYYnocBM040shpJTZzg1504KOaOOFjpbpw6yaW55hBDNAYN4gZGelNJ ihdNcRxfV8z+R21OYQncFMNeyXGi+GqxojxD1Tm/awQ61Cf9zcEYnvtz6c6YoVCuYP /esXF2U5FYahncfNaVAfyyVTJnnSJ0XZCY9E+GO1YsW+vTrPyS7LyiXQWGgTPzPtBl mg0S8dObY9asNAhWG1oHEKPZyQtyrW7lNHEdnMQUc2zcEPuLc1MbVJ1iDeqhPEap3W 2q5EQjdyVe0IA== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:33:03 +0200 Subject: [PATCH 10/12] mm/sparse: remove flags parameter from sparse_init_one_section() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-10-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2131; i=david@kernel.org; h=from:subject:message-id; bh=DckWm817GDohe+Jpj0X2/MGpAnLdf0iSl2oq+0nv+DY=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJpiGJ8Q3l91f3ndj9/ytd25uOvJENPJiXveMnvgJG rPSNjUYdpSyMIhxMMiKKbIEBd83ePlyXW21Gx8zzBxWJpAhDFycAjCRpzEM/6yXpcS7z3Bcy9Bt 3ZL/dF3H7HstSeYHrDlieadzlPUnLWf4n2HY+OJTruOio0Fd1m7VdgLyj/v/cjssvHlvwbyEwKr /vAA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Unused, let's remove it. Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- mm/sparse-vmemmap.c | 2 +- mm/sparse.c | 2 +- mm/sparse.h | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 5aba058df6b67..25d3472972363 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -894,7 +894,7 @@ int __meminit sparse_add_section(int nid, unsigned long= start_pfn, /* Align memmap to section boundary in the subsection case */ if (section_nr_to_pfn(section_nr) !=3D start_pfn) memmap =3D pfn_to_page(section_nr_to_pfn(section_nr)); - sparse_init_one_section(ms, section_nr, memmap, ms->usage, 0); + sparse_init_one_section(ms, section_nr, memmap, ms->usage); =20 return 0; } diff --git a/mm/sparse.c b/mm/sparse.c index 344acaaed94db..d2e7c21319e27 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -245,7 +245,7 @@ static void __init sparse_metadata_init_nid(int nid, memmap_boot_pages_add(section_nr_vmemmap_pages(pfn, PAGES_PER_SECTION, NULL, NULL)); sparse_init_one_section(__nr_to_section(section_nr), section_nr, - mem_map, usage, 0); + mem_map, usage); usage =3D (void *)usage + mem_section_usage_size(); } } diff --git a/mm/sparse.h b/mm/sparse.h index 03351f2467e34..f45dd280db6ff 100644 --- a/mm/sparse.h +++ b/mm/sparse.h @@ -91,7 +91,7 @@ int sparse_index_init(unsigned long section_nr, int nid); =20 static inline void sparse_init_one_section(struct mem_section *ms, unsigned long section_nr, struct page *mem_map, - struct mem_section_usage *usage, unsigned long flags) + struct mem_section_usage *usage) { unsigned long coded_mem_map; =20 @@ -109,8 +109,7 @@ static inline void sparse_init_one_section(struct mem_s= ection *ms, VM_WARN_ON_ONCE(coded_mem_map & ~SECTION_MAP_MASK); =20 ms->section_mem_map &=3D ~SECTION_MAP_MASK; - ms->section_mem_map |=3D coded_mem_map; - ms->section_mem_map |=3D flags | SECTION_HAS_MEM_MAP; + ms->section_mem_map |=3D coded_mem_map | SECTION_HAS_MEM_MAP; ms->usage =3D usage; } =20 --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 174DE568FD7; Wed, 9 Sep 2026 13:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960939; cv=none; b=NwepA4ijb24nWze/neLKAc60Q9GLdk+ojnYpO2fa0nF3/tDbF+XJEmnHyAuQ4+fHHvaq03g7IKacybUrQmNFTaE/nmAA7zhgHzkGP6tHk/MQxeZtC7tu8/tJqwsiVb8RsdLe0WgySX48Eybpn+pE0LVG1S3+56UVf0OY5fC3hSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960939; c=relaxed/simple; bh=elFTRUDefqtCYtZsGvjwDH8AmlVM1CM5zJvcDj1v4k4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oU55aaH8fKhwXiq77HSlYazLh1W4Z847XkQtNPPU+UxslB67obxnSb2zbvkBGXVOOBi5CO7lk5JjsV2Li+qVnZ7kK/iFBG65Ll1rsqUaWCYD0Vw4orudlOLe6QkEClkj2SmfZzuokSM3r43e1IOOEwcO46pptUNXGcvUNcdXQdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VIGyAPDE; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VIGyAPDE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B50331F00A3F; Wed, 9 Sep 2026 13:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960937; bh=H1aBakRnV2iGUhIOAlr/N+D/FmN54uy58dpZhC/x4NY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=VIGyAPDEKWd20kwvIUqot+xQIE1FKSVvgNyZ/BCaSBYBZ4/l7RmtwfUKsLtebNCZC KUyOuqdC7+6aDRTaV1D3LxHQ9jcb8ulJWjSiHbeVDIaV9LTxKQtl2kvyiCOKuiOd0B Rl5dwNfAArIAw6DLBbH8KfEbMCs1DGQKausO5zq8k/HjKGOfi9RcFBbS5TrbaolCAp bgFnI7XplUYPs4LONuG6s/f7TGDl+N+VbjGs2+CKIMZSFpZ6igjtJ9E7jJs+bJJ+yy PXooZ4itjy+6yrPhTiIiI8A9nIgqzsg18kC/pgJBbg/o6baV8bGpycq2hlzZs2JIsO OMjP5QzdY7mLg== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:33:04 +0200 Subject: [PATCH 11/12] fs/proc/page: clarify comment in get_max_dump_pfn() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-11-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=998; i=david@kernel.org; h=from:subject:message-id; bh=elFTRUDefqtCYtZsGvjwDH8AmlVM1CM5zJvcDj1v4k4=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJphmno7ZtaEjffuh/wH302o/Tb+27Zvs1DvC0Q0q6 ftjn2RrdJSyMIhxMMiKKbIEBd83ePlyXW21Gx8zzBxWJpAhDFycAjCR6NmMDMtvbK71sotI4+J/ o3Jcb+/Hh59sA5ctevyKp9qXn6c0LZPhD6fr25qaNd2XSyMTtt5Kf7j1029HxWYPp81f1I45Zey 8yQwA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A pfn_to_online_page() will only succeed on some PFNs within the same section, not necessarily all. Let's make that clearer. Signed-off-by: David Hildenbrand (Arm) Acked-by: Lorenzo Stoakes (ARM) Acked-by: Oscar Salvador Reviewed-by: Mike Rapoport (Microsoft) --- fs/proc/page.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index 260772b20bd99..6856ff3e3cf28 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -31,10 +31,9 @@ static inline unsigned long get_max_dump_pfn(void) { #ifdef CONFIG_SPARSEMEM /* - * The memmap of early sections is completely populated and marked - * online even if max_pfn does not fall on a section boundary - - * pfn_to_online_page() will succeed on all pages. Allow inspecting - * these memmaps. + * If max_pfn does not fall on a section boundary, pfn_to_online_page() + * can succeed on PFNs beyond max_pfn within the same section. Allow + * inspecting these memmaps. */ return round_up(max_pfn, PAGES_PER_SECTION); #else --=20 2.43.0 From nobody Fri Sep 25 18:21:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 34B5B569F1A; Wed, 9 Sep 2026 13:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960949; cv=none; b=YPuWlaCw/d9U8LKbQ/LwGbkJrYlNkwtzFuBh7WnNCWGodY08sv64M4AWy7zaQKb2PzFDeu0pbFPtrD8hPhkP3b+nsQkaMW0pxBOv4Q+OiMzag8j9jF0GoioTEUAQwFAJvUZ7FhnhvfcJsrwMxXocqwbkd88cQrNVEfREjuaJldw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788960949; c=relaxed/simple; bh=I1xFmYSCNfoZRtg/iuz9b+jqWmT7TApM4OSDy8PLZHc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rNJD++V3z5HCIr4PV43moSANkPQGRRP5D/yJetylDPGhfCCikIEv/MDwikke2PJQyytONUKaHv72fcV00p0wpkXZN6t6BiQNtPku4lwcXBbp2v2zhTow5kTyVeHLVu/r1ltbd9XXAcsanzZQE+ajB9xCY2WQ3+XMiYTDGS0Du10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lUP10OIi; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lUP10OIi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72CCA1F00A3E; Wed, 9 Sep 2026 13:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788960947; bh=ppqQV4pamAYsPTCmhaUztf71g95EkhNaJEiPUVBmZoE=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=lUP10OIiiOD0g1gKYxyCH57GeQCpOQLzLHyLszIH5wxx2hl1OGsyMlnlJy4o9hb9H vTrOvVYAthk4gvleTtWAJw71P7fv0FXFCCXGNP8cBs9MBdObgrQ6MjlpBPLC/UPW2S QX2T0FYx/bn46HOQjzuDWhc0YGbY/YL3k6D79wQHbNZbT7G+N1LGVnZ0OOvHnEvvGJ 9uRqg2cqO1vXaitIqGjFXRGf4ybQTmrIYuUF7g3DZjX671eT1b/hS56i9xzP6RED0F u00fsWfWEkfTtbOja82QX9Qf+O/BwWhl6H6FvG+Jtl303l8DvzaWXdGCMUBbR5IwyX Hw6rkhYHu33YA== From: "David Hildenbrand (Arm)" Date: Wed, 09 Sep 2026 15:33:05 +0200 Subject: [PATCH 12/12] mm/memory_hotplug: drop CONFIG_HAVE_ARCH_PFN_VALID handling from pfn_to_online_page() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-b4-sparsemem_cleanups-v1-12-008fc8d579fe@kernel.org> References: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> In-Reply-To: <20260909-b4-sparsemem_cleanups-v1-0-008fc8d579fe@kernel.org> To: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , Brendan Jackman , Johannes Weiner , Zi Yan , Oscar Salvador , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Jan Kiszka , Kieran Bingham Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1129; i=david@kernel.org; h=from:subject:message-id; bh=I1xFmYSCNfoZRtg/iuz9b+jqWmT7TApM4OSDy8PLZHc=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIWJpgJMyzyvB65vL27f85kbXdLt6gbDzY/Yp6Yf8VM0 q7DdL5oRykLgxgHg6yYIktQ8H2Dly/X1Va78THDzGFlAhnCwMUpABP52MPIMCEkOfOdVfQq5xUS 2W+mcbQLni1POiPosUizLu1HR5/6BIafjB+i52zNM5h+yPuoQ0/ve5nj2ncf8i+0Xq1Tdfdeq8B DNgA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Drop CONFIG_HAVE_ARCH_PFN_VALID handling, as CONFIG_HAVE_ARCH_PFN_VALID is never used with CONFIG_MEMORY_HOTPLUG, as the latter depends on CONFIG_SPARSEMEM_VMEMMAP. Make sure it stays that way. Signed-off-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) --- mm/memory_hotplug.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index b428da66d279c..58ce35cb48f57 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -344,6 +344,8 @@ struct page *pfn_to_online_page(unsigned long pfn) struct dev_pagemap *pgmap; struct mem_section *ms; =20 + BUILD_BUG_ON(IS_ENABLED(CONFIG_HAVE_ARCH_PFN_VALID)); + if (nr >=3D NR_MEM_SECTIONS) return NULL; =20 @@ -351,13 +353,6 @@ struct page *pfn_to_online_page(unsigned long pfn) if (!online_section(ms)) return NULL; =20 - /* - * Save some code text when online_section() + - * pfn_section_valid() are sufficient. - */ - if (IS_ENABLED(CONFIG_HAVE_ARCH_PFN_VALID) && !pfn_valid(pfn)) - return NULL; - if (!pfn_section_valid(ms, pfn)) return NULL; =20 --=20 2.43.0