From nobody Wed Dec 17 06:05:34 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 2911D31A814 for ; Mon, 15 Dec 2025 12:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765800455; cv=none; b=iFh430MeQtacQ2/NkwxrKosxsOKyknk5B887Xjpd3zYMNBcV6wJGyU1PwApA79xfkOhRWBwjHGJX7QrPMiDkOKTZFJG7YXbNWCY2kdI4KrPY9Ggv4LuLhBv/b3YrN1/Zc9s3PEvu5+rvRC7LoncpXcmX+PPbBOQPdjxnd55kMT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765800455; c=relaxed/simple; bh=X0xeLrf1TXcns3kKgLXAP+OUewmmoGYtUK735svAtxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hKITa4DwyRytgukO4YTfwAKghV8iKIXF/QVZTGFrZWsN2Bk9rBSjxt7/VehSej+iieG1Y42bH0BJT6c1KrgNAtPZi0TpXXM/OOIIltv7bRKft4z/V/X9nLpHvtQpd1IWPpx3rzLdpFuvuWBtrgyAAZ+3E1JTVU/QrFSJ9JQqczU= 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=jWcTlPWL; arc=none smtp.client-ip=198.175.65.12 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="jWcTlPWL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765800455; x=1797336455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X0xeLrf1TXcns3kKgLXAP+OUewmmoGYtUK735svAtxc=; b=jWcTlPWLAWs1ZAdeiBEM7aMn9jXYDmJ9FBLFC4YF81iK/wHmcPZoT+wG RV3MYkWaZf4aW+R7sfJmNas/oWCb21iibQTb3NSlKVitblYbJfnHVaGgx UslHO3gyl1xbnMDiaxn5j9ilRTvmVqHHFGlJK1Lw4W4faxS0g/v6Rp5gk ApSvEMvI6iJRBFl48rv1f7mIE/6pBVaJcR4ctVHZ6AMi/Ovo70hvwJr5B IKy+C92AKkNdNaPWSG2p65186xhghEb4b0o6IQzMlgbOKRV18T0EaEjWM zq9F97mMbpooIzxUSa9Gk4bnCgIwmc1N+vspTOe5bhglyisg3yaUy3m8B A==; X-CSE-ConnectionGUID: HYaqpJCBT0ii+CevLEFZiQ== X-CSE-MsgGUID: ROfsUJQ1SR2nN9YxF4LV5A== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="79154776" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="79154776" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2025 04:07:34 -0800 X-CSE-ConnectionGUID: J2n7uCkoRX2NsrRxNQD4YQ== X-CSE-MsgGUID: DphniEEzSKWRj3L5PshQqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="228357219" Received: from linux-pnp-server-27.sh.intel.com ([10.239.147.41]) by orviesa002.jf.intel.com with ESMTP; 15 Dec 2025 04:07:30 -0800 From: Tianyou Li To: David Hildenbrand , Oscar Salvador , Mike Rapoport , Wei Yang 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 v6 2/2] mm/memory hotplug: fix zone->contiguous always false when hotplug Date: Mon, 15 Dec 2025 21:04:37 +0800 Message-ID: <20251215130437.3914342-3-tianyou.li@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215130437.3914342-1-tianyou.li@intel.com> References: <20251215130437.3914342-1-tianyou.li@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuan Liu Function set_zone_contiguous used __pageblock_pfn_to_page to check the whole pageblock is in the same zone. One assumption is the memory section must online, otherwise the __pageblock_pfn_to_page will return NULL, then the set_zone_contiguous will be false. When move_pfn_range_to_zone invoked set_zone_contiguous, since the memory section did not online, the return value will always be false. To fix this issue, we removed the set_zone_contiguous from the move_pfn_range_to_zone, and place it after memory section onlined. Function remove_pfn_range_from_zone did not have this issue because memory section remains online at the time set_zone_contiguous invoked. Reviewed-by: Tianyou Li Reviewed-by: Nanhai Zou Signed-off-by: Yuan Liu --- mm/memory_hotplug.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 12839032ad42..0220021f6a68 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -810,8 +810,7 @@ void move_pfn_range_to_zone(struct zone *zone, unsigned= long start_pfn, { struct pglist_data *pgdat =3D zone->zone_pgdat; int nid =3D pgdat->node_id; - const enum zone_contig_state new_contiguous_state =3D - zone_contig_state_after_growing(zone, start_pfn, nr_pages); + clear_zone_contiguous(zone); =20 if (zone_is_empty(zone)) @@ -841,8 +840,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, new_contiguous_state); } =20 struct auto_movable_stats { @@ -1151,6 +1148,7 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsi= gned long nr_pages, { unsigned long end_pfn =3D pfn + nr_pages; int ret, i; + enum zone_contig_state new_contiguous_state =3D ZONE_CONTIG_NO; =20 ret =3D kasan_add_zero_shadow(__va(PFN_PHYS(pfn)), PFN_PHYS(nr_pages)); if (ret) @@ -1165,6 +1163,14 @@ int mhp_init_memmap_on_memory(unsigned long pfn, uns= igned long nr_pages, if (mhp_off_inaccessible) page_init_poison(pfn_to_page(pfn), sizeof(struct page) * nr_pages); =20 + /* + * If the allocated memmap pages are not in a full section, keep the + * contiguous state as ZONE_CONTIG_NO. + */ + if (IS_ALIGNED(end_pfn, PAGES_PER_SECTION)) + new_contiguous_state =3D zone_contig_state_after_growing(zone, + pfn, nr_pages); + move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE, false); =20 @@ -1183,6 +1189,7 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsi= gned long nr_pages, if (nr_pages >=3D PAGES_PER_SECTION) online_mem_sections(pfn, ALIGN_DOWN(end_pfn, PAGES_PER_SECTION)); =20 + set_zone_contiguous(zone, new_contiguous_state); return ret; } =20 @@ -1221,6 +1228,7 @@ int online_pages(unsigned long pfn, unsigned long nr_= pages, }; const int nid =3D zone_to_nid(zone); int need_zonelists_rebuild =3D 0; + enum zone_contig_state new_contiguous_state =3D ZONE_CONTIG_NO; unsigned long flags; int ret; =20 @@ -1235,6 +1243,7 @@ int online_pages(unsigned long pfn, unsigned long nr_= pages, !IS_ALIGNED(pfn + nr_pages, PAGES_PER_SECTION))) return -EINVAL; =20 + new_contiguous_state =3D zone_contig_state_after_growing(zone, pfn, nr_pa= ges); =20 /* associate pfn range with the zone */ move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_MOVABLE, @@ -1273,6 +1282,7 @@ int online_pages(unsigned long pfn, unsigned long nr_= pages, } =20 online_pages_range(pfn, nr_pages); + set_zone_contiguous(zone, new_contiguous_state); adjust_present_page_count(pfn_to_page(pfn), group, nr_pages); =20 if (node_arg.nid >=3D 0) --=20 2.47.1