From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 EE527327BEB for ; Mon, 8 Dec 2025 14:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765204110; cv=none; b=XVtkjldzozYN9Ocz/cS32fSKRvmhFUPdckjJ5iRIhnxunBsS6YQKfWhzrdnPFGLX9Ty+QqD3Vpfu59UtwQH4pRPqbwDPR1r0Uvy+91Zk85P4gcOk4aSTuEjZZgSiRNO4CrPzgUua9Xv/t/wqUM+xj2s4dYMmFVFqtywhqPP7bYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765204110; c=relaxed/simple; bh=/fQGvXBGLr7zSEqagmAWMLnNuEXBlmlyD9qytz8sS1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y34YBfaEE/kKa9JrpZcFMJLS0P5cBmb0ioLDXV2pUQPcM/Qx4K0HwCCQeU3yUiitHfN3QlkwzeehgL93J++RqDgDM8XJc/hYJStw8ECDlvl6sZEwTo3r8wNf1L7yDbI9NatgG0bX9us4zvTOHe7bIJsAtH9qY6zgJqpm6S5W7P4= 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=Gc2QFgSm; arc=none smtp.client-ip=192.198.163.14 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="Gc2QFgSm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765204109; x=1796740109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/fQGvXBGLr7zSEqagmAWMLnNuEXBlmlyD9qytz8sS1w=; b=Gc2QFgSmDkE89choPeMpUTzdFwOe5ZRz1ZM94or5QjdtzO18SrD1qLpC 78H0/rcK7XYQ87Zme3c5CbOc/U8j/k+KI23Qz0QjuDqfpkhV7fuPhM97w p4ukJVFInS5AHQVc0MgtzqDFSXPPhGqgLQt/GgqzJTZIef5HS7j0+gLkc hzUbdWTmNoTxxFJHrW3zeArV6Q0Uy+HkO1E3XLV+FJ7QVMK7+hNm7Yam8 nUHCqzBPnafIAj+qMmcBJzkMqW4+f0kSmy/dzUN536BrdH85omd6vbgpm 5Cs+5EA8GCmq710914N2gNvJEk4ZAJJMLe849Jm91zwmiHh3vTpHlUlqY A==; X-CSE-ConnectionGUID: M35nAVRgRDG8f5pdcGcb0A== X-CSE-MsgGUID: f6Mn4+IQTGCz5Fa0YOs8FA== X-IronPort-AV: E=McAfee;i="6800,10657,11636"; a="67181556" X-IronPort-AV: E=Sophos;i="6.20,258,1758610800"; d="scan'208";a="67181556" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2025 06:28:28 -0800 X-CSE-ConnectionGUID: TtX4Sfj+TC+R+w5MLaTyPQ== X-CSE-MsgGUID: 2KxPqU4mQFSQ0Oq25J6Z3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,258,1758610800"; d="scan'208";a="233317824" Received: from linux-pnp-server-27.sh.intel.com ([10.239.147.41]) by orviesa001.jf.intel.com with ESMTP; 08 Dec 2025 06:28:25 -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 v5 2/2] mm/memory hotplug: fix zone->contiguous always false when hotplug Date: Mon, 8 Dec 2025 23:25:44 +0800 Message-ID: <20251208152544.1150732-3-tianyou.li@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251208152544.1150732-1-tianyou.li@intel.com> References: <20251208152544.1150732-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: 8bit 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index d711f6e2c87f..f548d9180415 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -809,8 +809,7 @@ void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, { struct pglist_data *pgdat = zone->zone_pgdat; int nid = pgdat->node_id; - const enum zone_contig_state contiguous_state = - zone_contig_state_after_growing(zone, start_pfn, nr_pages); + clear_zone_contiguous(zone); if (zone_is_empty(zone)) @@ -840,8 +839,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, contiguous_state); } struct auto_movable_stats { @@ -1150,6 +1147,7 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, { unsigned long end_pfn = pfn + nr_pages; int ret, i; + enum zone_contig_state contiguous_state = ZONE_CONTIG_NO; ret = kasan_add_zero_shadow(__va(PFN_PHYS(pfn)), PFN_PHYS(nr_pages)); if (ret) @@ -1164,6 +1162,10 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, if (mhp_off_inaccessible) page_init_poison(pfn_to_page(pfn), sizeof(struct page) * nr_pages); + if (IS_ALIGNED(end_pfn, PAGES_PER_SECTION)) + contiguous_state = zone_contig_state_after_growing(zone, pfn, + nr_pages); + move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE, false); @@ -1182,6 +1184,7 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, if (nr_pages >= PAGES_PER_SECTION) online_mem_sections(pfn, ALIGN_DOWN(end_pfn, PAGES_PER_SECTION)); + set_zone_contiguous(zone, contiguous_state); return ret; } @@ -1220,6 +1223,7 @@ int online_pages(unsigned long pfn, unsigned long nr_pages, }; const int nid = zone_to_nid(zone); int need_zonelists_rebuild = 0; + enum zone_contig_state contiguous_state = ZONE_CONTIG_NO; unsigned long flags; int ret; @@ -1234,6 +1238,7 @@ int online_pages(unsigned long pfn, unsigned long nr_pages, !IS_ALIGNED(pfn + nr_pages, PAGES_PER_SECTION))) return -EINVAL; + contiguous_state = zone_contig_state_after_growing(zone, pfn, nr_pages); /* associate pfn range with the zone */ move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_MOVABLE, @@ -1272,6 +1277,7 @@ int online_pages(unsigned long pfn, unsigned long nr_pages, } online_pages_range(pfn, nr_pages); + set_zone_contiguous(zone, contiguous_state); adjust_present_page_count(pfn_to_page(pfn), group, nr_pages); if (node_arg.nid >= 0) -- 2.47.1