* [PATCH v3 1/2] mm/mm_init: fold adjust_zone_range_for_zone_movable() into its only caller
2026-08-14 13:37 [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node() Sang-Heon Jeon
@ 2026-08-14 13:37 ` Sang-Heon Jeon
2026-08-14 13:37 ` [PATCH v3 2/2] mm/mm_init: simplify ZONE_MOVABLE branch in zone_spanned_pages_in_node() Sang-Heon Jeon
2026-08-23 14:21 ` [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node() Mike Rapoport
2 siblings, 0 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-08-14 13:37 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton; +Cc: linux-kernel, linux-mm
adjust_zone_range_for_zone_movable() adjusts zone_start_pfn and
zone_end_pfn. It is only called from zone_spanned_pages_in_node(), which
adjusts the same two values before and after the call. This makes the
code harder to follow.
Fold the helper into the caller to make the code clearer. Also extract
zone_movable_pfn[nid], which is used four times, into a local variable
and skip the adjustment early to reduce the indentation level.
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/mm_init.c | 68 ++++++++++++++++++++++++----------------------------
1 file changed, 31 insertions(+), 37 deletions(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index eb53c327210b..df67d4e6f646 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1124,41 +1124,6 @@ void __ref memmap_init_zone_device(struct zone *zone,
}
#endif
-/*
- * The zone ranges provided by the architecture do not include ZONE_MOVABLE
- * because it is sized independent of architecture. Unlike the other zones,
- * the starting point for ZONE_MOVABLE is not fixed. It may be different
- * in each node depending on the size of each node and how evenly kernelcore
- * is distributed. This helper function adjusts the zone ranges
- * provided by the architecture for a given node by using the end of the
- * highest usable zone for ZONE_MOVABLE. This preserves the assumption that
- * zones within a node are in order of monotonic increases memory addresses
- */
-static void __init adjust_zone_range_for_zone_movable(int nid,
- unsigned long zone_type,
- unsigned long node_end_pfn,
- unsigned long *zone_start_pfn,
- unsigned long *zone_end_pfn)
-{
- /* Only adjust if ZONE_MOVABLE is on this node */
- if (zone_movable_pfn[nid]) {
- /* Size ZONE_MOVABLE */
- if (zone_type == ZONE_MOVABLE) {
- *zone_start_pfn = zone_movable_pfn[nid];
- *zone_end_pfn = min(node_end_pfn,
- arch_zone_highest_possible_pfn[movable_zone]);
-
- /* Adjust for ZONE_MOVABLE starting within this range */
- } else if (*zone_start_pfn < zone_movable_pfn[nid] &&
- *zone_end_pfn > zone_movable_pfn[nid]) {
- *zone_end_pfn = zone_movable_pfn[nid];
-
- /* Check if this whole range is within ZONE_MOVABLE */
- } else if (*zone_start_pfn >= zone_movable_pfn[nid])
- *zone_start_pfn = *zone_end_pfn;
- }
-}
-
/*
* Return the number of holes in a range on a node. If nid is MAX_NUMNODES,
* then all holes in the requested range will be accounted for.
@@ -1208,6 +1173,15 @@ static unsigned long __init zone_absent_pages_in_node(int nid,
/*
* Return the number of pages a zone spans in a node, including holes
* present_pages = zone_spanned_pages_in_node() - zone_absent_pages_in_node()
+ *
+ * The zone ranges provided by the architecture do not include ZONE_MOVABLE
+ * because it is sized independent of architecture. Unlike the other zones,
+ * the starting point for ZONE_MOVABLE is not fixed. It may be different
+ * in each node depending on the size of each node and how evenly kernelcore
+ * is distributed. The zone ranges provided by the architecture are adjusted
+ * for a given node by using the end of the highest usable zone for
+ * ZONE_MOVABLE. This preserves the assumption that zones within a node are
+ * in order of monotonic increases memory addresses
*/
static unsigned long __init zone_spanned_pages_in_node(int nid,
unsigned long zone_type,
@@ -1218,13 +1192,33 @@ static unsigned long __init zone_spanned_pages_in_node(int nid,
{
unsigned long zone_low = arch_zone_lowest_possible_pfn[zone_type];
unsigned long zone_high = arch_zone_highest_possible_pfn[zone_type];
+ unsigned long movable_pfn = zone_movable_pfn[nid];
/* Get the start and end of the zone */
*zone_start_pfn = clamp(node_start_pfn, zone_low, zone_high);
*zone_end_pfn = clamp(node_end_pfn, zone_low, zone_high);
- adjust_zone_range_for_zone_movable(nid, zone_type, node_end_pfn,
- zone_start_pfn, zone_end_pfn);
+ /* Nothing to adjust if ZONE_MOVABLE is not on this node */
+ if (!movable_pfn)
+ goto out;
+
+ /* Size ZONE_MOVABLE */
+ if (zone_type == ZONE_MOVABLE) {
+ *zone_start_pfn = movable_pfn;
+ *zone_end_pfn = min(node_end_pfn,
+ arch_zone_highest_possible_pfn[movable_zone]);
+
+ /* Adjust for ZONE_MOVABLE starting within this range */
+ } else if (*zone_start_pfn < movable_pfn &&
+ *zone_end_pfn > movable_pfn) {
+ *zone_end_pfn = movable_pfn;
+
+ /* Check if this whole range is within ZONE_MOVABLE */
+ } else if (*zone_start_pfn >= movable_pfn) {
+ *zone_start_pfn = *zone_end_pfn;
+ }
+
+out:
/* Check that this node has pages within the zone's required range */
if (*zone_end_pfn < node_start_pfn || *zone_start_pfn > node_end_pfn)
return 0;
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 2/2] mm/mm_init: simplify ZONE_MOVABLE branch in zone_spanned_pages_in_node()
2026-08-14 13:37 [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node() Sang-Heon Jeon
2026-08-14 13:37 ` [PATCH v3 1/2] mm/mm_init: fold adjust_zone_range_for_zone_movable() into its only caller Sang-Heon Jeon
@ 2026-08-14 13:37 ` Sang-Heon Jeon
2026-08-23 14:21 ` [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node() Mike Rapoport
2 siblings, 0 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-08-14 13:37 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton; +Cc: linux-kernel, linux-mm
*zone_start_pfn and *zone_end_pfn are first assigned
clamp(node_start_pfn, zone_low, zone_high) and clamp(node_end_pfn,
zone_low, zone_high).
If movable_pfn != 0, the branches adjust them as follows.
1. If zone_type == ZONE_MOVABLE, *zone_start_pfn = movable_pfn, which
can be outside the node, and *zone_end_pfn =
min(node_end_pfn, ...), which is at most node_end_pfn.
2. Else If *zone_start_pfn < movable_pfn < *zone_end_pfn,
*zone_end_pfn = movable_pfn.
3. Else If *zone_start_pfn >= movable_pfn, *zone_start_pfn =
*zone_end_pfn.
4. Else *zone_start_pfn < movable_pfn && *zone_end_pfn <= movable_pfn,
and nothing is assigned.
If node_end_pfn < zone_low or node_start_pfn > zone_high,
*zone_start_pfn and *zone_end_pfn are both zone_low or both
zone_high, outside the node.
Then case 2 cannot apply, in case 3 *zone_start_pfn = *zone_end_pfn,
which is that same pfn, and in case 4 nothing is assigned. So the
check against node_start_pfn and node_end_pfn returns 0 early.
Otherwise node_start_pfn <= *zone_start_pfn <= *zone_end_pfn <=
node_end_pfn.
Then in case 2 *zone_end_pfn = movable_pfn, in case 3
*zone_start_pfn = *zone_end_pfn, and in case 4 nothing is assigned.
So *zone_start_pfn and *zone_end_pfn stay within the node, the check
does not return 0, and min(*zone_end_pfn, node_end_pfn) and
max(*zone_start_pfn, node_start_pfn) change nothing.
So the check, min(*zone_end_pfn, node_end_pfn), and
max(*zone_start_pfn, node_start_pfn) only have an effect in case 1.
Also, cases 2 and 4 both have *zone_start_pfn < movable_pfn, and
min(*zone_end_pfn, movable_pfn) is movable_pfn in case 2 and
*zone_end_pfn in case 4. So the two cases can be merged into one
branch and case 3 becomes its else.
So remove *zone_end_pfn = min(*zone_end_pfn, node_end_pfn), move the
check and *zone_start_pfn = max(*zone_start_pfn, node_start_pfn)
inside the ZONE_MOVABLE branch, and merge cases 2 and 4 with
*zone_end_pfn = min(*zone_end_pfn, movable_pfn).
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/mm_init.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index df67d4e6f646..ab445111a846 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1208,25 +1208,24 @@ static unsigned long __init zone_spanned_pages_in_node(int nid,
*zone_end_pfn = min(node_end_pfn,
arch_zone_highest_possible_pfn[movable_zone]);
- /* Adjust for ZONE_MOVABLE starting within this range */
- } else if (*zone_start_pfn < movable_pfn &&
- *zone_end_pfn > movable_pfn) {
- *zone_end_pfn = movable_pfn;
+ /* Check that this node has pages within the zone's required range */
+ if (*zone_end_pfn < node_start_pfn ||
+ *zone_start_pfn > node_end_pfn)
+ return 0;
- /* Check if this whole range is within ZONE_MOVABLE */
- } else if (*zone_start_pfn >= movable_pfn) {
+ /* Move the zone start inside the node if necessary */
+ *zone_start_pfn = max(*zone_start_pfn, node_start_pfn);
+
+ /* This range starts below ZONE_MOVABLE */
+ } else if (*zone_start_pfn < movable_pfn) {
+ *zone_end_pfn = min(*zone_end_pfn, movable_pfn);
+
+ /* This whole range is within ZONE_MOVABLE */
+ } else {
*zone_start_pfn = *zone_end_pfn;
}
out:
- /* Check that this node has pages within the zone's required range */
- if (*zone_end_pfn < node_start_pfn || *zone_start_pfn > node_end_pfn)
- return 0;
-
- /* Move the zone boundaries inside the node if necessary */
- *zone_end_pfn = min(*zone_end_pfn, node_end_pfn);
- *zone_start_pfn = max(*zone_start_pfn, node_start_pfn);
-
/* Return the spanned pages */
return *zone_end_pfn - *zone_start_pfn;
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node()
2026-08-14 13:37 [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node() Sang-Heon Jeon
2026-08-14 13:37 ` [PATCH v3 1/2] mm/mm_init: fold adjust_zone_range_for_zone_movable() into its only caller Sang-Heon Jeon
2026-08-14 13:37 ` [PATCH v3 2/2] mm/mm_init: simplify ZONE_MOVABLE branch in zone_spanned_pages_in_node() Sang-Heon Jeon
@ 2026-08-23 14:21 ` Mike Rapoport
2026-08-23 15:27 ` Sang-Heon Jeon
2 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2026-08-23 14:21 UTC (permalink / raw)
To: Sang-Heon Jeon; +Cc: Andrew Morton, Mike Rapoport, linux-kernel, linux-mm
Hi,
> Hello,
>
> This series simplifies zone_spanned_pages_in_node(), which adjusts
> *zone_start_pfn and *zone_end_pfn before and after calling
> adjust_zone_range_for_zone_movable(). The helper adjusts the same two
> values, which makes the code harder to follow.
I'm not convinced that the result is easier to follow.
Indeed the same start and end variables are updated before and after
adjust_zone_range_for_zone_movable(), but it's clear that movable zone
adjustments require this.
Having the same adjustments inline forces the reader to track the exact
range comparison with and without zone movable and I don't see it as a
win.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node()
2026-08-23 14:21 ` [PATCH v3 0/2] mm/mm_init: simplify zone_spanned_pages_in_node() Mike Rapoport
@ 2026-08-23 15:27 ` Sang-Heon Jeon
0 siblings, 0 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-08-23 15:27 UTC (permalink / raw)
To: Mike Rapoport; +Cc: Andrew Morton, linux-kernel, linux-mm
Hello,
On Sun, Aug 23, 2026 at 11:21 PM Mike Rapoport <rppt@kernel.org> wrote:
>
> Hi,
>
> > Hello,
> >
> > This series simplifies zone_spanned_pages_in_node(), which adjusts
> > *zone_start_pfn and *zone_end_pfn before and after calling
> > adjust_zone_range_for_zone_movable(). The helper adjusts the same two
> > values, which makes the code harder to follow.
>
> I'm not convinced that the result is easier to follow.
>
> Indeed the same start and end variables are updated before and after
> adjust_zone_range_for_zone_movable(), but it's clear that movable zone
> adjustments require this.
>
> Having the same adjustments inline forces the reader to track the exact
> range comparison with and without zone movable and I don't see it as a
> win.
Thanks for the careful review.
Fair point. Inlining the helper is needed to remove the updates that
have no effect, but it might make the boundary less clear. I'll drop
the series.
> --
> Sincerely yours,
> Mike.
>
Best Regards
Sang-Heon Jeon
^ permalink raw reply [flat|nested] 5+ messages in thread