From: Sang-Heon Jeon <ekffu200098@gmail.com>
To: Mike Rapoport <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH v2 3/5] mm/mm_init: move the range check and clamping inside ZONE_MOVABLE branch
Date: Fri, 7 Aug 2026 01:20:54 +0900 [thread overview]
Message-ID: <20260806162100.313965-4-ekffu200098@gmail.com> (raw)
In-Reply-To: <20260806162100.313965-1-ekffu200098@gmail.com>
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 &&
*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@gmail.com>
---
mm/mm_init.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index bdc15de0a62a..fa6b5977261f 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1205,6 +1205,14 @@ 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 (*zone_start_pfn < zone_movable_pfn[nid] &&
*zone_end_pfn > zone_movable_pfn[nid]) {
@@ -1215,13 +1223,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 start 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
next prev parent reply other threads:[~2026-08-06 16:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 16:20 [PATCH v2 0/5] mm/mm_init: simplify zone_spanned_pages_in_node() Sang-Heon Jeon
2026-08-06 16:20 ` [PATCH v2 1/5] mm/mm_init: fold adjust_zone_range_for_zone_movable() into its only caller Sang-Heon Jeon
2026-08-06 16:20 ` [PATCH v2 2/5] mm/mm_init: remove redundant clamping in zone_spanned_pages_in_node() Sang-Heon Jeon
2026-08-06 16:20 ` Sang-Heon Jeon [this message]
2026-08-06 16:20 ` [PATCH v2 4/5] mm/mm_init: use min() when adjusting for ZONE_MOVABLE Sang-Heon Jeon
2026-08-06 16:20 ` [PATCH v2 5/5] mm/mm_init: clean up zone_spanned_pages_in_node() Sang-Heon Jeon
2026-08-13 19:11 ` [PATCH v2 0/5] mm/mm_init: simplify zone_spanned_pages_in_node() Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260806162100.313965-4-ekffu200098@gmail.com \
--to=ekffu200098@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®