Re: [PATCH v8 2/3] mm/memory hotplug/unplug: Add online_memory_block_pages() and offline_memory_block_pages()
From: Li, Tianyou
Date: Wed Jan 28 2026 - 08:59:30 EST
On 1/27/2026 2:58 PM, Mike Rapoport wrote:
On Sat, Jan 24, 2026 at 08:30:57PM +0800, Li, Tianyou wrote:
On 1/22/2026 7:32 PM, Mike Rapoport wrote:Yeah, that's what I thought about.
diff --git a/drivers/base/memory.c b/drivers/base/memory.cI think we can move most of memory_block_online() to the new function and
index 751f248ca4a8..ea4d6fbf34fd 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -246,31 +246,12 @@ static int memory_block_online(struct memory_block *mem)
nr_vmemmap_pages = mem->altmap->free;
mem_hotplug_begin();
- if (nr_vmemmap_pages) {
- ret = mhp_init_memmap_on_memory(start_pfn, nr_vmemmap_pages, zone);
- if (ret)
- goto out;
- }
-
- ret = online_pages(start_pfn + nr_vmemmap_pages,
- nr_pages - nr_vmemmap_pages, zone, mem->group);
- if (ret) {
- if (nr_vmemmap_pages)
- mhp_deinit_memmap_on_memory(start_pfn, nr_vmemmap_pages);
- goto out;
- }
-
- /*
- * Account once onlining succeeded. If the zone was unpopulated, it is
- * now already properly populated.
- */
- if (nr_vmemmap_pages)
- adjust_present_page_count(pfn_to_page(start_pfn), mem->group,
- nr_vmemmap_pages);
-
- mem->zone = zone;
-out:
+ ret = online_memory_block_pages(start_pfn, nr_pages, nr_vmemmap_pages,
+ zone, mem->group);
+ if (!ret)
+ mem->zone = zone;
pass struct memory_block to it.
I'd suggest
int mhp_block_online(struct memory_block *block)
and
int mhp_block_offline(struct memory_block *block)
Other than that LGTM.
It's doable, if not other comments I can change the code. Would it look like
moving the functions to mm/memory_hotplug.c, change the name to
mhp_block_online() and mhp_block_offline(), and change the references where
the original function invoked in drivers/base/memory.c?
Even more broadly, I think the functionality in drivers/base/memory.c
belongs to mm/ much more than to drivers/ but that's surely out of scope
for these patches.
Thanks Mike for the confirmation.
My prior thoughts on this was just break the code as small pieces asIMHO moving the entire function is cleaner, let's hear what David and Oscar
necessary to handle the pages online part together with zone contiguous
state update.
think.
Sure. Actually the patch has been ready with the mhp_block_online() and mhp_block_offline() moved to memory_hotplug.c, the online_memory_block_pages() and offline_memory_block_pages() remains but as static function.
Once get feedback from David and Oscar, I can change them accordingly.