Re: [PATCH 5/6] mm, memory_hotplug: do not associate hotadded memory to zones until online

From: Michal Hocko
Date: Thu Apr 06 2017 - 04:15:22 EST


On Thu 30-03-17 13:54:53, Michal Hocko wrote:
[...]
> -static int __meminit __add_section(int nid, struct zone *zone,
> - unsigned long phys_start_pfn)
> +static int __meminit __add_section(int nid, unsigned long phys_start_pfn)
> {
> int ret;
> + int i;
>
> if (pfn_valid(phys_start_pfn))
> return -EEXIST;
>
> - ret = sparse_add_one_section(zone, phys_start_pfn);
> -
> + ret = sparse_add_one_section(NODE_DATA(nid), phys_start_pfn);
> if (ret < 0)
> return ret;
>
> - ret = __add_zone(zone, phys_start_pfn);
> + /*
> + * Make all the pages reserved so that nobody will stumble over half
> + * initialized state.
> + */
> + for (i = 0; i < PAGES_PER_SECTION; i++) {
> + unsigned long pfn = phys_start_pfn + i;
> + if (!pfn_valid(pfn))
> + continue;
>
> - if (ret < 0)
> - return ret;
> + SetPageReserved(pfn_to_page(phys_start_pfn + i));
> + }
>
> return register_new_memory(nid, __pfn_to_section(phys_start_pfn));

I have just realized one more dependency on the zone initialization.
register_new_memory relies on is_zone_device_section to rule out
memblock specific operations including sysfs infrastructure. I have come
up with the following to handle this.
---