From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F7B7483820 for ; Thu, 6 Aug 2026 16:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786033290; cv=none; b=PCbLhMNrAiqACLdr05CqBpSdkN5YLo+wlhRUbRIL7ptUmrwL2vzQxuvwrIUQmk1hpMf4l4rMZsm5VraOhk5z7WpvGyPCefge2zDvM3UDnmtzg9fvP8UykVv+p/nVIlpVIxSh4HUIjIpH6hW2BKcV3ulU761VFRa9QfpNjs/EPhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786033290; c=relaxed/simple; bh=AmE5+ppjhnHWG3atDjIHPwJR+SNZgEEPJcZMZaHCQS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a0p606p7s5NUXH7ESuSGqym+pa5RFdukpBsoG9SAC8z4fCPz091bCnRNAhZYdtc2XnRjeZ332oFxBwo02qagjwxqr8SEFeeUYA7EqjZFYO+5zLr35ShpUcEQjRgN281vb4qpqdhv6fRrO7is7YTreRXxc0rRV47NPalqc05bInc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d3WZPZW6; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d3WZPZW6" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-84e0688b7e8so2312721b3a.1 for ; Thu, 06 Aug 2026 09:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786033286; x=1786638086; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Siy56LUg0D3k/aJEZkR3M4GURDeHhGcCXphn6iQtEPY=; b=d3WZPZW6nuQZYkDyUiV6W7T4rMLHMgBY4lH2g0wqOniWNbyNZFZQEetF/N1fA+fvwm Q4p/5dFtGR0e/twD9V6HUm4fIiODu6NVZXATMecf9Jd6e8voD0Sjoj1ZBmR7eilEBeKc UKN0+5gwoKamIKo7X4ROh1kHm7hMa1+3JV7klhp3FVB+LruS8ygjmqmi0NoenzYrG4Eb TFoVx6egOGW/2rBASPnFOa0Utg0NzMuu7GshpTtycHYKnxZOT59iLt82kdx/cH5Q5bbU qd2QM3vFzttLXoYQ7AkjGrYRRaA/EpzYq2jN6V4McjS3bN32ASBTqoRLno3vvNDBRa0l vCxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786033286; x=1786638086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Siy56LUg0D3k/aJEZkR3M4GURDeHhGcCXphn6iQtEPY=; b=MPf5hYXuanj8p5QwhXPVCWB+ofpp7y/zuQ8Ha86N2CuyUAtd8NnIHVFLsVICDIWl0+ NPrK5PJj46S3RKUs4mYNBrcuJmtNnZiGqZMAn5/q/yj7GiDwMdS5BSb3RTsnGAICoRj3 Dg4b/IgrMP546juwcjFgNtrcyDws7monsVDOPWQ85EdhmPvFmY0x+lfyhbNc7YpfJ76a zibe64R3f/uo2+lkrGRduS0Um6e6bFlpt9LoYSoEg5BD5NdTO9nEQh79WssI2R05+VsW aFmjJk+kT51uzJBRM8ooj9HFwyIfGAAu0V0XKrbwKFoKdgq71mR1p76jT0fegjKgthWH j0cg== X-Gm-Message-State: AOJu0YyA/qB1KwnV9Sv4/gajUPxztnW6NkvF9Ooq5qB4er+PjeBERSmy xbN+GyQIKQwZxVNPyJy+O2aieB0bGGgGnVTVXFEi1khPMofqb12Dvuz5 X-Gm-Gg: AR+sD11wvbNyZ7DORvK+FSgpeGzYk7emiLkaSX8U5ICMMKwI/afXfqSwcnmNbr+aUwC 0yx1JatpaN4n0CwMnvDOCVowOOTb022GekaA4pkR8mLivwMl/58+u8XMBDvu4NrcDdDZNErQp4t ifxxZ+xmY2vSK8oopo0yfma3ZYnlLqXHnxWBqXIkry9ABRVGX1YqKILao7ogl2GRuXU04i9Yvx4 fAk+rVhmjFaQDFxCnPZcWQ4R20ILARvwqjMxi964rEhZbE/HgHcerM60HhGxqIbNmQoHbprt2XX gUQTwY93jjjOMYyKcv8kMMEVK1RTLmKs85p58KpsDz0Qu1B5Aruw6XvoE0HIwa3KiZiCknTpoq2 sC2TvNE7y+C1ROmnF1zt/nLPlk8n8cMHjhzQp9Ixgq7lZf9TziIDxxRR6n6aIRHv035xh8Xj9WX ZkqPurQgNX8U/IVI98y35wzl2pefj1ZoGOlTCafFni+NuauU2qLEYzhDnG X-Received: by 2002:a05:6a00:4ace:b0:84e:e741:175e with SMTP id d2e1a72fcca58-84f2e0294f3mr19717547b3a.31.1786033286323; Thu, 06 Aug 2026 09:21:26 -0700 (PDT) Received: from ubuntu.. ([110.9.142.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f459b66e6sm1662739b3a.40.2026.08.06.09.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 09:21:25 -0700 (PDT) From: Sang-Heon Jeon To: Mike Rapoport , Andrew Morton 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 Message-ID: <20260806162100.313965-4-ekffu200098@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260806162100.313965-1-ekffu200098@gmail.com> References: <20260806162100.313965-1-ekffu200098@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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