• Oscar Salvador's avatar
    drivers/base/memory: introduce memory_block_{online,offline} · 8736cc2d
    Oscar Salvador authored
    Patch series "Allocate memmap from hotadded memory (per device)", v10.
    
    The primary goal of this patchset is to reduce memory overhead of the
    hot-added memory (at least for SPARSEMEM_VMEMMAP memory model).  The
    current way we use to populate memmap (struct page array) has two main
    drawbacks:
    
    a) it consumes an additional memory until the hotadded memory itself is
       onlined and
    
    b) memmap might end up on a different numa node which is especially
       true for movable_node configuration.
    
    c) due to fragmentation we might end up populating memmap with base
       pages
    
    One way to mitigate all these issues is to simply allocate memmap array
    (which is the largest memory footprint of the physical memory hotplug)
    from the hot-added memory itself.  SPARSEMEM_VMEMMAP memory model allows
    us to map any pfn range so the memory doesn't need to be online to be
    usable for the array.  See patch 4 for more details.  This feature is
    only usable when CONFIG_SPARSEMEM_VMEMMAP is set.
    
    [Overall design]:
    
    Implementation wise we reuse vmem_altmap infrastructure to override the
    default allocator used by vmemap_populate.  memory_block structure gains a
    new field called nr_vmemmap_pages, which accounts for the number of
    vmemmap pages used by that memory_block.  E.g: On x86_64, that is 512
    vmemmap pages on small memory bloks and 4096 on large memory blocks (1GB)
    
    We also introduce new two functions: memory_block_{online,offline}.  These
    functions take care of initializing/unitializing vmemmap pages prior to
    calling {online,offline}_pages, so the latter functions can remain totally
    untouched.
    
    More details can be found in the respective changelogs.
    
    This patch (of 8):
    
    This is a preparatory patch that introduces two new functions:
    memory_block_online() and memory_block_offline().
    
    For now, these functions will only call online_pages() and offline_pages()
    respectively, but they will be later in charge of preparing the vmemmap
    pages, carrying out the initialization and proper accounting of such
    pages.
    
    Since memory_block struct contains all the information, pass this struct
    down the chain till the end functions.
    
    Link: https://lkml.kernel.org/r/20210421102701.25051-1-osalvador@suse.de
    Link: https://lkml.kernel.org/r/20210421102701.25051-2-osalvador@suse.deSigned-off-by: default avatarOscar Salvador <osalvador@suse.de>
    Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    8736cc2d
memory.c 20.4 KB