linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/page: refine the calculation of highest possible node id
@ 2015-07-10  6:26 Wei Yang
  2015-07-10  7:35 ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Wei Yang @ 2015-07-10  6:26 UTC (permalink / raw)
  To: akpm, tj; +Cc: linux-mm, Wei Yang

nr_node_ids records the highest possible node id, which is calculated by
scanning the bitmap node_states[N_POSSIBLE]. Current implementation scan
the bitmap from the beginning, which will scan the whole bitmap.

This patch reverse the order by scanning from the end. By doing so, this
will save some time whose worst case is the best case of current
implementation.

Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
---
 include/linux/nodemask.h |   16 ++++++++++++++++
 mm/page_alloc.c          |    3 +--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 6e85889..dfca95f 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -253,6 +253,12 @@ static inline int __first_node(const nodemask_t *srcp)
 	return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
 }
 
+#define last_node(src) __last_node(&(src))
+static inline int __last_node(const nodemask_t *srcp)
+{
+	return min_t(int, MAX_NUMNODES, find_last_bit(srcp->bits, MAX_NUMNODES));
+}
+
 #define next_node(n, src) __next_node((n), &(src))
 static inline int __next_node(int n, const nodemask_t *srcp)
 {
@@ -360,10 +366,20 @@ static inline void __nodes_fold(nodemask_t *dstp, const nodemask_t *origp,
 	for ((node) = first_node(mask);			\
 		(node) < MAX_NUMNODES;			\
 		(node) = next_node((node), (mask)))
+
+static inline int highest_node_id(const nodemask_t possible)
+{
+	return last_node(possible);
+}
 #else /* MAX_NUMNODES == 1 */
 #define for_each_node_mask(node, mask)			\
 	if (!nodes_empty(mask))				\
 		for ((node) = 0; (node) < 1; (node)++)
+
+static inline int highest_node_id(const nodemask_t possible)
+{
+	return 0;
+}
 #endif /* MAX_NUMNODES */
 
 /*
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 506eac8..b2f75ea 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5453,8 +5453,7 @@ void __init setup_nr_node_ids(void)
 	unsigned int node;
 	unsigned int highest = 0;
 
-	for_each_node_mask(node, node_possible_map)
-		highest = node;
+	highest = highest_node_id(node_possible_map);
 	nr_node_ids = highest + 1;
 }
 #endif
-- 
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2015-07-16  0:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-10  6:26 [PATCH] mm/page: refine the calculation of highest possible node id Wei Yang
2015-07-10  7:35 ` Andrew Morton
2015-07-10  8:27   ` Wei Yang
2015-07-11  3:08   ` [PATCH V2] " Wei Yang
2015-07-11  4:17     ` [PATCH V3] " Wei Yang
2015-07-16  0:16       ` David Rientjes

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).