From nobody Sat Feb 7 23:10:53 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 1645A155A5D for ; Fri, 30 Jan 2026 15:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769785561; cv=none; b=rVkalmYkoNfmef4SMGzb5Sff+aWIA1yCqLBNA+C4ZO20da4UlqSmRZb7xwes72sQuHPtuVd6JzulkvvE8srE69i+wAqmwRAARb1qv4wUHCxop7AThufmnSHIxeb/mEElO3dhhvOTSX4cv/lp/FYPV7cSRU6jtcwegKsKiY/NFxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769785561; c=relaxed/simple; bh=z4itQQ8EdTou0Lagf7D+EwlyGfKDCiq3jLuL7LgiGg0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GwKWBfIi5kkzEciUby5+6cqTMGW2/i+QVsu7Lm5gYm7V6ZB8NJJF+aI1KAcCQrneRppn4vEf+DLdwmx9vjLY6AB7pfs6NnlYQx0coMPHUFUlNVWJlkJlLoUvrGppwcQWsDGVjzlLE1dGTZxgQI0o5j82Z7GKRVy2JQqFQwbL4MM= 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=BVzwp5Lu; arc=none smtp.client-ip=198.175.65.17 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="BVzwp5Lu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769785559; x=1801321559; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=z4itQQ8EdTou0Lagf7D+EwlyGfKDCiq3jLuL7LgiGg0=; b=BVzwp5Lu3h+ZeiO1zEnC+D2mnwpSktZSslsoPNPcN61H3a0Xv6Y3oN1i HFHGqa1DgRmUpaIf67PAaDMMvzO/azFHGtLWJ8ds0sSatCaWS/lGaF3pr QmKLZOq5638w+2y/Q8oXd2rgFP1B1qnocU082McQFDrgYkZ5QgdQlBnNj UMHtA8E/325qtUhR0cWFtvVAtReHLaa1lNHLyIAe/PvDq7Loud65+3A6Z v2tNzhjyLJQziA1Q/6fGcbXpVTgvBjOS4sn397ukm+ilbfJrmCQ/7rh8g XcBKUO3z7bgyFIq/QioEhwREjiqKrLCZeUQL6VOqeFBYyEszqgRG4fWyo Q==; X-CSE-ConnectionGUID: oUuid8I0TDOHzUPifxbWCQ== X-CSE-MsgGUID: 0t+13HdbQ/KICdR6XGn9PA== X-IronPort-AV: E=McAfee;i="6800,10657,11686"; a="71013652" X-IronPort-AV: E=Sophos;i="6.21,263,1763452800"; d="scan'208";a="71013652" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2026 07:05:58 -0800 X-CSE-ConnectionGUID: OS+Ay1+8STmH7nrELmRnXw== X-CSE-MsgGUID: VSHojw0JQHm9OFBmlmf1kg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,263,1763452800"; d="scan'208";a="231798299" Received: from linux-pnp-server-27.sh.intel.com ([10.239.147.41]) by fmviesa002.fm.intel.com with ESMTP; 30 Jan 2026 07:05:55 -0800 From: Tianyou Li To: David Hildenbrand , Oscar Salvador , Mike Rapoport , Wei Yang , Michal Hocko Cc: linux-mm@kvack.org, Yong Hu , Nanhai Zou , Yuan Liu , Tim Chen , Qiuxu Zhuo , Yu C Chen , Pan Deng , Tianyou Li , Chen Zhang , linux-kernel@vger.kernel.org Subject: [PATCH v9] mm/memory hotplug: Fix zone->contiguous always false when hotplug Date: Sat, 31 Jan 2026 00:06:35 +0800 Message-ID: <20260130160635.2671167-1-tianyou.li@intel.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuan Liu set_zone_contiguous() uses __pageblock_pfn_to_page() to detect pageblocks that either do not exist (hole) or that do not belong to the same zone. __pageblock_pfn_to_page(), however, relies on pfn_to_online_page(), effectively always returning NULL for memory ranges that were not onlined yet. So when called on a range-to-be-onlined, it indicates a memory hole to set_zone_contiguous(). Consequently, the set_zone_contiguous() call in move_pfn_range_to_zone(), which happens early during memory onlining, will never detect a zone as being contiguous. Bad: the fast path relies on the zone contiguous state may skipped. To fix the issue, move the set_zone_contiguous() call to a later stage in memory onlining, where pfn_to_online_page() will succeed: after we mark the memory sections to be online. Fixes: 2d070eab2e82 ("mm: consider zone which is not fully populated to hav= e holes") Cc: Michal Hocko Cc: stable@vger.kernel.org Reviewed-by: Nanhai Zou Signed-off-by: Yuan Liu Signed-off-by: Tianyou Li --- Separated from: https://lore.kernel.org/linux-mm/20260120143346.1427837-1-t= ianyou.li@intel.com/ mm/memory_hotplug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index a63ec679d861..c8f492b5daf0 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -782,8 +782,6 @@ void move_pfn_range_to_zone(struct zone *zone, unsigned= long start_pfn, memmap_init_range(nr_pages, nid, zone_idx(zone), start_pfn, 0, MEMINIT_HOTPLUG, altmap, migratetype, isolate_pageblock); - - set_zone_contiguous(zone); } =20 struct auto_movable_stats { @@ -1205,6 +1203,13 @@ int online_pages(unsigned long pfn, unsigned long nr= _pages, } =20 online_pages_range(pfn, nr_pages); + + /* + * Now that the ranges are indicated as online, check whether the whole + * zone is contiguous. + */ + set_zone_contiguous(zone); + adjust_present_page_count(pfn_to_page(pfn), group, nr_pages); =20 if (node_arg.nid >=3D 0) --=20 2.47.1