A few cleanup patches around memory_hotplug
Subsystems (2)
cover A few cleanup patches around memory_hotplug
Hi,
This series contains a few patches to fix obsolete and misplaced comments, clean up the try_offline_node function and so on. More details can be found in the respective changelogs. Thanks!
Miaohe Lin (4):
mm/memory_hotplug: remove obsolete comment of __add_pages mm/memory_hotplug: avoid calling zone_intersects() for ZONE_NORMAL mm/memory_hotplug: clean up try_offline_node mm/memory_hotplug: fix misplaced comment in offline_pages
mm/memory_hotplug.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/4 mm/memory_hotplug: remove obsolete comment of __add_pages
Since commit f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online"), there is no need to pass in the zone.
--- mm/memory_hotplug.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
mm/memory_hotplug.c +1 -4
@@ -296,10 +296,7 @@ struct page *pfn_to_online_page(unsigned long pfn)EXPORT_SYMBOL_GPL (pfn_to_online_page);/* -* Reasonably generic function for adding memory. It is -* expected that archs that support memory hotplug will -* call this function after deciding the zone to which to -* add the new pages. +* Reasonably generic function for adding memory. */ int __ref __add_pages (int nid,unsigned long pfn,unsigned long nr_pages,struct mhp_params *params)
Signature · 1 line
2.23.0
Re: [PATCH 1/4] mm/memory_hotplug: remove obsolete comment of __add_pages
Quoted 14 lines · Miaohe Lin
Since commit
f1dd2cd13c4b("mm,memory_hotplug: do not associate hotadded memory to zones until online"), there is no need to pass in the zone.Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)mm/memory_hotplug.c +0
-0@@ -296,10 +296,7 @@ struct page *pfn_to_online_page(unsigned long pfn)EXPORT_SYMBOL_GPL (pfn_to_online_page);
mm/memory_hotplug.c struct page *pfn_to_online_page(unsigned long pfn) · line 302
Quoted 10 lines
mm/memory_hotplug.c +1
-4/* -* Reasonably generic function for adding memory. It is -* expected that archs that support memory hotplug will -* call this function after deciding the zone to which to -* add the new pages. +* Reasonably generic function for adding memory. */ int __ref __add_pages (int nid,unsigned long pfn,unsigned long nr_pages,struct mhp_params *params)
I'd suggest just removing the comment completely.
Signature · 3 lines
Thanks, David / dhildenb
Andrew Morton
maintainerRe: [PATCH 1/4] mm/memory_hotplug: remove obsolete comment of __add_pages
Quoted 16 lines · On Mon, 7 Feb 2022 15:41:21 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 15 lines · Miaohe Lin
Since commit
f1dd2cd13c4b("mm,memory_hotplug: do not associate hotadded memory to zones until online"), there is no need to pass in the zone.Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)mm/memory_hotplug.c +0
-0@@ -296,10 +296,7 @@ struct page *pfn_to_online_page(unsigned long pfn)EXPORT_SYMBOL_GPL (pfn_to_online_page);
Quoted 11 lines
mm/memory_hotplug.c struct page *pfn_to_online_page(unsigned long pfn) · line 302
Quoted 9 lines
mm/memory_hotplug.c +1
-4/* -* Reasonably generic function for adding memory. It is -* expected that archs that support memory hotplug will -* call this function after deciding the zone to which to -* add the new pages. +* Reasonably generic function for adding memory. */ int __ref __add_pages (int nid,unsigned long pfn,unsigned long nr_pages,struct mhp_params *params)I'd suggest just removing the comment completely.
Thanks, I made that change.
A better site for documentation is at add_memory(). Which, as a full-on exported-to-modules API function, should really have some docs...
Oscar Salvador
maintainerRe: [PATCH 1/4] mm/memory_hotplug: remove obsolete comment of __add_pages
In reply to Miaohe LinQuoted 4 lines · Miaohe Lin
Since commit
f1dd2cd13c4b("mm,memory_hotplug: do not associate hotadded memory to zones until online"), there is no need to pass in the zone.Signed-off-by Miaohe Lin <[email protected]>
Yeah, I am with David here, "Reasonably generic function for adding memory" does not really tell me much about that function.
Signature · 2 lines
Oscar Salvador SUSE Labs
Re: [PATCH 1/4] mm/memory_hotplug: remove obsolete comment of __add_pages
Quoted 9 lines · Oscar Salvador
Quoted 4 lines · Miaohe Lin
Since commit
f1dd2cd13c4b("mm,memory_hotplug: do not associate hotadded memory to zones until online"), there is no need to pass in the zone.Signed-off-by Miaohe Lin <[email protected]>Yeah, I am with David here, "Reasonably generic function for adding memory" does not really tell me much about that function.
Agree with you. And Andrew have kindly made that change. Many thanks for your review. :)
PATCH 2/4 mm/memory_hotplug: avoid calling zone_intersects() for ZONE_NORMAL
In reply to Miaohe LinIf zid reaches ZONE_NORMAL, the caller will always get the NORMAL zone no matter what zone_intersects() returns. So we can save some possible cpu cycles by avoid calling zone_intersects() for ZONE_NORMAL.
--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
@@ -826,7 +826,7 @@ static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfnstruct pglist_data *pgdat =NODE_DATA (nid);int zid; -for (zid =0 ; zid <=ZONE_NORMAL ; zid++) { +for (zid =0 ; zid <ZONE_NORMAL ; zid++) {struct zone *zone = &pgdat->node_zones[zid];if (zone_intersects (zone, start_pfn, nr_pages))
Signature · 1 line
2.23.0
Re: [PATCH 2/4] mm/memory_hotplug: avoid calling zone_intersects() for ZONE_NORMAL
Quoted 14 lines · Miaohe Lin
If zid reaches
ZONE_NORMAL, the caller will always get the NORMAL zone no matter whatzone_intersects()returns. So we can save some possible cpu cycles by avoid callingzone_intersects()forZONE_NORMAL.Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory_hotplug.c +0
-0
mm/memory_hotplug.c static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfn · line 832
Quoted 8 lines
mm/memory_hotplug.c +1
-1@@ -826,7 +826,7 @@ static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfnstruct pglist_data *pgdat =NODE_DATA (nid);int zid; -for (zid =0 ; zid <=ZONE_NORMAL ; zid++) { +for (zid =0 ; zid <ZONE_NORMAL ; zid++) {struct zone *zone = &pgdat->node_zones[zid];if (zone_intersects (zone, start_pfn, nr_pages))
Makes sense, although we just don't care about the CPU cycles at that point.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 2/4] mm/memory_hotplug: avoid calling zone_intersects() for ZONE_NORMAL
In reply to Miaohe LinQuoted 5 lines · Miaohe Lin
If zid reaches
ZONE_NORMAL, the caller will always get the NORMAL zone no matter whatzone_intersects()returns. So we can save some possible cpu cycles by avoid callingzone_intersects()forZONE_NORMAL.Signed-off-by Miaohe Lin <[email protected]>
Quoted 21 lines
--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory_hotplug.c +1
-1@@ -826,7 +826,7 @@ static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfnstruct pglist_data *pgdat =NODE_DATA (nid);int zid; -for (zid =0 ; zid <=ZONE_NORMAL ; zid++) { +for (zid =0 ; zid <ZONE_NORMAL ; zid++) {struct zone *zone = &pgdat->node_zones[zid];if (zone_intersects (zone, start_pfn, nr_pages))Signature · 1 line
2.23.0
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH 3/4 mm/memory_hotplug: clean up try_offline_node
In reply to Miaohe LinWe can use helper macro node_spanned_pages to check whether node spans pages. And we can change the parameter of check_cpu_on_node to nid as that's what it really cares. Thus we can further get rid of the local variable pgdat and improve the readability a bit.
--- mm/memory_hotplug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
mm/memory_hotplug.c +4 -5
@@ -2008,12 +2008,12 @@ static int get_nr_vmemmap_pages_cb(struct memory_block *mem, void *arg)return mem->nr_vmemmap_pages; } -static int check_cpu_on_node (pg_data_t *pgdat) +static int check_cpu_on_node (int nid) {int cpu;for_each_present_cpu (cpu) { -if (cpu_to_node (cpu) == pgdat->node_id) +if (cpu_to_node (cpu) == nid)/* * the cpu on this node isn't removed, and we can't * offline this node.
@@ -2047,7 +2047,6 @@ static int check_no_memblock_for_node_cb(struct memory_block *mem, void *arg)*/ void try_offline_node (int nid) { -pg_data_t *pgdat =NODE_DATA (nid);int rc;/*
@@ -2055,7 +2054,7 @@ void try_offline_node(int nid)* offline it. A node spans memory after move_pfn_range_to_zone(), * e.g., after the memory block was onlined. */ -if (pgdat->node_spanned_pages) +if (node_spanned_pages (nid))return ;/*
@@ -2067,7 +2066,7 @@ void try_offline_node(int nid)if (rc)return ; -if (check_cpu_on_node (pgdat)) +if (check_cpu_on_node (nid))return ;/*
Signature · 1 line
2.23.0
Re: [PATCH 3/4] mm/memory_hotplug: clean up try_offline_node
Quoted 47 lines · Miaohe Lin
We can use helper macro
node_spanned_pagesto check whether node spans pages. And we can change the parameter ofcheck_cpu_on_nodeto nid as that's what it really cares. Thus we can further get rid of the local variable pgdat and improve the readability a bit.Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)mm/memory_hotplug.c +3
-4@@ -2008,12 +2008,12 @@ static int get_nr_vmemmap_pages_cb(struct memory_block *mem, void *arg)return mem->nr_vmemmap_pages; } -static int check_cpu_on_node (pg_data_t *pgdat) +static int check_cpu_on_node (int nid) {int cpu;for_each_present_cpu (cpu) { -if (cpu_to_node (cpu) == pgdat->node_id) +if (cpu_to_node (cpu) == nid)/* * the cpu on this node isn't removed, and we can't * offline this node. @@ -2047,7 +2047,6 @@ static int check_no_memblock_for_node_cb(struct memory_block *mem, void *arg)*/ void try_offline_node (int nid) { -pg_data_t *pgdat =NODE_DATA (nid);int rc;/* @@ -2055,7 +2054,7 @@ void try_offline_node(int nid)* offline it. A node spans memory after move_pfn_range_to_zone(), * e.g., after the memory block was onlined. */ -if (pgdat->node_spanned_pages) +if (node_spanned_pages (nid))return ;/*
mm/memory_hotplug.c void try_offline_node(int nid) · line 2072
Quoted 8 lines
mm/memory_hotplug.c +1
-1@@ -2067,7 +2066,7 @@ void try_offline_node(int nid)if (rc)return ; -if (check_cpu_on_node (pgdat)) +if (check_cpu_on_node (nid))return ;/*
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 3/4] mm/memory_hotplug: clean up try_offline_node
In reply to Miaohe LinQuoted 6 lines · Miaohe Lin
We can use helper macro
node_spanned_pagesto check whether node spans pages. And we can change the parameter ofcheck_cpu_on_nodeto nid as that's what it really cares. Thus we can further get rid of the local variable pgdat and improve the readability a bit.Signed-off-by Miaohe Lin <[email protected]>
Quoted 53 lines
--- mm/memory_hotplug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)mm/memory_hotplug.c +4
-5@@ -2008,12 +2008,12 @@ static int get_nr_vmemmap_pages_cb(struct memory_block *mem, void *arg)return mem->nr_vmemmap_pages; } -static int check_cpu_on_node (pg_data_t *pgdat) +static int check_cpu_on_node (int nid) {int cpu;for_each_present_cpu (cpu) { -if (cpu_to_node (cpu) == pgdat->node_id) +if (cpu_to_node (cpu) == nid)/* * the cpu on this node isn't removed, and we can't * offline this node. @@ -2047,7 +2047,6 @@ static int check_no_memblock_for_node_cb(struct memory_block *mem, void *arg)*/ void try_offline_node (int nid) { -pg_data_t *pgdat =NODE_DATA (nid);int rc;/* @@ -2055,7 +2054,7 @@ void try_offline_node(int nid)* offline it. A node spans memory after move_pfn_range_to_zone(), * e.g., after the memory block was onlined. */ -if (pgdat->node_spanned_pages) +if (node_spanned_pages (nid))return ;/* @@ -2067,7 +2066,7 @@ void try_offline_node(int nid)if (rc)return ; -if (check_cpu_on_node (pgdat)) +if (check_cpu_on_node (nid))return ;/* Signature · 1 line
2.23.0
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH 4/4 mm/memory_hotplug: fix misplaced comment in offline_pages
In reply to Miaohe LinIt's misplaced since commit 7960509329c2 ("mm, memory_hotplug: print reason for the offlining failure"). Move it to the right place.
--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
@@ -1966,6 +1966,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,return 0 ; failed_removal_isolated: +/* pushback to free area */ undo_isolate_page_range (start_pfn, end_pfn,MIGRATE_MOVABLE );memory_notify (MEM_CANCEL_OFFLINE , &arg); failed_removal_pcplists_disabled:
@@ -1976,7 +1977,6 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, (unsigned long long ) start_pfn <<PAGE_SHIFT , ((unsigned long long ) end_pfn <<PAGE_SHIFT ) -1 , reason); -/* pushback to free area */ mem_hotplug_done ();return ret; }
Signature · 1 line
2.23.0
Re: [PATCH 4/4] mm/memory_hotplug: fix misplaced comment in offline_pages
Quoted 21 lines · Miaohe Lin
It's misplaced since commit
7960509329c2("mm,memory_hotplug: print reason for the offlining failure"). Move it to the right place.Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory_hotplug.c +1
-0@@ -1966,6 +1966,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,return 0 ; failed_removal_isolated: +/* pushback to free area */ undo_isolate_page_range (start_pfn, end_pfn,MIGRATE_MOVABLE );memory_notify (MEM_CANCEL_OFFLINE , &arg); failed_removal_pcplists_disabled:
mm/memory_hotplug.c int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, · line 1982
Quoted 7 lines
mm/memory_hotplug.c +0
-1@@ -1976,7 +1977,6 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, (unsigned long long ) start_pfn <<PAGE_SHIFT , ((unsigned long long ) end_pfn <<PAGE_SHIFT ) -1 , reason); -/* pushback to free area */ mem_hotplug_done ();return ret; }
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 4/4] mm/memory_hotplug: fix misplaced comment in offline_pages
In reply to Miaohe LinQuoted 4 lines · Miaohe Lin
It's misplaced since commit
7960509329c2("mm,memory_hotplug: print reason for the offlining failure"). Move it to the right place.Signed-off-by Miaohe Lin <[email protected]>
Quoted 28 lines
--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory_hotplug.c +1
-1@@ -1966,6 +1966,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,return 0 ; failed_removal_isolated: +/* pushback to free area */ undo_isolate_page_range (start_pfn, end_pfn,MIGRATE_MOVABLE );memory_notify (MEM_CANCEL_OFFLINE , &arg); failed_removal_pcplists_disabled:@@ -1976,7 +1977,6 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, (unsigned long long ) start_pfn <<PAGE_SHIFT , ((unsigned long long ) end_pfn <<PAGE_SHIFT ) -1 , reason); -/* pushback to free area */ mem_hotplug_done ();return ret; }Signature · 1 line
2.23.0
Signature · 2 lines
Oscar Salvador SUSE Labs