diff mbox series

[47/49] nodemask: add num_node_state_eq()

Message ID 20220210224933.379149-48-yury.norov@gmail.com (mailing list archive)
State New
Headers show
Series None | expand

Commit Message

Yury Norov Feb. 10, 2022, 10:49 p.m. UTC
Page allocator uses num_node_state() to compare number of nodes with a
given number. The underlying code calls bitmap_weight(), and we can do
it more efficiently with num_node_state_eq because conditional nodes_weight
may stop traversing the nodemask earlier, as soon as condition is (or is
not) met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 include/linux/nodemask.h | 5 +++++
 mm/page_alloc.c          | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Mike Rapoport Feb. 11, 2022, 10:41 a.m. UTC | #1
On Thu, Feb 10, 2022 at 02:49:31PM -0800, Yury Norov wrote:
> Page allocator uses num_node_state() to compare number of nodes with a
> given number. The underlying code calls bitmap_weight(), and we can do
> it more efficiently with num_node_state_eq because conditional nodes_weight
> may stop traversing the nodemask earlier, as soon as condition is (or is
> not) met.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Acked-by: Mike Rapoport <rppt@linux.ibm.com>

> ---
>  include/linux/nodemask.h | 5 +++++
>  mm/page_alloc.c          | 2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
> index 197598e075e9..c5014dbf3cce 100644
> --- a/include/linux/nodemask.h
> +++ b/include/linux/nodemask.h
> @@ -466,6 +466,11 @@ static inline int num_node_state(enum node_states state)
>  	return nodes_weight(node_states[state]);
>  }
>  
> +static inline int num_node_state_eq(enum node_states state, int num)
> +{
> +	return nodes_weight_eq(node_states[state], num);
> +}
> +
>  #define for_each_node_state(__node, __state) \
>  	for_each_node_mask((__node), node_states[__state])
>  
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index cface1d38093..897e64b66ca4 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8434,7 +8434,7 @@ void __init page_alloc_init(void)
>  	int ret;
>  
>  #ifdef CONFIG_NUMA
> -	if (num_node_state(N_MEMORY) == 1)
> +	if (num_node_state_eq(N_MEMORY, 1))
>  		hashdist = 0;
>  #endif
>  
> -- 
> 2.32.0
> 
>
diff mbox series

Patch

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 197598e075e9..c5014dbf3cce 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -466,6 +466,11 @@  static inline int num_node_state(enum node_states state)
 	return nodes_weight(node_states[state]);
 }
 
+static inline int num_node_state_eq(enum node_states state, int num)
+{
+	return nodes_weight_eq(node_states[state], num);
+}
+
 #define for_each_node_state(__node, __state) \
 	for_each_node_mask((__node), node_states[__state])
 
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index cface1d38093..897e64b66ca4 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8434,7 +8434,7 @@  void __init page_alloc_init(void)
 	int ret;
 
 #ifdef CONFIG_NUMA
-	if (num_node_state(N_MEMORY) == 1)
+	if (num_node_state_eq(N_MEMORY, 1))
 		hashdist = 0;
 #endif