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 v3 2/2] mm/mm_init: simplify ZONE_MOVABLE branch in zone_spanned_pages_in_node()
Date: Fri, 14 Aug 2026 22:37:39 +0900 [thread overview]
Message-ID: <20260814133744.2746782-3-ekffu200098@gmail.com> (raw)
In-Reply-To: <20260814133744.2746782-1-ekffu200098@gmail.com>
*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
prev parent reply other threads:[~2026-08-14 13:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20260814133744.2746782-3-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