From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 A555D40B109 for ; Thu, 23 Jul 2026 08:45:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784796349; cv=none; b=SiC86FaJwY5zhdOHxM2UuKTKH8P3oCgw8QXq/2Y3FyHLJFlY0QK0djzaKcONdIixLSx2bMtSQfxr8puwSXLRBxjQXwUBC1mwM5Zkj9tVFrZthe0IvS958P9kZmO1TWfGjdaepE2lu5wgfgtEn0UZoCZwv5OhyTlw1Nqe0zxi3us= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784796349; c=relaxed/simple; bh=wt/1Q/1Uc8s3JGUPFe4oh+yq/wTku+L5499+dfNpp+A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VYR7V2xMhyVk2qdhCrrjxJFJKEz4Mqj1Bll0zznkTAx3DjYYKoBaAO8a2Xp0R4mNVmzB1n9BMr/dr/ZbbKQroPauoOMhf+Ram8S6bEDsdQRsMY+Vx9qm7uL8MPuBP2aAcZ/BB8YVSS4rLiGtxXZH9wN0Y5X/k3sCPiQM8Rx8sAg= 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=n/83yfdB; arc=none smtp.client-ip=198.175.65.10 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="n/83yfdB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1784796348; x=1816332348; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wt/1Q/1Uc8s3JGUPFe4oh+yq/wTku+L5499+dfNpp+A=; b=n/83yfdBmW32T5W2EO/zq+s3UMiPLsgUS3hFFQda8MLZrLGaDHurSuNz vT0VU2UvK0YutlNntFeQLB1LgRis4BJO8eDP8kkXNxzeifJSupWY88/73 zLrhJ0kBDmzkfxcWNR1AkuiaAB2uIYfClwGE8FGuRcEkQNbomtPf1a4B+ s9P+kfeUvB97lWgNCdhqcODhC8vz/yB+8NucBgXMw5PPh5Ffdnm+0a42c 0hJOqqJJkTV07HXVYyKHc/P8fQwThvZDzwnoiY0O04EINfYTtGPSmwpF/ MFnNcPq0KqsPVOFE0lidyfShTF8L/N4ShRzbgZWcW1mO+1eZLm8D51Z4V A==; X-CSE-ConnectionGUID: Y3KvKa9XT+iS+tjwFxn92g== X-CSE-MsgGUID: BpioDjaoTLOjNol8cC58jA== X-IronPort-AV: E=McAfee;i="6800,10657,11854"; a="102854651" X-IronPort-AV: E=Sophos;i="6.25,180,1779174000"; d="scan'208";a="102854651" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2026 01:45:47 -0700 X-CSE-ConnectionGUID: amV6tR1LQq2BfEoLMkFrqA== X-CSE-MsgGUID: 0Xxj1lxqTqW2HB+YmsYBiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,180,1779174000"; d="scan'208";a="258408727" Received: from spr10.sh.intel.com (HELO localhost) ([10.239.23.75]) by orviesa007.jf.intel.com with ESMTP; 23 Jul 2026 01:45:44 -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 0/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Date: Thu, 23 Jul 2026 04:49:44 -0400 Message-ID: <20260723084946.189392-1-yuan1.liu@intel.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series introduces a pages_with_online_memmap member into struct zone to avoid pageblock-by-pageblock scans across the entire zone and improve memory hotplug performance. Reworked how pages_with_online_memmap accounts for PFNs in early boot memory in response to Sashiko's review comments [2], which identified potential issues with the previous implementation. Approach ======== Add a new zone member pages_with_online_memmap that tracks the number of pages within the zone span that have an online memory map (including present pages and memory holes smaller than a subsection whose memory map has been initialized). When spanned_pages == pages_with_online_memmap the zone is contiguous and pfn_to_page() can be called on any PFN in the zone span without further pfn_valid() checks. For early boot memory, pages_with_online_memmap is calculated in memmap_init_zone_range(). Since every PFN within a memblock region satisfies pfn_to_online_page(), the calculation aligns both boundaries of each memblock range to PAGES_PER_SUBSECTION and counts the aligned pages that fall within the zone span. If two adjacent memblock regions share a subsection (i.e. the hole between them is smaller than a subsection), the overlapping subsection pages are counted only once. For hotplugged memory, pages_with_online_memmap is updated through adjust_present_page_count(), which is called during memory online and offline. Only pages that fall within the current zone span are accounted towards pages_with_online_memmap. A "too small" value is safe, it merely prevents detecting a contiguous zone. The contiguity check using pages_with_online_memmap is stricter than the old pageblock-by-pageblock scan. The old set_zone_contiguous() iterated at pageblock granularity via pageblock_pfn_to_page(), so a zone could be marked contiguous even if a subsection-sized hole existed within a pageblock. The new check requires spanned_pages == pages_with_online_memmap, meaning every PFN in the zone span must satisfy pfn_to_online_page(). Performance =========== 1. For VM hotplug performance data, please refer to Patch 1. 2. This series also benefits CXL hotplug. Performance results are as follows https://lore.kernel.org/all/20260409023552.GA2807@AE/ Tested cases ============ 1. Hotplug/unplug correctness with both online_movable and online policies, including partial unplug, middle-block offline gaps, and edge-block span shrink. 2. Large scale (256G/512G) plug/unplug performance. 3. Boot-time subsection holes (aligned/unaligned, in-zone and cross-zone) with correct pages_with_online_memmap accounting. 4. kernelcore=mirror: verified no overcounting. Patch overview ============== This series is based on the kernelcore-mirror branch [1]. Patch 1 introduces pages_with_online_memmap to replace pageblock-by-pageblock scans across the entire zone for zone contiguity checks. Patch 2 avoids incorrectly shrinking the zone span during memory unplug when a memory or hole boundary falls in the middle of a subsection. v6 changes: 1. Dropped patches 1-3 from v5. The kernelcore=mirror overlap issue that caused pages_with_online_memmap to be overcounted has been resolved by the series [1]. 2. Reworked pages_with_online_memmap accounting during early boot. v5: https://lore.kernel.org/linux-mm/20260520093457.3719960-1-yuan1.liu@intel.com/ v4: https://lore.kernel.org/linux-mm/20260421125508.2317429-1-yuan1.liu@intel.com/ v3: https://lore.kernel.org/linux-mm/20260408031615.1831922-1-yuan1.liu@intel.com/ [1] https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock.git/log/?h=kernelcore-mirror [2] https://sashiko.dev/#/patchset/20260520093457.3719960-3-yuan1.liu@intel.com Yuan Liu (2): mm/memory_hotplug: optimize zone contiguous check when changing pfn range mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Documentation/mm/physical_memory.rst | 13 +++++++ drivers/base/memory.c | 6 +++ include/linux/mmzone.h | 47 ++++++++++++++++++++++ mm/internal.h | 8 +--- mm/memory_hotplug.c | 54 ++++++++++++++------------ mm/mm_init.c | 58 +++++++++++++++++----------- 6 files changed, 132 insertions(+), 54 deletions(-) base-commit: b69c2a1fa9beb4c3db24b4013e07f5cb7e7260aa -- 2.47.3