linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* two small vmalloc cleanups
@ 2020-10-02 12:40 Christoph Hellwig
  2020-10-02 12:40 ` [PATCH 1/2] mm: cleanup the gfp_mask handling in __vmalloc_area_node Christoph Hellwig
  2020-10-02 12:40 ` [PATCH 2/2] mm: remove the filename in the top of file comment in vmalloc.c Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Christoph Hellwig @ 2020-10-02 12:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm

Hi Andrew,

this series has two misc vmalloc cleanups.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] mm: cleanup the gfp_mask handling in __vmalloc_area_node
  2020-10-02 12:40 two small vmalloc cleanups Christoph Hellwig
@ 2020-10-02 12:40 ` Christoph Hellwig
  2020-10-02 12:40 ` [PATCH 2/2] mm: remove the filename in the top of file comment in vmalloc.c Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2020-10-02 12:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm

__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>
---
 mm/vmalloc.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index be4724b916b3e7..5e3eea8ff952ea 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2410,21 +2410,19 @@ EXPORT_SYMBOL(vmap);
 static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 				 pgprot_t prot, int node)
 {
-	struct page **pages;
-	unsigned int nr_pages, array_size, i;
 	const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
-	const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN;
-	const gfp_t highmem_mask = (gfp_mask & (GFP_DMA | GFP_DMA32)) ?
-					0 :
-					__GFP_HIGHMEM;
+	unsigned int nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
+	unsigned int array_size = nr_pages * sizeof(struct page *), i;
+	struct page **pages;
 
-	nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
-	array_size = (nr_pages * sizeof(struct page *));
+	gfp_mask |= __GFP_NOWARN;
+	if (!(gfp_mask & (GFP_DMA | GFP_DMA32)))
+		gfp_mask |= __GFP_HIGHMEM;
 
 	/* Please note that the recursion is strictly bounded. */
 	if (array_size > PAGE_SIZE) {
-		pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask,
-				node, area->caller);
+		pages = __vmalloc_node(array_size, 1, nested_gfp, node,
+					area->caller);
 	} else {
 		pages = kmalloc_node(array_size, nested_gfp, node);
 	}
@@ -2442,9 +2440,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 		struct page *page;
 
 		if (node == NUMA_NO_NODE)
-			page = alloc_page(alloc_mask|highmem_mask);
+			page = alloc_page(gfp_mask);
 		else
-			page = alloc_pages_node(node, alloc_mask|highmem_mask, 0);
+			page = alloc_pages_node(node, gfp_mask, 0);
 
 		if (unlikely(!page)) {
 			/* Successfully allocated i pages, free them in __vunmap() */
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mm: remove the filename in the top of file comment in vmalloc.c
  2020-10-02 12:40 two small vmalloc cleanups Christoph Hellwig
  2020-10-02 12:40 ` [PATCH 1/2] mm: cleanup the gfp_mask handling in __vmalloc_area_node Christoph Hellwig
@ 2020-10-02 12:40 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2020-10-02 12:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm

No point in having the filename inside the file.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/vmalloc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 5e3eea8ff952ea..1ae0656c0b3415 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- *  linux/mm/vmalloc.c
- *
  *  Copyright (C) 1993  Linus Torvalds
  *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  *  SMP-safe vmalloc/vfree/ioremap, Tigran Aivazian <tigran@veritas.com>, May 2000
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-02 12:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 12:40 two small vmalloc cleanups Christoph Hellwig
2020-10-02 12:40 ` [PATCH 1/2] mm: cleanup the gfp_mask handling in __vmalloc_area_node Christoph Hellwig
2020-10-02 12:40 ` [PATCH 2/2] mm: remove the filename in the top of file comment in vmalloc.c Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).