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