• W
    memory-hotplug: common APIs to support page tables hot-remove · ae9aae9e
    Wen Congyang 提交于
    When memory is removed, the corresponding pagetables should alse be
    removed.  This patch introduces some common APIs to support vmemmap
    pagetable and x86_64 architecture direct mapping pagetable removing.
    
    All pages of virtual mapping in removed memory cannot be freed if some
    pages used as PGD/PUD include not only removed memory but also other
    memory.  So this patch uses the following way to check whether a page
    can be freed or not.
    
    1) When removing memory, the page structs of the removed memory are
       filled with 0FD.
    
    2) All page structs are filled with 0xFD on PT/PMD, PT/PMD can be
       cleared.  In this case, the page used as PT/PMD can be freed.
    
    For direct mapping pages, update direct_pages_count[level] when we freed
    their pagetables.  And do not free the pages again because they were
    freed when offlining.
    
    For vmemmap pages, free the pages and their pagetables.
    
    For larger pages, do not split them into smaller ones because there is
    no way to know if the larger page has been split.  As a result, there is
    no way to decide when to split.  We deal the larger pages in the
    following way:
    
    1) For direct mapped pages, all the pages were freed when they were
       offlined.  And since menmory offline is done section by section, all
       the memory ranges being removed are aligned to PAGE_SIZE.  So only need
       to deal with unaligned pages when freeing vmemmap pages.
    
    2) For vmemmap pages being used to store page_struct, if part of the
       larger page is still in use, just fill the unused part with 0xFD.  And
       when the whole page is fulfilled with 0xFD, then free the larger page.
    
    [akpm@linux-foundation.org: fix typo in comment]
    [tangchen@cn.fujitsu.com: do not calculate direct mapping pages when freeing vmemmap pagetables]
    [tangchen@cn.fujitsu.com: do not free direct mapping pages twice]
    [tangchen@cn.fujitsu.com: do not free page split from hugepage one by one]
    [tangchen@cn.fujitsu.com: do not split pages when freeing pagetable pages]
    [akpm@linux-foundation.org: use pmd_page_vaddr()]
    [akpm@linux-foundation.org: fix used-uninitialised bug]
    Signed-off-by: NYasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
    Signed-off-by: NJianguo Wu <wujianguo@huawei.com>
    Signed-off-by: NWen Congyang <wency@cn.fujitsu.com>
    Signed-off-by: NTang Chen <tangchen@cn.fujitsu.com>
    Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Cc: Jiang Liu <jiang.liu@huawei.com>
    Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
    Cc: Wu Jianguo <wujianguo@huawei.com>
    Cc: Ingo Molnar <mingo@elte.hu>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    ae9aae9e
init_64.c 33.6 KB