Re: [PATCH RFC 3/3] mm/memory_hotplug: Remove memory block devices before arch_remove_memory()

From: David Hildenbrand
Date: Tue Apr 09 2019 - 05:25:57 EST


On 09.04.19 11:18, Oscar Salvador wrote:
> On Mon, Apr 08, 2019 at 12:12:26PM +0200, David Hildenbrand wrote:
>> Let's factor out removing of memory block devices, which is only
>> necessary for memory added via add_memory() and friends that created
>> memory block devices. Remove the devices before calling
>> arch_remove_memory().
>>
>> TODO: We should try to get rid of the errors that could be reported by
>> unregister_memory_block_under_nodes(). Ignoring failures is not that
>> nice.
>
> Hi David,
>
> I am sorry but I will not have to look into this until next week as I am
> up to my ears with work plus I am in the middle of a move.

No worries, I have plenty of other stuff to do as well and this is only
an RFC that will require other refactorings and maybe discussions first
- one of these, I will send out shortly so we can discuss.

Happy moving :)

>
> I remember I was once trying to simplify unregister_mem_sect_under_nodes (your
> new unregister_memory_block_under_nodes), and I checked whether we could get
> rid of the NODEMASK_ALLOC there, something like:

Yeah, something like that makes perfect sense. Thanks!

>
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index 8598fcbd2a17..f4294a2928dd 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -805,16 +805,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
> int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
> unsigned long phys_index)
> {
> - NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
> + nodemask_t unlinked_nodes;
> unsigned long pfn, sect_start_pfn, sect_end_pfn;
>
> - if (!mem_blk) {
> - NODEMASK_FREE(unlinked_nodes);
> - return -EFAULT;
> - }
> - if (!unlinked_nodes)
> - return -ENOMEM;
> - nodes_clear(*unlinked_nodes);
> + nodes_clear(unlinked_nodes);
>
> sect_start_pfn = section_nr_to_pfn(phys_index);
> sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
> @@ -826,14 +820,13 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
> continue;
> if (!node_online(nid))
> continue;
> - if (node_test_and_set(nid, *unlinked_nodes))
> + if (node_test_and_set(nid, unlinked_nodes))
> continue;
> sysfs_remove_link(&node_devices[nid]->dev.kobj,
> kobject_name(&mem_blk->dev.kobj));
> sysfs_remove_link(&mem_blk->dev.kobj,
> kobject_name(&node_devices[nid]->dev.kobj));
> }
> - NODEMASK_FREE(unlinked_nodes);
> return 0;
> }
>
>
> nodemask_t is 128bytes when CONFIG_NODES_SHIFT is 10 , which is the maximum value.
> We just need to check whether we can overflow the stack or not.
>
> AFAICS, it is not really a shore stack but it might not be that deep either.


--

Thanks,

David / dhildenb