diff mbox series

[46/49] mm/mempolicy: replace nodes_weight with nodes_weight_eq

Message ID 20220210224933.379149-47-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
do_migrate_pages() calls nodes_weight() to compare the weight
of nodemask with a given number. We can do it more efficiently with
nodes_weight_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>
---
 mm/mempolicy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mike Rapoport Feb. 11, 2022, 10:40 a.m. UTC | #1
On Thu, Feb 10, 2022 at 02:49:30PM -0800, Yury Norov wrote:
> do_migrate_pages() calls nodes_weight() to compare the weight
> of nodemask with a given number. We can do it more efficiently with
> nodes_weight_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>

> ---
>  mm/mempolicy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 7c852793d9e8..56efd00b1b6e 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1154,7 +1154,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
>  			 *          [0-7] - > [3,4,5] moves only 0,1,2,6,7.
>  			 */
>  
> -			if ((nodes_weight(*from) != nodes_weight(*to)) &&
> +			if (!nodes_weight_eq(*from, nodes_weight(*to)) &&
>  						(node_isset(s, *to)))
>  				continue;
>  
> -- 
> 2.32.0
> 
>
Christophe JAILLET Feb. 11, 2022, 5:44 p.m. UTC | #2
Le 10/02/2022 à 23:49, Yury Norov a écrit :
> do_migrate_pages() calls nodes_weight() to compare the weight
> of nodemask with a given number. We can do it more efficiently with
> nodes_weight_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>
> ---
>   mm/mempolicy.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 7c852793d9e8..56efd00b1b6e 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1154,7 +1154,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
>   			 *          [0-7] - > [3,4,5] moves only 0,1,2,6,7.
>   			 */
>   
> -			if ((nodes_weight(*from) != nodes_weight(*to)) &&
> +			if (!nodes_weight_eq(*from, nodes_weight(*to)) &&
>   						(node_isset(s, *to)))

Hi,

I've not looked in details, but would it make sense to hoist the 
"(nodes_weight(*from) != nodes_weight(*to))" test out of the 
for_each_node_mask() to compute it only once?

'from' and 'to' look unmodified in the loop.

Just my 2c,
CJ

>   				continue;
>
Yury Norov Feb. 11, 2022, 7:47 p.m. UTC | #3
+ Larry Woodman <lwoodman@redhat.com>

On Fri, Feb 11, 2022 at 06:44:39PM +0100, Christophe JAILLET wrote:
> Le 10/02/2022 à 23:49, Yury Norov a écrit :
> > do_migrate_pages() calls nodes_weight() to compare the weight
> > of nodemask with a given number. We can do it more efficiently with
> > nodes_weight_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>
> > ---
> >   mm/mempolicy.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > index 7c852793d9e8..56efd00b1b6e 100644
> > --- a/mm/mempolicy.c
> > +++ b/mm/mempolicy.c
> > @@ -1154,7 +1154,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
> >   			 *          [0-7] - > [3,4,5] moves only 0,1,2,6,7.
> >   			 */
> > -			if ((nodes_weight(*from) != nodes_weight(*to)) &&
> > +			if (!nodes_weight_eq(*from, nodes_weight(*to)) &&
> >   						(node_isset(s, *to)))
> 
> Hi,
> 
> I've not looked in details, but would it make sense to hoist the
> "(nodes_weight(*from) != nodes_weight(*to))" test out of the
> for_each_node_mask() to compute it only once?
> 
> 'from' and 'to' look unmodified in the loop.

It seems that 'from' and 'to' are untouched in the outer while()
loop as well, so we can compare weights of nodemaps only once at the
beginning.

Larry, can you please comment on that?

Thanks,
Yury
diff mbox series

Patch

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 7c852793d9e8..56efd00b1b6e 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1154,7 +1154,7 @@  int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
 			 *          [0-7] - > [3,4,5] moves only 0,1,2,6,7.
 			 */
 
-			if ((nodes_weight(*from) != nodes_weight(*to)) &&
+			if (!nodes_weight_eq(*from, nodes_weight(*to)) &&
 						(node_isset(s, *to)))
 				continue;