[PATCH 3/4] mm/mm_init: move the range check and clamping inside ZONE_MOVABLE branch
From: Sang-Heon Jeon
Date: Tue Aug 04 2026 - 12:07:05 EST
Outside the ZONE_MOVABLE branch the check and the clamping have no
effect, because every branch ends with one of the following.
- *zone_start_pfn == *zone_end_pfn, so the function returns 0 anyway.
- node_start_pfn <= *zone_start_pfn <= *zone_end_pfn <= node_end_pfn,
so the check does not return 0 and max(*zone_start_pfn,
node_start_pfn) is always *zone_start_pfn.
The branches set *zone_start_pfn and *zone_end_pfn as follows.
1. If zone_movable_pfn[nid] != 0 && zone_type == ZONE_MOVABLE,
*zone_start_pfn = zone_movable_pfn[nid] and *zone_end_pfn =
min(node_end_pfn, ...).
2. Else If zone_movable_pfn[nid] != 0 && !mirrored_kernelcore &&
*zone_start_pfn < zone_movable_pfn[nid] < *zone_end_pfn,
*zone_end_pfn = zone_movable_pfn[nid].
The condition requires the clamped *zone_start_pfn and
*zone_end_pfn to differ, which cannot happen when node_end_pfn <
zone_low or node_start_pfn > zone_high.
So *zone_start_pfn = max(node_start_pfn, zone_low) >=
node_start_pfn, and zone_movable_pfn[nid] < clamped *zone_end_pfn =
min(node_end_pfn, zone_high) <= node_end_pfn.
So node_start_pfn <= *zone_start_pfn < *zone_end_pfn <=
node_end_pfn.
3. Else If zone_movable_pfn[nid] != 0 && *zone_start_pfn >=
zone_movable_pfn[nid], *zone_start_pfn = *zone_end_pfn.
4. Else *zone_start_pfn = clamp(node_start_pfn, zone_low, zone_high)
and *zone_end_pfn = clamp(node_end_pfn, zone_low, zone_high)
a. If node_end_pfn < zone_low, *zone_start_pfn = *zone_end_pfn =
zone_low.
b. If node_start_pfn > zone_high, *zone_start_pfn = *zone_end_pfn =
zone_high.
c. If node_end_pfn >= zone_low && node_start_pfn <= zone_high,
node_start_pfn <= *zone_start_pfn <= *zone_end_pfn <=
node_end_pfn.
So move both inside the ZONE_MOVABLE branch.
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@xxxxxxxxx>
---
mm/mm_init.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 75fe1918d4d4..1190a27ed0fb 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1253,6 +1253,17 @@ 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]);
+ /*
+ * 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 start inside the node if necessary */
+ *zone_start_pfn = max(*zone_start_pfn, node_start_pfn);
+
/* Adjust for ZONE_MOVABLE starting within this range */
} else if (!mirrored_kernelcore &&
*zone_start_pfn < zone_movable_pfn[nid] &&
@@ -1264,13 +1275,6 @@ static unsigned long __init zone_spanned_pages_in_node(int nid,
*zone_start_pfn = *zone_end_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;
-
- /* Move the zone boundaries inside the node if necessary */
- *zone_start_pfn = max(*zone_start_pfn, node_start_pfn);
-
/* Return the spanned pages */
return *zone_end_pfn - *zone_start_pfn;
}
--
2.43.0