Re: [PATCH V7 3/3] arm64/mm: Enable memory hot remove
From: Anshuman Khandual
Date: Thu Sep 12 2019 - 04:37:48 EST
On 09/12/2019 09:58 AM, Anshuman Khandual wrote:
> On 09/10/2019 09:47 PM, Catalin Marinas wrote:
>> On Tue, Sep 03, 2019 at 03:15:58PM +0530, Anshuman Khandual wrote:
>>> @@ -770,6 +1022,28 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
>>> void vmemmap_free(unsigned long start, unsigned long end,
>>> struct vmem_altmap *altmap)
>>> +#ifdef CONFIG_MEMORY_HOTPLUG
>>> + /*
>>> + * FIXME: We should have called remove_pagetable(start, end, true).
>>> + * vmemmap and vmalloc virtual range might share intermediate kernel
>>> + * page table entries. Removing vmemmap range page table pages here
>>> + * can potentially conflict with a concurrent vmalloc() allocation.
>>> + *
>>> + * This is primarily because vmalloc() does not take init_mm ptl for
>>> + * the entire page table walk and it's modification. Instead it just
>>> + * takes the lock while allocating and installing page table pages
>>> + * via [p4d|pud|pmd|pte]_alloc(). A concurrently vanishing page table
>>> + * entry via memory hot remove can cause vmalloc() kernel page table
>>> + * walk pointers to be invalid on the fly which can cause corruption
>>> + * or worst, a crash.
>>> + *
>>> + * So free_empty_tables() gets called where vmalloc and vmemmap range
>>> + * do not overlap at any intermediate level kernel page table entry.
>>> + */
>>> + unmap_hotplug_range(start, end, true);
>>> + if (!vmalloc_vmemmap_overlap)
>>> + free_empty_tables(start, end);
>>> #endif /* CONFIG_SPARSEMEM_VMEMMAP */
> Hello Catalin,
>> I wonder whether we could simply ignore the vmemmap freeing altogether,
>> just leave it around and not unmap it. This way, we could call
> This would have been an option (even if we just ignore for a moment that
> it might not be the cleanest possible method) if present memory hot remove
> scenarios involved just system RAM of comparable sizes.
> But with persistent memory which will be plugged in as ZONE_DEVICE might
> ask for a vmem_atlamp based vmemmap mapping where the backing memory comes
> from the persistent memory range itself not from existing system RAM. IIRC
> altmap support was originally added because the amount persistent memory on
> a system might be order of magnitude higher than that of regular system RAM.
> During normal memory hot add (without altmap) would have caused great deal
> of consumption from system RAM just for persistent memory range's vmemmap
> mapping. In order to avoid such a scenario altmap was created to allocate
> vmemmap mapping backing memory from the device memory range itself.
> In such cases vmemmap must be unmapped and it's backing memory freed up for
> the complete removal of persistent memory which originally requested for
> altmap based vmemmap backing.
> Just as a reference, the upcoming series which enables altmap support on
> arm64 tries to allocate vmemmap mapping backing memory from the device range
> itself during memory hot add and free them up during memory hot remove. Those
> methods will not be possible if memory hot-remove does not really free up
> vmemmap backing storage.
Just to add in here. There is an ongoing work which will enable allocating
memory from the hot-add range itself even for normal system RAM. So this
might not be specific to ZONE_DEVICE based device/persistent memory alone
for a long time.