mm/sparsemem: add helpers track active portions of a section at boot

Prepare for hot{plug,remove} of sub-ranges of a section by tracking a
sub-section active bitmask, each bit representing a PMD_SIZE span of the
architecture's memory hotplug section size.

The implications of a partially populated section is that pfn_valid()
needs to go beyond a valid_section() check and either determine that the
section is an "early section", or read the sub-section active ranges
from the bitmask.  The expectation is that the bitmask (subsection_map)
fits in the same cacheline as the valid_section() / early_section()
data, so the incremental performance overhead to pfn_valid() should be

The rationale for using early_section() to short-ciruit the
subsection_map check is that there are legacy code paths that use
pfn_valid() at section granularity before validating the pfn against
pgdat data.  So, the early_section() check allows those traditional
assumptions to persist while also permitting subsection_map to tell the
truth for purposes of populating the unused portions of early sections
with PMEM and other ZONE_DEVICE mappings.

Signed-off-by: Dan Williams <>
Reported-by: Qian Cai <>
Tested-by: Jane Chu <>
Tested-by: Aneesh Kumar K.V <>	[ppc64]
Reviewed-by: Oscar Salvador <>
Cc: Michal Hocko <>
Cc: Vlastimil Babka <>
Cc: Logan Gunthorpe <>
Cc: Pavel Tatashin <>
Cc: David Hildenbrand <>
Cc: Jeff Moyer <>
Cc: Jérôme Glisse <>
Cc: Jonathan Corbet <>
Cc: Mike Rapoport <>
Cc: Toshi Kani <>
Cc: Wei Yang <>
Cc: Jason Gunthorpe <>
Cc: Christoph Hellwig <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
3 files changed