We reserved hotpluggable memory in memblock. And when memory initialization is done, we have to free it to buddy system. This patch free memory reserved by memblock with flag MEMBLK_HOTPLUGGABLE. Signed-off-by: Tang Chen <tangchen@xxxxxxxxxxxxxx> Reviewed-by: Wanpeng Li <liwanp@xxxxxxxxxxxxxxxxxx> --- include/linux/memblock.h | 1 + mm/memblock.c | 17 +++++++++++++++++ mm/nobootmem.c | 3 +++ 3 files changed, 21 insertions(+), 0 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index ce315b2..d113175 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -66,6 +66,7 @@ int memblock_reserve(phys_addr_t base, phys_addr_t size); int memblock_reserve_node(phys_addr_t base, phys_addr_t size, int nid); int memblock_reserve_local_node(phys_addr_t base, phys_addr_t size, int nid); int memblock_reserve_hotpluggable(phys_addr_t base, phys_addr_t size, int nid); +void memblock_free_hotpluggable(void); void memblock_trim_memory(phys_addr_t align); void memblock_mark_kernel_nodes(void); bool memblock_is_kernel_node(int nid); diff --git a/mm/memblock.c b/mm/memblock.c index 51f0264..9df0b5f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -568,6 +568,23 @@ int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size) return __memblock_remove(&memblock.reserved, base, size); } +static void __init_memblock memblock_free_flags(unsigned long flags) +{ + int i; + struct memblock_type *reserved = &memblock.reserved; + + for (i = 0; i < reserved->cnt; i++) { + if (reserved->regions[i].flags == flags) + memblock_remove_region(reserved, i); + } +} + +void __init_memblock memblock_free_hotpluggable() +{ + memblock_dbg("memblock: free all hotpluggable memory"); + memblock_free_flags(MEMBLK_HOTPLUGGABLE); +} + static int __init_memblock memblock_reserve_region(phys_addr_t base, phys_addr_t size, int nid, diff --git a/mm/nobootmem.c b/mm/nobootmem.c index bdd3fa2..dbfbcb9 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -165,6 +165,9 @@ unsigned long __init free_all_bootmem(void) for_each_online_pgdat(pgdat) reset_node_lowmem_managed_pages(pgdat); + /* Hotpluggable memory reserved by memblock should also be freed. */ + memblock_free_hotpluggable(); + /* * We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id * because in some case like Node0 doesn't have RAM installed -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html