Skip to contentSkip to conversation

Remove node's validity check in alloc_pages

PATCH New Minchan Kim 2 participants 7 messages Apr 14, 2010

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Remove node's validity check in alloc_pages

V2
* Add some reviewed-by

alloc_pages calls alloc_pages_node with numa_node_id(). alloc_pages_node can't see nid < 0.

So we can use alloc_pages_exact_node instead of alloc_pages_node. It could avoid comparison and branch as 6484eb3e2a81807722 tried.

---
 include/linux/gfp.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/gfp.h +1 -1
index 4c6d413..b65f003 100644
@@ -308,7 +308,7 @@ extern struct page *alloc_page_vma(gfp_t gfp_mask,
 			struct vm_area_struct *vma, unsigned long addr);
 #else
 #define alloc_pages(gfp_mask, order) \
-		alloc_pages_node(numa_node_id(), gfp_mask, order)
+		alloc_pages_exact_node(numa_node_id(), gfp_mask, order)
 #define alloc_page_vma(gfp_mask, vma, addr) alloc_pages(gfp_mask, 0)
 #endif
 #define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
Signature · 7 lines
1.7.0.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/1 change alloc function in pcpu_alloc_pages

alloc_pages_node is called with cpu_to_node(cpu).
I think cpu_to_node(cpu) never returns -1.
(But I am not sure we need double check.)

So we can use alloc_pages_exact_node instead of alloc_pages_node. It could avoid comparison and branch as 6484eb3e2a81807722 tried.

Cc Tejun Heo <[email protected]>
Cc Christoph Lameter <[email protected]>
---
 mm/percpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/percpu.c +1 -1
index 768419d..ec3e671 100644
@@ -720,7 +720,7 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
 		for (i = page_start; i < page_end; i++) {
 			struct page **pagep = &pages[pcpu_page_idx(cpu, i)];
 
-			*pagep = alloc_pages_node(cpu_to_node(cpu), gfp, 0);
+			*pagep = alloc_pages_exact_node(cpu_to_node(cpu), gfp, 0);
 			if (!*pagep) {
 				pcpu_free_pages(chunk, pages, populated,
 						page_start, page_end);
Signature · 7 lines
1.7.0.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH v2 1/1 change alloc function in alloc_slab_page

In reply to Minchan Kim

V2
* change changelog
* Add some reviewed-by

alloc_slab_page always checks nid == -1, so alloc_page_node can't be called with -1.
It means node's validity check in alloc_pages_node is unnecessary. So we can use alloc_pages_exact_node instead of alloc_pages_node. It could avoid comparison and branch as 6484eb3e2a81807722 tried.

---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +1 -1
index b364844..9984165 100644
@@ -1084,7 +1084,7 @@ static inline struct page *alloc_slab_page(gfp_t flags, int node,
 	if (node == -1)
 		return alloc_pages(flags, order);
 	else
-		return alloc_pages_node(node, flags, order);
+		return alloc_pages_exact_node(node, flags, order);
 }
 
 static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
Signature · 1 line
1.7.0.5
#4 lore raw

PATCH v2 1/1 change alloc function in vmemmap_alloc_block

In reply to Minchan Kim

V2
* Add some reviewed-by

if node_state is N_HIGH_MEMORY, node doesn't have -1. It means node's validity check is unnecessary.
So we can use alloc_pages_exact_node instead of alloc_pages_node. It could avoid comparison and branch as 6484eb3e2a81807722 tried.

---
 mm/sparse-vmemmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/sparse-vmemmap.c +1 -1
index 392b9bb..7710ebc 100644
@@ -53,7 +53,7 @@ void * __meminit vmemmap_alloc_block(unsigned long size, int node)
 		struct page *page;
 
 		if (node_state(node, N_HIGH_MEMORY))
-			page = alloc_pages_node(node,
+			page = alloc_pages_exact_node(node,
 				GFP_KERNEL | __GFP_ZERO, get_order(size));
 		else
 			page = alloc_pages(GFP_KERNEL | __GFP_ZERO,
Signature · 1 line
1.7.0.5
#5 lore raw

PATCH v2 1/1 change alloc function in __vmalloc_area_node

In reply to Minchan Kim

V2
* Add some reviewed-by

__vmalloc_area_node never pass -1 to alloc_pages_node. It means node's validity check is unnecessary.
So we can use alloc_pages_exact_node instead of alloc_pages_node. It could avoid comparison and branch as 6484eb3e2a81807722 tried.

---
 mm/vmalloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/vmalloc.c +1 -1
index ae00746..7abf423 100644
@@ -1499,7 +1499,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 		if (node < 0)
 			page = alloc_page(gfp_mask);
 		else
-			page = alloc_pages_node(node, gfp_mask, 0);
+			page = alloc_pages_exact_node(node, gfp_mask, 0);
 
 		if (unlikely(!page)) {
 			/* Successfully allocated i pages, free them in __vunmap() */
Signature · 1 line
1.7.0.5
#6 lore raw

PATCH v2 1/1 Add comment in alloc_pages_exact_node

In reply to Minchan Kim

V2
o modify comment by suggestion. (Thanks to Mel)

alloc_pages_exact_node naming makes some people misleading. They considered it following as.
"This function will allocate pages from node which I wanted exactly".
But it can allocate pages from fallback list if page allocator can't find free page from node user wanted.

So let's comment this NOTE.

Actually I wanted to change naming with better. ex) alloc_pages_explict_node.
But I changed my mind since the comment would be enough.

If anybody suggests better name, I will do with pleasure.

Cc Mel Gorman <[email protected]>
Cc KAMEZAWA Hiroyuki <[email protected]>
Cc Bob Liu <[email protected]>
---
 include/linux/gfp.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/gfp.h +6 -0
index b65f003..56b5fe6 100644
@@ -288,6 +288,12 @@ static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
 	return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask));
 }
 
+/*
+ * Use this instead of alloc_pages_node when the caller knows
+ * exactly which node they need (as opposed to passing in -1
+ * for current). Fallback to other nodes will still occur
+ * unless __GFP_THISNODE is specified.
+ */
 static inline struct page *alloc_pages_exact_node(int nid, gfp_t gfp_mask,
 						unsigned int order)
 {
Signature · 7 lines
1.7.0.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Applied
#3 lore raw

Re: [PATCH v2] change alloc function in alloc_slab_page

In reply to Minchan Kim
Quoted 21 lines · Minchan Kim

V2
* change changelog
* Add some reviewed-by

alloc_slab_page always checks nid == -1, so alloc_page_node can't be
called with -1. It means node's validity check in alloc_pages_node is unnecessary. So we can use alloc_pages_exact_node instead of alloc_pages_node. It could avoid comparison and branch as 6484eb3e2a81807722 tried.

---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +0 -0
index b364844..9984165 100644

mm/slub.c static inline struct page *alloc_slab_page(gfp_t flags, int node, · line 1090

Quoted 8 lines
mm/slub.c +1 -1
@@ -1084,7 +1084,7 @@ static inline struct page *alloc_slab_page(gfp_t flags, int node,
 	if (node == -1)
 		return alloc_pages(flags, order);
 	else
-		return alloc_pages_node(node, flags, order);
+		return alloc_pages_exact_node(node, flags, order);
 }
 
 static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)

Applied, thanks!