Linux-mm Archive on
 help / color / Atom feed
* [patch 083/158] mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes
@ 2019-12-01  1:54 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2019-12-01  1:54 UTC (permalink / raw)
  To: akpm, anshuman.khandual, dan.j.williams, david, linux-mm, mhocko,
	mm-commits, nao.horiguchi, osalvador, pasha.tatashin, torvalds

From: David Hildenbrand <>
Subject: mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes

Our onlining/offlining code is unnecessarily complicated.  Only memory
blocks added during boot can have holes (a range that is not
IORESOURCE_SYSTEM_RAM).  Hotplugged memory never has holes (e.g., see
add_memory_resource()).  All memory blocks that belong to boot memory are
already online.

Note that boot memory can have holes and the memmap of the holes is marked
PG_reserved.  However, also memory allocated early during boot is
PG_reserved - basically every page of boot memory that is not given to the
buddy is PG_reserved.

Therefore, when we stop allowing to offline memory blocks with holes, we
implicitly no longer have to deal with onlining memory blocks with holes. 
E.g., online_pages() will do a walk_system_ram_range(...,
online_pages_range), whereby online_pages_range() will effectively only
free the memory holes not falling into a hole to the buddy.  The other
pages (holes) are kept PG_reserved (via

This allows to simplify the code.  For example, we no longer have to worry
about marking pages that fall into memory holes PG_reserved when onlining
memory.  We can stop setting pages PG_reserved completely in

Offlining memory blocks added during boot is usually not guaranteed to
work either way (unmovable data might have easily ended up on that memory
during boot).  So stopping to do that should not really hurt.  Also,
people are not even aware of a setup where onlining/offlining of memory
blocks with holes used to work reliably (see [1] and [2] especially
regarding the hotplug path) - I doubt it worked reliably.

For the use case of offlining memory to unplug DIMMs, we should see no
change.  (holes on DIMMs would be weird).

Please note that hardware errors (PG_hwpoison) are not memory holes and
are not affected by this change when offlining.


Reviewed-by: Dan Williams <>
Signed-off-by: David Hildenbrand <>
Acked-by: Michal Hocko <>
Cc: Oscar Salvador <>
Cc: Pavel Tatashin <>
Cc: Dan Williams <>
Cc: Anshuman Khandual <>
Cc: Naoya Horiguchi <>
Signed-off-by: Andrew Morton <>

 mm/memory_hotplug.c |   28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

--- a/mm/memory_hotplug.c~mm-memory_hotplug-dont-allow-to-online-offline-memory-blocks-with-holes
+++ a/mm/memory_hotplug.c
@@ -1485,10 +1485,19 @@ static void node_states_clear_node(int n
 		node_clear_state(node, N_MEMORY);
+static int count_system_ram_pages_cb(unsigned long start_pfn,
+				     unsigned long nr_pages, void *data)
+	unsigned long *nr_system_ram_pages = data;
+	*nr_system_ram_pages += nr_pages;
+	return 0;
 static int __ref __offline_pages(unsigned long start_pfn,
 		  unsigned long end_pfn)
-	unsigned long pfn, nr_pages;
+	unsigned long pfn, nr_pages = 0;
 	unsigned long offlined_pages = 0;
 	int ret, node, nr_isolate_pageblock;
 	unsigned long flags;
@@ -1499,6 +1508,22 @@ static int __ref __offline_pages(unsigne
+	/*
+	 * Don't allow to offline memory blocks that contain holes.
+	 * Consequently, memory blocks with holes can never get onlined
+	 * via the hotplug path - online_pages() - as hotplugged memory has
+	 * no holes. This way, we e.g., don't have to worry about marking
+	 * memory holes PG_reserved, don't need pfn_valid() checks, and can
+	 * avoid using walk_system_ram_range() later.
+	 */
+	walk_system_ram_range(start_pfn, end_pfn - start_pfn, &nr_pages,
+			      count_system_ram_pages_cb);
+	if (nr_pages != end_pfn - start_pfn) {
+		ret = -EINVAL;
+		reason = "memory holes";
+		goto failed_removal;
+	}
 	/* This makes hotplug much easier...and readable.
 	   we assume this for now. .*/
 	if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start,
@@ -1510,7 +1535,6 @@ static int __ref __offline_pages(unsigne
 	zone = page_zone(pfn_to_page(valid_start));
 	node = zone_to_nid(zone);
-	nr_pages = end_pfn - start_pfn;
 	/* set above range as isolated */
 	ret = start_isolate_page_range(start_pfn, end_pfn,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01  1:54 [patch 083/158] mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes akpm

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone