From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B1A540B39F for ; Thu, 23 Jul 2026 08:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784796356; cv=none; b=bpE1Yy0qhJRKU6wkKQbZ83jIx8KpImGdgFfEhAjR8oFKI99sRXAlm98VnL03TNYap1DEwY222ckYmqyI1cl5//SIlIBjkhD4kVLoACiDAhzm6aEMdwgPj4g8cqNzd/Rfh2tT/PmWrzvdlwNMsKUtKu15sBdHlSVcOELmPD62tl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784796356; c=relaxed/simple; bh=7rbY+wmZoNdck+weN1iewQCGpYuqzUNthhhl13Abfnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ux0fCv3qyHtb/aEqGHxrIIjmWrAtqLv2yVGvhO2SgkdfLQru3v0RA3W2vcIKZZEKOSj0kPSwQPd/nhRv8uCiKIDzqJ9GCGXaPtCsV8d/8MOY55UbZzhtdzsu0ToyMmjbKvTO2Gbbpezjn1N0VmM3ku90bgcGb1+R//kg4ZjQPfM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DJ74iq71; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DJ74iq71" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1784796355; x=1816332355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7rbY+wmZoNdck+weN1iewQCGpYuqzUNthhhl13Abfnc=; b=DJ74iq716ELiCikcGhqTXRbWslafIfwkXDX5YbTmCAe86gBNHPJUTFNV 5TFgbMUdoMHCxdRtDNgs2ojDlAfJnml14Sr/PqSRChO7E0rXOuiZrkF8c A2axZ/DCc+57SAB6/YKhbbLsVchgxRR1mEBLpyKclo8Opyp/5tbtMHZOM S1E7mw+UnqB8MhNfKzFy9u8Res950jY08PzS8jua1H0ubQU2vFLxh0hmd /0JFrtyLtvlzuRLy1AZgb3kcxtVPwiL6RMoXM9SsvEo4xCy7bVEY96gvu M2p5ClCizN2XXDw/x82nGnH+aBtr8JYcRbS2rm7b5oHTWWOrMOifXV00Z Q==; X-CSE-ConnectionGUID: WpW0GD3bSn2Bd+q/fwGd7Q== X-CSE-MsgGUID: Tz9AI+IlRf60TEQqc7sBOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11854"; a="72986450" X-IronPort-AV: E=Sophos;i="6.25,180,1779174000"; d="scan'208";a="72986450" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2026 01:45:54 -0700 X-CSE-ConnectionGUID: FUhMTWgORFmJguJuC3tvsA== X-CSE-MsgGUID: ID6ghIrQTSmIBXZJFQdXXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,180,1779174000"; d="scan'208";a="254966703" Received: from spr10.sh.intel.com (HELO localhost) ([10.239.23.75]) by fmviesa007.fm.intel.com with ESMTP; 23 Jul 2026 01:45:52 -0700 From: Yuan Liu To: David Hildenbrand , Oscar Salvador , Mike Rapoport , Wei Yang Cc: linux-mm@kvack.org, Nanhai Zou , Yuan Liu , Pan Deng , Tianyou Li , Chen Zhang , Jason Zeng , linux-kernel@vger.kernel.org Subject: [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Date: Thu, 23 Jul 2026 04:49:46 -0400 Message-ID: <20260723084946.189392-3-yuan1.liu@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260723084946.189392-1-yuan1.liu@intel.com> References: <20260723084946.189392-1-yuan1.liu@intel.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 When shrinking a zone span after removing a PFN range, find_smallest_section_pfn() and find_biggest_section_pfn() only checked one edge PFN in each subsection for nid/zone matching. If a memory or hole boundary falls in the middle of a subsection, that edge PFN may belong to a different nid/zone, causing the helpers to miss a valid PFN within that subsection. Fix this by checking both subsection edge PFNs for nid/zone matching. Keep a single pfn_to_online_page() check per subsection, since online state is the same for all PFNs in a subsection. Reviewed-by: Jason Zeng Signed-off-by: Yuan Liu --- mm/memory_hotplug.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 4c699fd9c479..3a281d595207 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -427,17 +427,24 @@ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { - for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SUBSECTION) { - if (unlikely(!pfn_to_online_page(start_pfn))) - continue; + unsigned long next_pfn; - if (unlikely(pfn_to_nid(start_pfn) != nid)) - continue; + for (; start_pfn < end_pfn; start_pfn = next_pfn) { + unsigned long tail_pfn; - if (zone != page_zone(pfn_to_page(start_pfn))) + next_pfn = start_pfn + PAGES_PER_SUBSECTION; + tail_pfn = next_pfn - 1; + + if (unlikely(!pfn_to_online_page(start_pfn))) continue; - return start_pfn; + if (likely(pfn_to_nid(start_pfn) == nid) && + zone == page_zone(pfn_to_page(start_pfn))) + return start_pfn; + + if (likely(pfn_to_nid(tail_pfn) == nid) && + zone == page_zone(pfn_to_page(tail_pfn))) + return start_pfn; } return 0; @@ -448,21 +455,26 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { - unsigned long pfn; + unsigned long pfn, prev_pfn; /* pfn is the end pfn of a memory section. */ pfn = end_pfn - 1; - for (; pfn >= start_pfn; pfn -= PAGES_PER_SUBSECTION) { - if (unlikely(!pfn_to_online_page(pfn))) - continue; + for (; pfn >= start_pfn; pfn = prev_pfn) { + unsigned long head_pfn; - if (unlikely(pfn_to_nid(pfn) != nid)) - continue; + prev_pfn = pfn - PAGES_PER_SUBSECTION; + head_pfn = prev_pfn + 1; - if (zone != page_zone(pfn_to_page(pfn))) + if (unlikely(!pfn_to_online_page(pfn))) continue; - return pfn; + if (likely(pfn_to_nid(pfn) == nid) && + zone == page_zone(pfn_to_page(pfn))) + return pfn; + + if (likely(pfn_to_nid(head_pfn) == nid) && + zone == page_zone(pfn_to_page(head_pfn))) + return pfn; } return 0; -- 2.47.3