Skip to contentSkip to conversation

mm/memory_hotplug: pass in nid to online_pages()

PATCH In review David Hildenbrand 1 participant 4 messages Jan 13, 2020 – Jan 14, 2020

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

cover mm/memory_hotplug: pass in nid to online_pages()

Simplify onlining code and get rid of find_memory_block(). Pass in the nid from the memory block we are trying to online directly, instead of manually looking it up.

David Hildenbrand (2):
mm/memory_hotplug: pass in nid to online_pages() drivers/base/memory.c: get rid of find_memory_block()

 drivers/base/memory.c          | 15 ++++-----------
 include/linux/memory.h         |  1 -
 include/linux/memory_hotplug.h |  3 ++-
 mm/memory_hotplug.c            | 13 ++-----------
 4 files changed, 8 insertions(+), 24 deletions(-)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/2 mm/memory_hotplug: pass in nid to online_pages()

No need to lookup the memory block, we can directly pass in the nid.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Oscar Salvador <[email protected]>
---
 drivers/base/memory.c          |  6 +++---
 include/linux/memory_hotplug.h |  3 ++-
 mm/memory_hotplug.c            | 13 ++-----------
 3 files changed, 7 insertions(+), 15 deletions(-)
drivers/base/memory.c +3 -3
index 2604a15c728b..2cf3542b04d0 100644
@@ -236,7 +236,7 @@ static bool pages_correctly_probed(unsigned long start_pfn)
  */
 static int
 memory_block_action(unsigned long start_section_nr, unsigned long action,
-		    int online_type)
+		    int online_type, int nid)
 {
 	unsigned long start_pfn;
 	unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
@@ -249,7 +249,7 @@ memory_block_action(unsigned long start_section_nr, unsigned long action,
 		if (!pages_correctly_probed(start_pfn))
 			return -EBUSY;
 
-		ret = online_pages(start_pfn, nr_pages, online_type);
+		ret = online_pages(start_pfn, nr_pages, online_type, nid);
 		break;
 	case MEM_OFFLINE:
 		ret = offline_pages(start_pfn, nr_pages);
@@ -275,7 +275,7 @@ static int memory_block_change_state(struct memory_block *mem,
 		mem->state = MEM_GOING_OFFLINE;
 
 	ret = memory_block_action(mem->start_section_nr, to_state,
-				mem->online_type);
+				  mem->online_type, mem->nid);
 
 	mem->state = ret ? from_state_req : to_state;
 
include/linux/memory_hotplug.h +2 -1
index 820689093894..f4d59155f3d4 100644
@@ -94,7 +94,8 @@ extern int zone_grow_free_lists(struct zone *zone, unsigned long new_nr_pages);
 extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);
 extern int add_one_highpage(struct page *page, int pfn, int bad_ppro);
 /* VM interface that may be used by firmware interface */
-extern int online_pages(unsigned long, unsigned long, int);
+extern int online_pages(unsigned long pfn, unsigned long nr_pages,
+			int online_type, int nid);
 extern struct zone *test_pages_in_a_zone(unsigned long start_pfn,
 					 unsigned long end_pfn);
 extern unsigned long __offline_isolated_pages(unsigned long start_pfn,
mm/memory_hotplug.c +2 -11
index 5ee2c6e10934..fb1c878d054d 100644
@@ -758,27 +758,18 @@ struct zone * zone_for_pfn_range(int online_type, int nid, unsigned start_pfn,
 	return default_zone_for_pfn(nid, start_pfn, nr_pages);
 }
 
-int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type)
+int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
+		       int online_type, int nid)
 {
 	unsigned long flags;
 	unsigned long onlined_pages = 0;
 	struct zone *zone;
 	int need_zonelists_rebuild = 0;
-	int nid;
 	int ret;
 	struct memory_notify arg;
-	struct memory_block *mem;
 
 	mem_hotplug_begin();
 
-	/*
-	 * We can't use pfn_to_nid() because nid might be stored in struct page
-	 * which is not yet initialized. Instead, we find nid from memory block.
-	 */
-	mem = find_memory_block(__pfn_to_section(pfn));
-	nid = mem->nid;
-	put_device(&mem->dev);
-
 	/* associate pfn range with the zone */
 	zone = zone_for_pfn_range(online_type, nid, pfn, nr_pages);
 	move_pfn_range_to_zone(zone, pfn, nr_pages, NULL);
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/2 drivers/base/memory.c: get rid of find_memory_block()

In reply to David Hildenbrand

No longer needed, remove it.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Dan Williams <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Anshuman Khandual <[email protected]>
Cc Oscar Salvador <[email protected]>
---
 drivers/base/memory.c  | 9 +--------
 include/linux/memory.h | 1 -
 2 files changed, 1 insertion(+), 9 deletions(-)
drivers/base/memory.c +1 -8
index 2cf3542b04d0..8b3ab910b812 100644
@@ -590,13 +590,6 @@ static struct memory_block *find_memory_block_by_id(unsigned long block_id)
 	return mem;
 }
 
-struct memory_block *find_memory_block(struct mem_section *section)
-{
-	unsigned long block_id = base_memory_block_id(__section_nr(section));
-
-	return find_memory_block_by_id(block_id);
-}
-
 static struct attribute *memory_memblk_attrs[] = {
 	&dev_attr_phys_index.attr,
 	&dev_attr_state.attr,
@@ -700,7 +693,7 @@ static void unregister_memory(struct memory_block *memory)
 
 	WARN_ON(radix_tree_delete(&memory_blocks, memory->dev.id) == NULL);
 
-	/* drop the ref. we got via find_memory_block() */
+	/* drop the ref. we got via find_memory_block_by_id() */
 	put_device(&memory->dev);
 	device_unregister(&memory->dev);
 }
include/linux/memory.h +0 -1
index 3ab4aa2d67ae..0b0732a94972 100644
@@ -113,7 +113,6 @@ void remove_memory_block_devices(unsigned long start, unsigned long size);
 extern void memory_dev_init(void);
 extern int memory_notify(unsigned long val, void *v);
 extern int memory_isolate_notify(unsigned long val, void *v);
-extern struct memory_block *find_memory_block(struct mem_section *);
 typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *);
 extern int walk_memory_blocks(unsigned long start, unsigned long size,
 			      void *arg, walk_memory_blocks_func_t func);
Signature · 1 line
2.24.1
#3 lore raw

Re: [PATCH v1 2/2] drivers/base/memory.c: get rid of find_memory_block()

Quoted 49 lines · David Hildenbrand

No longer needed, remove it.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Dan Williams <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Anshuman Khandual <[email protected]>
Cc Oscar Salvador <[email protected]>
---
 drivers/base/memory.c  | 9 +--------
 include/linux/memory.h | 1 -
 2 files changed, 1 insertion(+), 9 deletions(-)
drivers/base/memory.c +1 -8
index 2cf3542b04d0..8b3ab910b812 100644
@@ -590,13 +590,6 @@ static struct memory_block *find_memory_block_by_id(unsigned long block_id)
 	return mem;
 }
 
-struct memory_block *find_memory_block(struct mem_section *section)
-{
-	unsigned long block_id = base_memory_block_id(__section_nr(section));
-
-	return find_memory_block_by_id(block_id);
-}
-
 static struct attribute *memory_memblk_attrs[] = {
 	&dev_attr_phys_index.attr,
 	&dev_attr_state.attr,
@@ -700,7 +693,7 @@ static void unregister_memory(struct memory_block *memory)
 
 	WARN_ON(radix_tree_delete(&memory_blocks, memory->dev.id) == NULL);
 
-	/* drop the ref. we got via find_memory_block() */
+	/* drop the ref. we got via find_memory_block_by_id() */
 	put_device(&memory->dev);
 	device_unregister(&memory->dev);
 }
include/linux/memory.h +0 -0
index 3ab4aa2d67ae..0b0732a94972 100644

include/linux/memory.h void remove_memory_block_devices(unsigned long start, unsigned long size); · line 118

Quoted 7 lines
include/linux/memory.h +0 -1
@@ -113,7 +113,6 @@ void remove_memory_block_devices(unsigned long start, unsigned long size);
 extern void memory_dev_init(void);
 extern int memory_notify(unsigned long val, void *v);
 extern int memory_isolate_notify(unsigned long val, void *v);
-extern struct memory_block *find_memory_block(struct mem_section *);
 typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *);
 extern int walk_memory_blocks(unsigned long start, unsigned long size,
 			      void *arg, walk_memory_blocks_func_t func);

My git-grepping skills betrayed me :) There is one remaining user in ppc code. Let's drop this patch for now.

Signature · 3 lines
Thanks,

David / dhildenb