lkml.org 
[lkml]   [2019]   [Apr]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 2/6] arm64/mm: Enable memory hot remove
From
Date


On 04/03/2019 11:27 PM, Robin Murphy wrote:
> On 03/04/2019 18:32, Logan Gunthorpe wrote:
>>
>>
>> On 2019-04-02 10:30 p.m., Anshuman Khandual wrote:
>>> Memory removal from an arch perspective involves tearing down two different
>>> kernel based mappings i.e vmemmap and linear while releasing related page
>>> table pages allocated for the physical memory range to be removed.
>>>
>>> Define a common kernel page table tear down helper remove_pagetable() which
>>> can be used to unmap given kernel virtual address range. In effect it can
>>> tear down both vmemap or kernel linear mappings. This new helper is called
>>> from both vmemamp_free() and ___remove_pgd_mapping() during memory removal.
>>> The argument 'direct' here identifies kernel linear mappings.
>>>
>>> Vmemmap mappings page table pages are allocated through sparse mem helper
>>> functions like vmemmap_alloc_block() which does not cycle the pages through
>>> pgtable_page_ctor() constructs. Hence while removing it skips corresponding
>>> destructor construct pgtable_page_dtor().
>>>
>>> While here update arch_add_mempory() to handle __add_pages() failures by
>>> just unmapping recently added kernel linear mapping. Now enable memory hot
>>> remove on arm64 platforms by default with ARCH_ENABLE_MEMORY_HOTREMOVE.
>>>
>>> This implementation is overall inspired from kernel page table tear down
>>> procedure on X86 architecture.
>>
>> I've been working on very similar things for RISC-V. In fact, I'm
>> currently in progress on a very similar stripped down version of
>> remove_pagetable(). (Though I'm fairly certain I've done a bunch of
>> stuff wrong.)
>>
>> Would it be possible to move this work into common code that can be used
>> by all arches? Seems like, to start, we should be able to support both
>> arm64 and RISC-V... and maybe even x86 too.
>>
>> I'd be happy to help integrate and test such functions in RISC-V.

I am more inclined towards consolidating remove_pagetable() across platforms
like arm64 and RISC-V (probably others). But there are clear distinctions
between user page table and kernel page table tear down process.

>
> Indeed, I had hoped we might be able to piggyback off generic code for this anyway,
> given that we have generic pagetable code which knows how to free process pagetables,
> and kernel pagetables are also pagetables.

But there are differences. To list some

* Freeing mapped and pagetable pages

- Memory hot remove deals with both vmemmap and linear mappings
- Selectively call pgtable_page_dtor() for linear mappings (arch specific)
- Not actually freeing PTE|PMD|PUD mapped pages for linear mappings
- Freeing mapped pages for vmemap mappings

* TLB shootdown

- User page table process uses mmu_gather mechanism for TLB flush
- Kernel page table tear down can do with less TLB flush invocations
- Dont have to care about flush deferral etc

* THP and HugeTLB

- Kernel page table tear down procedure does not have to understand THP or HugeTLB
- Though it has to understand possible arch specific special block mappings

- Specific kernel linear mappings on arm64
- PUD|PMD|CONT_PMD|CONT_PTE large page mappings

- Specific vmemmap mappings on arm64
- PMD large or PTE mappings

-User page table tear down procedure needs to understand THP and HugeTLB

* Page table locking

- Kernel procedure locks init_mm.page_table_lock while clearing an individual entry
- Kernel procedure does not have to worry about mmap_sem

* ZONE_DEVICE struct vmem_altmap

- Kernel page table tear down procedure needs to accommodate 'struct vmem_altmap' when
vmemmap mappings are created with pages allocated from 'struct vmem_altmap' (ZONE_DEVICE)
rather than buddy allocator or memblock.

\
 
 \ /
  Last update: 2019-04-04 10:24    [W:0.074 / U:4.724 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site