SPARSEMEM currently tries to allocate each section's page extensions from the buddy allocator before falling back to vmalloc. Boot-time section allocation happens after vmalloc is available, and memory hotplug allocations do not require physically contiguous backing.
Use vzalloc_node() directly and remove the buddy-specific allocation, free, and kmemleak bookkeeping. This leaves one runtime backing type and lets a later change add memblock as the distinct boot-time path to simplify the code. Signed-off-by: Muchun Song <[email protected]> --- v2: - Add a preparatory cleanup that always uses vmalloc for SPARSEMEM section page extensions (suggested by Mike Rapoport) --- mm/page_ext.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/mm/page_ext.c b/mm/page_ext.c index dbc1bfa258f1..3b581242fd52 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -285,15 +285,9 @@ static struct page_ext *lookup_page_ext(const struct page *page) static void *__meminit alloc_page_ext(size_t size, int nid) { - gfp_t flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN; - void *addr = NULL; - - addr = alloc_pages_exact_nid(nid, size, flags); - if (addr) - kmemleak_alloc(addr, size, 1, flags); - else - addr = vzalloc_node(size, nid); + void *addr; + addr = vzalloc_node(size, nid); if (addr) memmap_pages_add(DIV_ROUND_UP(size, PAGE_SIZE)); @@ -339,19 +333,10 @@ static int __meminit init_section_page_ext(unsigned long pfn, int nid) static void free_page_ext(void *addr) { size_t table_size; - struct page *page; table_size = page_ext_size * PAGES_PER_SECTION; memmap_pages_add(-1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); - - if (is_vmalloc_addr(addr)) { - vfree(addr); - } else { - page = virt_to_page(addr); - BUG_ON(PageReserved(page)); - kmemleak_free(addr); - free_pages_exact(addr, table_size); - } + vfree(addr); } static void __free_page_ext(unsigned long pfn) -- 2.54.0
