From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 A755D3BED31 for ; Wed, 20 May 2026 09:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779269715; cv=none; b=AQ89BwZd89UxXOT/xRPWqYgCxB0PY1rZTuwPi2Nm93rPgxjoQCgHQdEoBYK0mEhNVBupb3sAtttq8ZE7ABrQzbmLPOhY21yCTh3j3lhMead+LB3VRz1tRbCe5N/YWu+Ct7jIAPZulvdXKabeTN9cjApent5xRPoLbV+uArKCFwc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779269715; c=relaxed/simple; bh=nFRZXqgGPfIgPBON0SJLaOpvx4uThcReRRlNS5e7KoI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=buSp2rEp4wFb/vvm6LtDSap5sdu6CPxK+EH+BdZhsEBmddxUdCaKCHV3kUEYkI73tCxTNa5cTDkXgSQi6yL3P0lV17Uiwi+oQAsbUMft7JbXmtrKIZ3VKcnbgudhRzEsU8gXGwR0ozy0GFFui6gK4Hl8PEFGlVSMFwdoFcCQNNc= 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=EcLA4CWL; arc=none smtp.client-ip=198.175.65.11 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="EcLA4CWL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779269713; x=1810805713; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=nFRZXqgGPfIgPBON0SJLaOpvx4uThcReRRlNS5e7KoI=; b=EcLA4CWLMaV+cYFn+/FG1T3MAMTAdC1utYgEzMpmD7cFhsUQAoy86Xwi nm6TIDTsMxu0EuFtLvU21RX2c+FH8woeQd5OgASMNJ3S1sOgmXHi9kLuN gu+z/+hjP+NfVFpptX7WCSaPmERp1hiNNdBpeA52OuhSEdnBDFdoF17vE lwMA5515meGk3mOGD+cA5z1eBqeZck5jLxBXYvbpDE7NiQmG8LiPef2yK sMR5BdB4zk9N+mU5WflZzrNCjBforjG+9RYWoDfaxeCiqvukM2uAnJiwA wWY6ggaI38ctjyn7wJM9yCcsqwkcaY+NBm5rTox+a5C1ga9qJ5m/NQ6w+ Q==; X-CSE-ConnectionGUID: Z87RxZ16SYWsLnEs/FX2RA== X-CSE-MsgGUID: AOYa8LYXTc+UOX0vi8gREA== X-IronPort-AV: E=McAfee;i="6800,10657,11791"; a="90460998" X-IronPort-AV: E=Sophos;i="6.23,244,1770624000"; d="scan'208";a="90460998" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2026 02:35:12 -0700 X-CSE-ConnectionGUID: 9XB2cf0yS5SPn8XYVUodaQ== X-CSE-MsgGUID: 4eCEJDTkQJ+WVB3jM/kzdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,244,1770624000"; d="scan'208";a="241925176" Received: from spr10.sh.intel.com (HELO localhost) ([10.239.23.75]) by fmviesa004.fm.intel.com with ESMTP; 20 May 2026 02:35:08 -0700 From: Yuan Liu 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 , Jason Zeng , linux-kernel@vger.kernel.org Subject: [PATCH v5 0/5] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Date: Wed, 20 May 2026 05:34:52 -0400 Message-ID: <20260520093457.3719960-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. For VM hotplug performance data, please refer to Patch 4. This series also benefits CXL hotplug. Performance results are as follows https://lore.kernel.org/all/20260409023552.GA2807@AE/ Patches 1 and 2 avoid pages_with_online_memmap overcounting when kernelcore=mirror is enabled. Patch 3 avoids incorrect accounting of pages_with_online_memmap when subsection holes exist in early sections. pfn_valid() says early sections always have a full memmap, so even invalid subsections have a memmap. pfn_to_online_page() says an invalid subsection cannot be online and its content must be stale. for_each_valid_pfn() follows pfn_valid() semantics, and we use it to initialize memmap that is not going to be online and account it as pages_with_online_memmap, which is wrong. The cleanest approach is to avoid allocating memmap for subsections, which also removes the special early-section handling from pfn_valid() and for_each_valid_pfn(). The price is another test_bit(idx, usage->subsection_map) check for early sections. If that ever becomes a real problem, a future optimization could cache "full valid section" in a section flag. Patch 4 introduces pages_with_online_memmap to replace pageblock-by-pageblock scans across the entire zone for zone contiguity checks Patch 5 avoids incorrectly shrinking the zone span during memory unplug when a memory or hole boundary falls in the middle of a subsection. v3: https://lore.kernel.org/linux-mm/20260408031615.1831922-1-yuan1.liu@intel.com/ v4: https://lore.kernel.org/linux-mm/20260421125508.2317429-1-yuan1.liu@intel.com/ v4 changes: 1. Address the pages_with_online_memmap overcounting when kernelcore=mirror v5 changes: 1. Rebase onto v7.1-rc3. 2. Address incorrect pages_with_online_memmap accounting in several cases, including kernelcore=mirror, holes in early sections, and incorrect zone shrinking. Yuan Liu (5): mm: move mirrored memory overlap checking to the outer loop mm: skip non-mirrored ZONE_NORMAL memory map init when kernelcore=mirror mm: remove the special early-section handling from pfn_valid() and for_each_valid_pfn() 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 | 60 +++++++++++++++++--- mm/internal.h | 8 +-- mm/memory_hotplug.c | 54 +++++++++--------- mm/mm_init.c | 83 +++++++++++----------------- mm/sparse-vmemmap.c | 4 +- 7 files changed, 136 insertions(+), 92 deletions(-) -- 2.47.3