Skip to content

Commit f255935

Browse files
Christoph Hellwigtorvalds
authored andcommitted
mm: cleanup the gfp_mask handling in __vmalloc_area_node
Patch series "two small vmalloc cleanups". This patch (of 2): __vmalloc_area_node currently has four different gfp_t variables to just express this simple logic: - use the passed in mask, plus __GFP_NOWARN and __GFP_HIGHMEM (if suitable) for the underlying page allocation - use just the reclaim flags from the passed in mask plus __GFP_ZERO for allocating the page array Simplify this down to just use the pre-existing nested_gfp as-is for the page array allocation, and just the passed in gfp_mask for the page allocation, after conditionally ORing __GFP_HIGHMEM into it. This also makes the allocation warning a little more correct. Also initialize two variables at the time of declaration while touching this area. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Link: https://lkml.kernel.org/r/20201002124035.1539300-1-hch@lst.de Link: https://lkml.kernel.org/r/20201002124035.1539300-2-hch@lst.de Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 301fa9f commit f255935

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

mm/vmalloc.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,21 +2461,19 @@ EXPORT_SYMBOL_GPL(vmap_pfn);
24612461
static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
24622462
pgprot_t prot, int node)
24632463
{
2464-
struct page **pages;
2465-
unsigned int nr_pages, array_size, i;
24662464
const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
2467-
const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN;
2468-
const gfp_t highmem_mask = (gfp_mask & (GFP_DMA | GFP_DMA32)) ?
2469-
0 :
2470-
__GFP_HIGHMEM;
2465+
unsigned int nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
2466+
unsigned int array_size = nr_pages * sizeof(struct page *), i;
2467+
struct page **pages;
24712468

2472-
nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
2473-
array_size = (nr_pages * sizeof(struct page *));
2469+
gfp_mask |= __GFP_NOWARN;
2470+
if (!(gfp_mask & (GFP_DMA | GFP_DMA32)))
2471+
gfp_mask |= __GFP_HIGHMEM;
24742472

24752473
/* Please note that the recursion is strictly bounded. */
24762474
if (array_size > PAGE_SIZE) {
2477-
pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask,
2478-
node, area->caller);
2475+
pages = __vmalloc_node(array_size, 1, nested_gfp, node,
2476+
area->caller);
24792477
} else {
24802478
pages = kmalloc_node(array_size, nested_gfp, node);
24812479
}
@@ -2493,9 +2491,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
24932491
struct page *page;
24942492

24952493
if (node == NUMA_NO_NODE)
2496-
page = alloc_page(alloc_mask|highmem_mask);
2494+
page = alloc_page(gfp_mask);
24972495
else
2498-
page = alloc_pages_node(node, alloc_mask|highmem_mask, 0);
2496+
page = alloc_pages_node(node, gfp_mask, 0);
24992497

25002498
if (unlikely(!page)) {
25012499
/* Successfully allocated i pages, free them in __vfree() */

0 commit comments

Comments
 (0)