Skip to contentSkip to conversation

mm/memory_hotplug: move debug_pagealloc_map_pages() into online_pages_range()

PATCH RESEND Applied David Hildenbrand 2 participants 3 messages Dec 3, 2024 – Dec 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 mm/memory_hotplug: move debug_pagealloc_map_pages() into online_pages_range()

In the near future, we want to have a single way to handover PageOffline pages to the buddy, whereby they could have:

(a) Never been exposed to the buddy before: kept PageOffline when onlining the memory block.
(b) Been allocated from the buddy, for example using alloc_contig_range() to then be set PageOffline,

Let's start by making generic_online_page() less special compared to ordinary page freeing (e.g., free_contig_range()), and perform the debug_pagealloc_map_pages() call unconditionally, even when the online callback might decide to keep the pages offline.

All pages are already initialized with PageOffline, so nobody touches them either way.

Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>

---

SMTP server issues, resending so it reaches linux-mm as well.

---
 mm/memory_hotplug.c | 10 +++++++++-
 mm/page_alloc.c     |  6 ------
 2 files changed, 9 insertions(+), 7 deletions(-)
mm/memory_hotplug.c +9 -1
index c43b4e7fb298..20af14e695c7 100644
@@ -650,6 +650,7 @@ static void online_pages_range(unsigned long start_pfn, unsigned long nr_pages)
 	 * this and the first chunk to online will be pageblock_nr_pages.
 	 */
 	for (pfn = start_pfn; pfn < end_pfn;) {
+		struct page *page = pfn_to_page(pfn);
 		int order;
 
 		/*
@@ -664,7 +665,14 @@ static void online_pages_range(unsigned long start_pfn, unsigned long nr_pages)
 		else
 			order = MAX_PAGE_ORDER;
 
-		(*online_page_callback)(pfn_to_page(pfn), order);
+		/*
+		 * Exposing the page to the buddy by freeing can cause
+		 * issues with debug_pagealloc enabled: some archs don't
+		 * like double-unmappings. So treat them like any pages that
+		 * were allocated from the buddy.
+		 */
+		debug_pagealloc_map_pages(page, 1 << order);
+		(*online_page_callback)(page, order);
 		pfn += (1UL << order);
 	}
 
mm/page_alloc.c +0 -6
index cc3296cf8c95..01927f03af0b 100644
@@ -1293,12 +1293,6 @@ void __meminit __free_pages_core(struct page *page, unsigned int order,
 			set_page_count(p, 0);
 		}
 
-		/*
-		 * Freeing the page with debug_pagealloc enabled will try to
-		 * unmap it; some archs don't like double-unmappings, so
-		 * map it first.
-		 */
-		debug_pagealloc_map_pages(page, nr_pages);
 		adjust_managed_page_count(page, nr_pages);
 	} else {
 		for (loop = 0; loop < nr_pages; loop++, p++) {
Signature · 1 line
2.47.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · David Hildenbrand

In the near future, we want to have a single way to handover PageOffline pages to the buddy, whereby they could have:

(a) Never been exposed to the buddy before: kept PageOffline when onlining the memory block.
(b) Been allocated from the buddy, for example using alloc_contig_range() to then be set PageOffline,

Let's start by making generic_online_page() less special compared to

This got me confused for a moment. I'd have said "making __free_pages_core" less special? As that is where we were calling debug_pagealloc_map_pages() if the context on the context.

Quoted 10 lines

ordinary page freeing (e.g., free_contig_range()), and perform the debug_pagealloc_map_pages() call unconditionally, even when the online callback might decide to keep the pages offline.

All pages are already initialized with PageOffline, so nobody touches them either way.

Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Signature · 2 lines
Oscar Salvador
SUSE Labs
#2 lore raw
Quoted 9 lines · Oscar Salvador
Quoted 8 lines · David Hildenbrand

In the near future, we want to have a single way to handover PageOffline pages to the buddy, whereby they could have:

(a) Never been exposed to the buddy before: kept PageOffline when onlining the memory block.
(b) Been allocated from the buddy, for example using alloc_contig_range() to then be set PageOffline,

Quoted 5 lines
Quoted 1 line

Let's start by making generic_online_page() less special compared to

This got me confused for a moment. I'd have said "making __free_pages_core" less special? As that is where we were calling debug_pagealloc_map_pages() if the context on the context.

Well, yes, but it's really generic_online_page()->__free_pages_core() that triggers this exact code only.

@Andrew, can you fix that up?

s/generic_online_page()/generic_online_page()->__free_pages_core()/

Quoted 5 lines
Quoted 5 lines

ordinary page freeing (e.g., free_contig_range()), and perform the debug_pagealloc_map_pages() call unconditionally, even when the online callback might decide to keep the pages offline.

Quoted 8 lines
Quoted 6 lines

All pages are already initialized with PageOffline, so nobody touches them either way.

Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>

Thanks!

Signature · 3 lines
Cheers,

David / dhildenb