mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yuan Liu <yuan1.liu@intel.com>
To: David Hildenbrand <david@kernel.org>,
	Oscar Salvador <osalvador@suse.de>,
	Mike Rapoport <rppt@kernel.org>,
	Wei Yang <richard.weiyang@gmail.com>
Cc: linux-mm@kvack.org, Nanhai Zou <nanhai.zou@intel.com>,
	Yuan Liu <yuan1.liu@intel.com>, Pan Deng <pan.deng@intel.com>,
	Tianyou Li <tianyou.li@intel.com>,
	Chen Zhang <zhangchen.kidd@jd.com>,
	Jason Zeng <jason.zeng@intel.com>,
	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	[thread overview]
Message-ID: <20260723084946.189392-1-yuan1.liu@intel.com> (raw)

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


             reply	other threads:[~2026-07-23  8:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  8:49 Yuan Liu [this message]
2026-07-23  8:49 ` [PATCH v6 1/2] " Yuan Liu
2026-08-05 11:53   ` David Hildenbrand (Arm)
2026-08-06  7:23     ` Liu, Yuan1
2026-08-06  8:45       ` David Hildenbrand (Arm)
2026-08-06  9:52         ` Liu, Yuan1
2026-08-07 11:29           ` David Hildenbrand (Arm)
2026-08-07 12:15             ` Liu, Yuan1
2026-08-09  3:12               ` Wei Yang
2026-08-10 14:04               ` David Hildenbrand (Arm)
2026-08-11 12:23                 ` David Hildenbrand (Arm)
2026-08-12  9:17                   ` Liu, Yuan1
2026-08-12 10:11                     ` David Hildenbrand (Arm)
2026-08-15  1:55                   ` Wei Yang
2026-08-19 15:57                     ` David Hildenbrand (Arm)
2026-07-23  8:49 ` [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Yuan Liu
2026-07-25  2:49   ` Wei Yang
2026-07-27  9:49     ` Liu, Yuan1
2026-07-30  2:36       ` Wei Yang
2026-07-30  7:57         ` Liu, Yuan1
2026-08-01  0:59           ` Wei Yang
2026-08-05 11:02   ` David Hildenbrand (Arm)
2026-08-06  7:14     ` Liu, Yuan1
2026-08-07  3:22     ` Wei Yang
2026-08-07 11:25       ` David Hildenbrand (Arm)
2026-08-05  9:40 ` [PATCH v6 0/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Liu, Yuan1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723084946.189392-1-yuan1.liu@intel.com \
    --to=yuan1.liu@intel.com \
    --cc=david@kernel.org \
    --cc=jason.zeng@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nanhai.zou@intel.com \
    --cc=osalvador@suse.de \
    --cc=pan.deng@intel.com \
    --cc=richard.weiyang@gmail.com \
    --cc=rppt@kernel.org \
    --cc=tianyou.li@intel.com \
    --cc=zhangchen.kidd@jd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®