mm/sparse.c: use kvmalloc/kvfree to alloc/free memmap for the classic sparse
authorBaoquan He <bhe@redhat.com>
Thu, 2 Apr 2020 04:09:31 +0000 (21:09 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 2 Apr 2020 16:35:30 +0000 (09:35 -0700)
This change makes populate_section_memmap()/depopulate_section_memmap
much simpler.

Suggested-by: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Link: http://lkml.kernel.org/r/20200316125450.GG3486@MiWiFi-R3L-srv
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/sparse.c

index 55fe305e8d7ba7e68e7a14487c1cc4a377b82132..f0705f4167cbfb4f9510f76317a3b4ea6ca4426a 100644 (file)
@@ -664,35 +664,14 @@ static void free_map_bootmem(struct page *memmap)
 struct page * __meminit populate_section_memmap(unsigned long pfn,
                unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
 {
-       struct page *page, *ret;
-       unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION;
-
-       page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size));
-       if (page)
-               goto got_map_page;
-
-       ret = vmalloc(memmap_size);
-       if (ret)
-               goto got_map_ptr;
-
-       return NULL;
-got_map_page:
-       ret = (struct page *)pfn_to_kaddr(page_to_pfn(page));
-got_map_ptr:
-
-       return ret;
+       return kvmalloc(array_size(sizeof(struct page),
+                                  PAGES_PER_SECTION), GFP_KERNEL);
 }
 
 static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,
                struct vmem_altmap *altmap)
 {
-       struct page *memmap = pfn_to_page(pfn);
-
-       if (is_vmalloc_addr(memmap))
-               vfree(memmap);
-       else
-               free_pages((unsigned long)memmap,
-                          get_order(sizeof(struct page) * PAGES_PER_SECTION));
+       kvfree(pfn_to_page(pfn));
 }
 
 static void free_map_bootmem(struct page *memmap)