Remove node's validity check in alloc_pages
Subsystems (6)
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
@@ -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>
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.
--- mm/percpu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
mm/percpu.c +1 -1
@@ -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>
PATCH v2 1/1 change alloc function in alloc_slab_page
In reply to Minchan KimV2
* 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
@@ -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
PATCH v2 1/1 change alloc function in vmemmap_alloc_block
In reply to Minchan KimV2
* 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
@@ -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
PATCH v2 1/1 change alloc function in __vmalloc_area_node
In reply to Minchan KimV2
* 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
@@ -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
PATCH v2 1/1 Add comment in alloc_pages_exact_node
In reply to Minchan KimV2
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.
--- include/linux/gfp.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/gfp.h +6 -0
@@ -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>
Pekka Enberg
AppliedRe: [PATCH v2] change alloc function in alloc_slab_page
In reply to Minchan KimQuoted 21 lines · Minchan Kim
V2
* change changelog
* Add some reviewed-by
alloc_slab_pagealways checks nid == -1, soalloc_page_nodecan't be
called with -1. It means node's validity check inalloc_pages_nodeis unnecessary. So we can usealloc_pages_exact_nodeinstead ofalloc_pages_node. It could avoid comparison and branch as6484eb3e2a81807722tried.Cc Pekka Enberg <[email protected]>Cc Christoph Lameter <[email protected]>Signed-off-by Minchan Kim <[email protected]>Reviewed-by KAMEZAWA Hiroyuki <[email protected]>Reviewed-by Mel Gorman <[email protected]>--- mm/slub.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)mm/slub.c +0
-0
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!