drivers/base/memory: clarify adding and removing of memory blocks

Let's make it clearer at which places we actually add and remove memory
blocks -- streamlining the terminology -- and highlight which memory block
start out online and which start out as offline.

 * rename add_memory_block -> add_boot_memory_block
 * rename init_memory_block -> add_memory_block
 * rename unregister_memory -> remove_memory_block
 * rename register_memory -> __add_memory_block
 * add add_hotplug_memory_block
 * mark add_boot_memory_block with __init (suggested by Oscar)

__add_memory_block() is  a pure helper for add_memory_block(), remove
the somewhat obvious comment.

Link: https://lkml.kernel.org/r/20220221154531.11382-1-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
David Hildenbrand 2022-03-22 14:47:34 -07:00 committed by Linus Torvalds
parent 395f6081ba
commit 2aa065f7af
1 changed files with 20 additions and 18 deletions

View File

@ -619,11 +619,7 @@ static const struct attribute_group *memory_memblk_attr_groups[] = {
NULL, NULL,
}; };
/* static int __add_memory_block(struct memory_block *memory)
* register_memory - Setup a sysfs device for a memory block
*/
static
int register_memory(struct memory_block *memory)
{ {
int ret; int ret;
@ -723,9 +719,9 @@ void memory_block_add_nid(struct memory_block *mem, int nid,
} }
#endif #endif
static int init_memory_block(unsigned long block_id, unsigned long state, static int add_memory_block(unsigned long block_id, unsigned long state,
unsigned long nr_vmemmap_pages, unsigned long nr_vmemmap_pages,
struct memory_group *group) struct memory_group *group)
{ {
struct memory_block *mem; struct memory_block *mem;
int ret = 0; int ret = 0;
@ -756,7 +752,7 @@ static int init_memory_block(unsigned long block_id, unsigned long state,
mem->zone = early_node_zone_for_memory_block(mem, NUMA_NO_NODE); mem->zone = early_node_zone_for_memory_block(mem, NUMA_NO_NODE);
#endif /* CONFIG_NUMA */ #endif /* CONFIG_NUMA */
ret = register_memory(mem); ret = __add_memory_block(mem);
if (ret) if (ret)
return ret; return ret;
@ -768,7 +764,7 @@ static int init_memory_block(unsigned long block_id, unsigned long state,
return 0; return 0;
} }
static int add_memory_block(unsigned long base_section_nr) static int __init add_boot_memory_block(unsigned long base_section_nr)
{ {
int section_count = 0; int section_count = 0;
unsigned long nr; unsigned long nr;
@ -780,11 +776,18 @@ static int add_memory_block(unsigned long base_section_nr)
if (section_count == 0) if (section_count == 0)
return 0; return 0;
return init_memory_block(memory_block_id(base_section_nr), return add_memory_block(memory_block_id(base_section_nr),
MEM_ONLINE, 0, NULL); MEM_ONLINE, 0, NULL);
} }
static void unregister_memory(struct memory_block *memory) static int add_hotplug_memory_block(unsigned long block_id,
unsigned long nr_vmemmap_pages,
struct memory_group *group)
{
return add_memory_block(block_id, MEM_OFFLINE, nr_vmemmap_pages, group);
}
static void remove_memory_block(struct memory_block *memory)
{ {
if (WARN_ON_ONCE(memory->dev.bus != &memory_subsys)) if (WARN_ON_ONCE(memory->dev.bus != &memory_subsys))
return; return;
@ -823,8 +826,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size,
return -EINVAL; return -EINVAL;
for (block_id = start_block_id; block_id != end_block_id; block_id++) { for (block_id = start_block_id; block_id != end_block_id; block_id++) {
ret = init_memory_block(block_id, MEM_OFFLINE, vmemmap_pages, ret = add_hotplug_memory_block(block_id, vmemmap_pages, group);
group);
if (ret) if (ret)
break; break;
} }
@ -835,7 +837,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size,
mem = find_memory_block_by_id(block_id); mem = find_memory_block_by_id(block_id);
if (WARN_ON_ONCE(!mem)) if (WARN_ON_ONCE(!mem))
continue; continue;
unregister_memory(mem); remove_memory_block(mem);
} }
} }
return ret; return ret;
@ -864,7 +866,7 @@ void remove_memory_block_devices(unsigned long start, unsigned long size)
if (WARN_ON_ONCE(!mem)) if (WARN_ON_ONCE(!mem))
continue; continue;
unregister_memory_block_under_nodes(mem); unregister_memory_block_under_nodes(mem);
unregister_memory(mem); remove_memory_block(mem);
} }
} }
@ -924,7 +926,7 @@ void __init memory_dev_init(void)
*/ */
for (nr = 0; nr <= __highest_present_section_nr; for (nr = 0; nr <= __highest_present_section_nr;
nr += sections_per_block) { nr += sections_per_block) {
ret = add_memory_block(nr); ret = add_boot_memory_block(nr);
if (ret) if (ret)
panic("%s() failed to add memory block: %d\n", __func__, panic("%s() failed to add memory block: %d\n", __func__,
ret); ret);